with File Paths
The easiest and most reliable way to merge PDF files, using the “GroupDocs.Merger for Java” product, is to use the full paths to these files.
The following example demonstrates how to merge PDF files using file paths in Java code:
- Create an instance of Merger class and pass the full PDF file path as a constructor parameter.
- Add another PDF file to merge with join method.
- Call Merger class save method and specify the filename for the merged PDF file as parameter.
There are situations, and quite often, when it is necessary to work with other classes inherited from java.io.InputStream, for example with FileInputStream or others. In this case, it is necessary to use additional parameters to specify the exact file type that is used in this case. Because the “GroupDocs.Merger for Java” product cannot always accurately determine the file type by its stream. Therefore, to avoid exceptions when merging PDF and other files, see the example below:
- Create an instance of Merger class and pass instance of LoadOptions with PPTX file type as a constructor parameter.
- Create an instance of JoinOptions class with PPTX file type as a constructor parameter.
- Add another PPTX stream to merge with join method and pass instance of JoinOptions class as a method parameter.
- Call Merger class save method and specify the filename for the merged PPTX file as parameter.
There may also be situations when it is necessary to combine different types of streams into PDF. In this case, you can use the example below:
- Create an instance of Merger class and pass instance of LoadOptions with ini DOCX file type and out PDF one as a constructor parameters.
- Create an instance of JoinOptions class with PPTX file type as a constructor parameter.
- Add another PPTX stream to merge with join method and pass instance of JoinOptions class as a method parameter.
- Call Merger class save method and specify the filename for the merged PDF file as parameter.