Class PdfMerge


public class PdfMerge extends PdfOptimizer
Tool to merge PDF files together
  • Constructor Details

    • PdfMerge

      public PdfMerge()
  • Method Details

    • main

      public static void main(String[] args) throws IOException
      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

      public void merge(File[] files, File output, byte[][] passwords) throws IOException
      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 merged
      output - a File object for the file to save the content to
      passwords - 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

      public static void mergeFiles(File inputFile1, File inputFile2, 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 order
      inputFile2 - A PDF file to add to a document and appear after inputFile1
      outputFile - 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 order
      password1 - A password for inputFile1. If no password is required an empty string or null should be provided
      inputFile2 - A PDF file to add to a document and appear after inputFile1
      password2 - A password for inputFile2. If no password is required an empty string or null should be provided
      outputFile - 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, 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 document
      outputFile - 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 document
      passwords - 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 provided
      outputFile - 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.