Process PDF Documents
Optimize, Merge, Sign, Split an existing PDF Document
How to Process PDF Files in Java
// Remove unused objects and optimize PDF files
PdfOptimizer.optimizePDF(new File("inputFile.pdf"), new File("outputFile.pdf"));// Merge two files into a single file
PdfMerge.mergeFiles(new File("inputFile1.pdf"), new File("inputFile2.pdf"), new File("outputFile.pdf"));
// Merge an array of PDFs into a single file
PdfMerge.mergeFiles(new File[]{new File("inputFile.pdf"), ...}, new File("outputFile.pdf"));final PdfManipulator pdf = new PdfManipulator();
pdf.loadDocument(new File("inputFile.pdf"));
// Remove attachments and embedded files
pdf.removeEmbeddedFiles();
// Remove scripts and code
pdf.removeJavaScript();
// Remove document information and metadata
pdf.removeMetadata();
pdf.apply();
pdf.writeDocument(new File("outputFile.pdf"));// Digitally sign a PDF file
PdfSigner.signPdf(
"inputFile.pdf",
"outputFile.pdf",
"keystorePassword",
"keystoreFile.p12",
"signerName",
"signerLocation",
"signingReason",
ACCESS_PERMISSION.P1
);// Split a PDF file into two files where the first page contains pages 1-pageToSplitAt inclusive, the second contains all other pages
PdfManipulator.splitInHalf(new File("inputFile.pdf"), new File("outputFolder"), pageToSplitAt);
// Split all pages into separate PDF files, all output has the same file name with the page numbers appended
PdfManipulator.splitIntoPages(new File("inputFile.pdf"), new File("outputFolder"), numberOfPages);Use JPedal as part of your PDF automation pipeline
| Feature | What it does | Tutorial |
|---|---|---|
| Attach/embed files | Embed an arbitrary file into the PDF and optionally add a file attachment annotation to a page. | How to Attach Files to a PDF |
| Digitally sign | Add cryptographic digital signatures for document authentication and integrity verification. | How to Sign PDF Files in Java |
| Manipulate pages | Add, copy, delete, rotate, and resize pages, plus arrange pages in an N-up grid layout. | How to Manipulate PDF Documents in Java |
| Merge | Combine multiple PDF files into a single document, preserving fonts, images, and page structure. | PDF Merge in Java |
| Optimize | Reduce file size by eliminating unused objects, flattening layers, and downsampling images. | How to Remove Unused Objects from a PDF |
| Redact | Permanently remove sensitive text from the PDF structure so it cannot be recovered. | How to Remove Text from a PDF |
| Sanitize | Remove potentially harmful content, including JavaScript, embedded files, and launch actions. | How to Sanitize PDF Files |
| Split | Divide a PDF into individual pages or user-defined ranges, for example splitting a 100-page document into ten 10-page documents. | How to Split a PDF in Java |
JPedal has the advantage of running in the same Java virtual machine, so we save a lot of CPU resources.
- T. Büngener (Software Architect InSign)
Frequently Asked Questions
Can I chain operations, like deleting pages, in one pass?
Yes. PdfManipulator queues up manipulations and applies them all in the order you added them with a single apply() and writeDocument() call, so you can delete pages, add text, embed files and more in one workflow instead of a separate read/write cycle per operation.
Does merging PDFs with different page sizes cause layout problems?
Not if you use the NORMALISE_PAGE_SIZE_TO_MATCH_FIRST option, which resizes every merged page to match the first page of the first document. It is not compatible with interleave mode, which ignores it.
What format does JPedal need to digitally sign a PDF?
A PKCS#12 keystore containing your private key and X.509 certificate, signed with SHA256withRSA, with a private key that has digitalSignature usage capability. JPedal produces PAdES Baseline Level B signatures.
Do I need any external tools to merge, split, or sign PDFs with JPedal?
No. These operations run entirely inside your JVM through the JPedal library, with no native binaries or external processes required.
Does redacting text really remove it, or just draw over it?
It removes it. Any text within the redaction rectangle is deleted from the document itself, not hidden behind a visual overlay, based on what percentage of each character's area falls inside the rectangle.
JPedal is absolutely easy to use and it provided the best results of all libraries we tested over the years. We need to create renditions of PDF files so that people can view them conveniently in the browser.
- Roman K. (Developer at German Digital Big Data Platform)
Support for JPedal is done extremely well and for continuously using the software, what the customer needs is good support for the issues we face. And it is superb in that respect.
- Developer (Large Multinational Corporation)