Package org.jpedal.tools
Class PdfMerge
java.lang.Object
org.jpedal.tools.PdfOptimizer
org.jpedal.tools.PdfMerge
Tool to merge PDF files together
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Class to track merged content reference changesNested classes/interfaces inherited from class org.jpedal.tools.PdfOptimizer
PdfOptimizer.Optimization
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Merge two files together and save the merged content to a specified file.void
Merge an array of files together and save the merged content into the specified output file.static void
mergeFiles
(File[] inputFiles, File outputFile) Merge the provided file array into a single document with the pages from files appearing in the order of the array.static void
mergeFiles
(File[] inputFiles, String[] passwords, File outputFile) Merge the provided file array into a single document with the pages from files appearing in the order of the array.static void
mergeFiles
(File inputFile1, File inputFile2, File outputFile) Merge the two provided files into a single document with the pages from inputFile1 appearing first.static void
Merge the two provided files into a single document with the pages from inputFile1 appearing first.Methods inherited from class org.jpedal.tools.PdfOptimizer
closePDF, getoptimizedFileAsBytes, loadFile, loadFile, loadFile, loadFile, optimizePDF, optimizePDF, optimizePDF, optimizePDF, refreshBuffer, removeUnusedObjects, writeoptimizedFileToStream
-
Constructor Details
-
PdfMerge
public PdfMerge()
-
-
Method Details
-
main
Merge two files together and save the merged content to a specified file.- Parameters:
args
- Expects a String array of 3 values. The first being the filenames for two files to merge, and the third being the filename for the output- Throws:
IOException
-
merge
Merge an array of files together and save the merged content into the specified output file.- Parameters:
files
- a File array for the files to be mergedoutput
- a File object for the file to save the content topasswords
- a byte array for passwords for each file provided. The array must either be null or an array of equal length to the input files with any file not requiring a password containing either null or an empty array.- Throws:
IOException
- Thrown if the file is corrupted or invalid in some way
-
mergeFiles
Merge the two provided files into a single document with the pages from inputFile1 appearing first.- Parameters:
inputFile1
- A PDF file to add to a document and appear first in the page orderinputFile2
- A PDF file to add to a document and appear after inputFile1outputFile
- A PDF filename to save the merged content to- Throws:
IOException
- thrown is there is a problem reading the provided files or outputing the content.
-
mergeFiles
public static void mergeFiles(File inputFile1, String password1, File inputFile2, String password2, File outputFile) throws IOException Merge the two provided files into a single document with the pages from inputFile1 appearing first.- Parameters:
inputFile1
- A PDF file to add to a document and appear first in the page orderpassword1
- A password for inputFile1. If no password is required an empty string or null should be providedinputFile2
- A PDF file to add to a document and appear after inputFile1password2
- A password for inputFile2. If no password is required an empty string or null should be providedoutputFile
- A PDF filename to save the merged content to- Throws:
IOException
- thrown is there is a problem reading the provided files or outputing the content.
-
mergeFiles
Merge the provided file array into a single document with the pages from files appearing in the order of the array.- Parameters:
inputFiles
- A File array of PDF to merge into a single documentoutputFile
- A PDF filename to save the merged content to- Throws:
IOException
- thrown is there is a problem reading the provided files or outputing the content.
-
mergeFiles
public static void mergeFiles(File[] inputFiles, String[] passwords, File outputFile) throws IOException Merge the provided file array into a single document with the pages from files appearing in the order of the array.- Parameters:
inputFiles
- A File array of PDF to merge into a single documentpasswords
- A String array of passwords for the inputFiles. The file and password arrays must be in the same order so the password and file have the same index. If no password is required for a file an empty string or null should be providedoutputFile
- A PDF filename to save the merged content to- Throws:
IOException
- thrown is there is a problem reading the provided files or outputing the content.
-