Merge PDF files using Java

High-speed, powerful, and secure API for merging PDF documents in Java


PDF merge API allows you to combine and merge multiple PDF files. Using PDF Merge API, you can retain the numbering of the pages, remove duplicate fonts to increase performance, and even create a table of contents for the merged documents.

Merge PDF documents programmatically

ConvertAPI provides a PDF Merge tool available as a REST API service. In addition, we provide a Java SDK for effortless integration into your project. It is accessible via Maven, and the source code can be found on GitHub. Simply sign up for a free account, grab your API secret key, install our Java library, and you are good to go!

Install the ConvertAPI library into the Java project

Go to the ConvertAPI Java client page and download the JAR file. Place JAR into your project library directory.

The library is also available in Maven. Add the following dependency to your pom.xml:


Merge PDF files using Java

Once you have the library installed, you can use this code example to join multiple PDF files using Java programming language:

package com.convertapi.examples;

import com.convertapi.client.Config;
import com.convertapi.client.ConvertApi;

import static java.lang.System.getenv;

 * Code snippet is using the ConvertAPI Java Client:
 * Read more about PDF Merge API:
public class MergePdf {

    public static void main(String[] args) {

        ConvertApi.convert("pdf", "merge",
            new Param("Files", Paths.get("/path/to/samnple-1.pdf")),
            new Param("Files", Paths.get("/path/to/sample-2.pdf"))
            new Param("Files", Paths.get("/path/to/sample-3.pdf"))

        System.out.println("PDF file saved to: " + tmpDir + "result.pdf");

That's all it takes to implement a PDF merge functionality into the Java project. You can combine local PDF files together with the files hosted on a server accessible via the URL, or the files uploaded to our server accessible by FileId.

Advanced techniques

You can find a complete list of conversion parameters on our interactive demo tool page. More advanced techniques and examples can be found in our GitHub examples folder. Happy coding!