Crop and Trim PDF Pages Crop PDF pages.
PDF Crop Pages
Crop PDF pages.
Upload PDF
Drop your PDF into the upload area.
Set Crop Values
Enter top, bottom, left, and right trim values in points, and choose which pages to crop.
Download
Download your cropped PDF.
What Is PDF Crop Pages?
A PDF Crop Pages is a tool that removes unwanted margins from PDF documents by cropping specific pages or all pages at once. Graphic designers and document editors use it to refine their layouts and prepare files for printing or digital distribution. One specific problem it solves is the issue of excess whitespace around page content, which can be particularly troublesome when working with scanned or imported documents.
The tool allows users to input crop values in points, with options to trim the top, bottom, left, and right edges of each page. It also features a page mode selector, enabling users to choose between cropping all pages or specifying custom page ranges using a comma-separated list of page numbers or ranges, such as "1-3, 5". This level of control makes it ideal for tasks like crop pdf margins or trim pdf pages.
What sets this tool apart is its ability to process PDFs entirely client-side, eliminating the need to upload sensitive documents to external servers. When using it to crop pdf pages online, users can take advantage of features like automatic page counting and validation of crop values to ensure that the resulting document is not corrupted or invalid. For example, if a user attempts to crop a page by more than its width or height, the tool will display an error message indicating that the crop values exceed the page dimensions. This attention to detail makes it a reliable choice for tasks like how to crop a pdf, especially when working with free pdf crop pages tools.
Why Use PDF Crop Pages?
-
Enter crop values in points per edge
-
Crop specific pages or all at once
-
All processing runs in your browser
-
No signup required
Common Use Cases
Scanned Documents
Remove black margins from scanned PDFs.
Print Preparation
Trim to fit specific paper sizes.
Forms & Contracts
Crop to essential content only.
Archiving
Reduce file size by removing excess margins.
Technical Guide
The tool works by utilizing the pdf-lib library to load and manipulate PDF documents. When a file is dropped into the FileDropzone component, it triggers the handleFile function, which reads the file as an array buffer and loads it into a PDFDocument object using pdf-lib's load method with the ignoreEncryption option set to true. The getPageCount method of the PDFDocument object is then used to retrieve the total number of pages in the document, which is stored in the pageCount state variable.
The parsePages function takes a string input representing page ranges and returns an array of page indices. This function splits the input string into parts using commas as separators, trims each part, and filters out empty strings. It then iterates over each part, checking if it contains a hyphen to determine if it represents a range of pages or a single page number. If it's a range, the function extracts the start and end page numbers, checks if they are valid, and adds the corresponding page indices to a set. If it's a single page number, the function simply adds the page index to the set.
The process function is triggered when the user clicks the crop button, and it uses the pdf-lib library to manipulate the media and crop boxes of each page. It first checks if the file is valid and if at least one non-zero crop value has been entered. If these conditions are met, it retrieves the PDFDocument object, gets the total number of pages, and determines which pages to crop based on the page mode selected by the user. The function then iterates over each page index, retrieves the corresponding page object using the getPage method, and gets its media box dimensions using the getMediaBox method.
The tool uses the setMediaBox and setCropBox methods of the page object to apply the crop values entered by the user. It calculates the new width and height of the page by subtracting the left and right crop values from the original width and the top and bottom crop values from the original height. If the new dimensions are invalid, it displays an error message indicating that the crop values exceed the page dimensions.
The cropped PDF is then saved using the save method of the PDFDocument object, which returns a byte array representing the cropped document. This byte array is used to create a blob object, which is in turn used to create an object URL that can be used to download the cropped PDF. The URL.createObjectURL method is used to create this object URL, and the revokeObjectURL method is used to clean up any existing object URLs when the component unmounts.
The React library is used to manage the tool's state and handle user input. The useState hook is used to store the file, page count, crop values, and other state variables, while the useCallback hook is used to memoize functions like handleFile and process. The useEffect hook is used to clean up object URLs when the component unmounts.
The tool also uses various browser APIs, such as the arrayBuffer method of the File object to read the file contents, and the URL.createObjectURL method to create an object URL for downloading the cropped PDF. The Blob constructor is used to create a blob object from the byte array returned by the save method of the PDFDocument object.
The tool's client-side processing eliminates the need to upload sensitive documents to external servers, making it a reliable choice for tasks like cropping PDF pages online. The use of pdf-lib and React enables efficient and secure manipulation of PDF documents, while the attention to detail in handling crop values and page dimensions ensures that the resulting document is not corrupted or invalid.
Tips & Best Practices
-
1Use margin presets for common page sizes if available
-
2All processing stays in your browser
-
3Download cropped PDF when ready
-
4Bookmark for quick access
Related Tools
Frequently Asked Questions
Q Is the PDF crop tool free?
Q Is my PDF safe when cropping?
Q Can I crop PDFs offline?
Q Which browsers support PDF cropping?
Q Can I use this for commercial PDFs?
About This Tool
PDF Crop Pages is a free online tool by FreeToolkit.ai. All processing happens directly in your browser — your data never leaves your device. No registration or installation required.