Some test text!

menu
search
Crop pageskeyboard_arrow_down

Crop a page

There are two options to crop a page. First is using a UI component that can crop or reset pages. Second is an API guide to programmatically crop a page.

Crop pages dialog

With the PDFTron library you can crop pages manually or automatically, as well as reset document pages to their original size. The UserCropDialogFragment allows a user to adjust the page's crop box which can then be applied to a subset of pages or to all the pages in a document.

Crop pages

linkShow user crop pages dialog

To show a user crop pages dialog in your activity, create a new instance of UserCropDialogFragment by calling newInstance() and setting the PDFViewCtrl:

private PDFViewCtrl mPdfViewCtrl;
// ...
public void showUserCropDialog(FragmentManager fragmentManager) {
    UserCropDialogFragment fragment = UserCropDialogFragment.newInstance();
    fragment.setPdfViewCtrl(mPdfViewCtrl);
    // Set a custom style for this dialog
    fragment.setStyle(DialogFragment.STYLE_NO_TITLE, R.style.CustomAppTheme);
    // Show the dialog
    fragment.show(fragmentManager, "user_crop_pages_dialog");
}

In order to view user cropped pages in PDFViewCtrl make sure you set Page.e_user_crop as the default page box:

mPdfViewCtrl.setPageBox(Page.e_user_crop);

You can also set a listener via setOnUserCropDialogDismissListener(...) to be notified when the user crop dialog is dismissed.

UserCropDialogFragment does not crop pages permanently, it may not handled well by other PDF viewer. To crop pages permanently, see cropping pages permanently

linkAutomatically crop pages

You can also automatically crop the edges of the document based on the position of the content. To do this, you can simply call the utility method UserCropUtilities.AutoCropInBackgroundTask and pass in your activity and PDFViewCtrl.

linkExample
UserCropUtilities.AutoCropInBackgroundTask autoCropTask =
    new UserCropUtilities.AutoCropInBackgroundTask(getContext(), mPdfViewCtrl,
        new UserCropUtilities.AutoCropInBackgroundTask.AutoCropTaskListener() {
            @Override
            public void onAutoCropTaskDone() {
                // Auto crop task was finished or cancelled
            }
        });

linkRemove user defined crop boxes

If you wish to remove user defined cropping for a given page you can call the utility method UserCropUtilities.removeUserCropFromPage(Page).

linkPermanently crop pages

Cropping pages using the above methods are at user-level. User-level page-cropping may not be handled well by other PDF viewers. To apply crop pages permanently use UserCropUtilities.cropDoc(PDFDoc).

Get the answers you need: Support

close

Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

PDFTron Receives USD$71 Million Growth Investment Led By Silversmith Capital Partners

Learn more
close