Some test text!

Search
Hamburger Icon

Web / Guides

Cropping PDF pages using JavaScript

Make sure you have Full API enabled in WebViewer.

To crop a page in a PDF document.

async function main() {
  const doc = await PDFNet.PDFDoc.createFromURL(filename);

  // Access a PDF page
  const page = await doc.getPage(1);

  // Crop the page
  page.setCropBox(new PDFNet.Rect(0, 0, 500, 600));
}
PDFNet.runWithCleanup(main);

About cropping the page

The crop box defines the region to which the contents of the page are to be clipped (cropped) when displayed or printed. Unlike other types of boxes, the crop box has no defined meaning in terms of physical page geometry or intended use; it merely imposes clipping on the page contents. The default value is the page's media box. A new crop box can be imposed on a page with Page.SetCropBox().

Trial setup questions? Ask experts on Discord
Need other help? Contact Support
Pricing or product questions? Contact Sales