Document Conversion Library for JAVA

Discover the ConvertAPI Java SDK to effortlessly handle file transformations, data extraction, and comprehensive document management. Take advantage of its extensive document conversion and management capabilities directly within your Java environment.

Maven GitHub

Integrate within minutes

It is easy to start converting documents using Java in a few simple steps:

1

Sign up for a free account

Sign up for free and receive 250 conversions to try and evaluate our service. You will receive a free trial with no credit card required upon registration!

2

Set up the conversion online

On your account dashboard you will access an intuitive UI tool that allows you to set up the conversion, adjust the parameters, and try the conversion online with zero code.

3

Copy auto-generated code snippet

Once you have set up the conversion parameters and are happy with the conversion results, you will receive an auto-generated Java code snippet with your custom parameters!

Get started now

Document management toolkit for Java

The ConvertAPI Java library is a comprehensive, developer-focused solution for versatile document conversion and enhancement. With extensive support across hundreds of file formats, you can efficiently transform PDFs, Office documents, images, and more. Whether merging files, compressing large assets, extracting data, or applying secure redactions, this flexible toolkit integrates seamlessly into your Java environment.

File Converter Suite

High-performance and unbeatable accuracy document converter suite with support for over 500+ conversion.

Document Builder using Java

Generate dynamic DOCX and PDF documents like invoices, contracts, reports, on the fly.

Document Management tools

Protect, redact, compare, watermark, flatten, compress and modify your documents using ConvertAPI Java SDK.

Security and Decryption

Protect and unprotect PDFs, MS Office Powerpoint and MS Office Word documents.

AI Data Extractor

Built to scale with your business, whether you're handling a few conversions or thousands.

Archiving & Optimization

Reduce file sizes without losing quality. Archive converters are designed to handle over 100 different file formats.

Take a look at Java code samples

View on GitHub

Configure it online - we will generate the Java code for you!

Configure your file conversion directly online using our intuitive interface. Select the desired parameters and see the results in real-time. Once you're satisfied, we’ll automatically generate the Java code for you, making integration into your project effortless. No need to start from scratch—just copy the code and implement it seamlessly into your Java application!

Get started now

File conversion example using Java

The ConvertAPI Java library empowers developers to seamlessly integrate advanced document conversion and manipulation capabilities into their Java applications. Supporting hundreds of file formats—including PDFs, Office documents, images, and more—it streamlines complex tasks like merging files, compressing large documents, extracting valuable data, and securely redacting sensitive information.

With intuitive methods and flexible parameters, the library reduces development overhead and speeds up integration, allowing you to focus on delivering reliable, high-quality document processing solutions within a familiar Java environment.

Install the ConvertAPI library into your JAVA project

To get started, install the ConvertAPI Java package using Maven:

# Add the following dependency to your pom.xml:
<dependency>
   <groupId>com.convertapi.client</groupId>
   <artifactId>convertapi</artifactId>
   <version>2.10</version>
</dependency>

Convert PPTX to PDF example

The ConvertAPI Java library makes it effortless to convert PPTX presentations into PDFs while offering a wide range of customizable parameters to meet your specific requirements. Whether you need to adjust page size, define conversion quality, embed fonts, or include speaker notes, the library provides intuitive options right out of the box.

With straightforward integration into your Java application, converting PPTX files to PDF is not only reliable and efficient, but also easily adaptable to suit the exact presentation standards and design elements your project demands.

// Code snippet is using the ConvertAPI JavaScript Client: https://github.com/ConvertAPI/convertapi-library-js

// Code snippet is using the ConvertAPI Node.js Client: https://github.com/ConvertAPI/convertapi-nodejs

// Code snippet is using the ConvertAPI PHP Client: https://github.com/ConvertAPI/convertapi-php

// Code snippet is using the ConvertAPI Java Client: https://github.com/ConvertAPI/convertapi-java

// Code snippet is using the ConvertAPI C# Client: https://github.com/ConvertAPI/convertapi-dotnet

# Code snippet is using the ConvertAPI Ruby Client: https://github.com/ConvertAPI/convertapi-ruby

# Code snippet is using the ConvertAPI Python Client: https://github.com/ConvertAPI/convertapi-python

// Code snippet is using the ConvertAPI Go Client: https://github.com/ConvertAPI/convertapi-go

REM Code snippet is using the command line utility program: https://github.com/ConvertAPI/convertapi-cli

<!-- For conversions with the multiple file result please refer to this example: https://repl.it/@ConvertAPI/HTML-Form-with-multiple-file-result -->

Convert a Remote File

This example demonstrates how to execute a document conversion directly from a remote URL. This illustrates how to convert a file hosted on a remote server by providing its direct URL.

Key Features:

  • Accepts a publicly accessible file URL as input.
  • Processes the file conversion without downloading it locally first.
  • Stores the converted file on the local machine.

It is useful for automating the conversion of files available online without manual intervention.

/**
 * Example of conversion remote file. Converting file must be accessible from
 * the internet.
 */
public class ConvertRemoteFile {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Config.setDefaultApiCredentials(getenv("CONVERTAPI_CREDENTIALS"));   //Get your api credentials at https://www.convertapi.com/a

        System.out.println("Converting remote PPTX to PDF");
        CompletableFuture<ConversionResult> result = ConvertApi.convert("pptx", "pdf",
            new Param("file", "https://cdn.convertapi.com/cara/testfiles/presentation.pptx")
        );

        Path pdfFile = Paths.get(System.getProperty("java.io.tmpdir") + "/myfile.pdf");
        result.get().saveFile(pdfFile).get();

        System.out.println("PDF file saved to: " + pdfFile.toString());
    }
}

Convert File Stream

Shows how to perform file conversions entirely in memory using streams, eliminating the need for temporary file downloads and uploads.

Key Features

  • Reads the input file into an InputStream.
  • Processes the conversion directly from the stream.
  • Writes the output to an OutputStream, avoiding disk I/O.
/**
 * Example of the file conversion when data is passed as a stream.
 */
public class ConvertStream {

    public static void main(String[] args) throws ExecutionException, InterruptedException, IOException {
        Config.setDefaultApiCredentials(getenv("CONVERTAPI_CREDENTIALS"));   //Get your api credentials at https://www.convertapi.com/a

        // Creating file data stream
        InputStream stream = Files.newInputStream(new File("src/main/resources/test.docx").toPath());

        System.out.println("Converting stream of DOCX data to PDF");
        CompletableFuture<ConversionResult> result = ConvertApi.convert("docx", "pdf",
                new Param("file", stream, "test.docx")
        );

        Path pdfFile = Paths.get(System.getProperty("java.io.tmpdir") + "/myfile.pdf");
        result.get().saveFile(pdfFile).get();

        System.out.println("PDF file saved to: " + pdfFile.toString());
    }
}

Convert Web To PDF

This example demonstrates converting a live web page into a PDF document by providing its URL.

Key Features:

  • Fetches web content directly from the provided URL.
  • Generates a PDF representation of the web page.
  • Saves the resulting PDF to the local file system.

It is ideal for archiving web pages or generating PDF versions of online content for offline access or record-keeping.

/**
 * Example of converting Web Page URL to PDF file
 * https://www.convertapi.com/web-to-pdf
 */
public class ConvertWebToPdf {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Config.setDefaultApiCredentials(getenv("CONVERTAPI_CREDENTIALS"));   //Get your api credentials at https://www.convertapi.com/a

        System.out.println("Converting WEB to PDF");
        CompletableFuture<ConversionResult> result = ConvertApi.convert("web", "pdf",
            new Param("url", "https://en.wikipedia.org/wiki/Data_conversion"),
            new Param("filename", "web-example")
        );

        Path tmpDir = Paths.get(System.getProperty("java.io.tmpdir"));
        CompletableFuture<Path> pdfFile = result.get().saveFile(tmpDir);

        System.out.println("PDF file saved to: " + pdfFile.get().toString());
    }
}

Conversion Chaining

Demonstrates chaining multiple conversions in a single workflow, such as converting a PDF to JPG and compressing result files into a ZIP archive.

Key Features:

  • Executes sequential conversions using intermediate results.
  • Manages multiple steps within a single process.
  • Outputs the final converted file after all transformations.

It is extremely useful for complex workflows requiring multiple file transformations in a specific sequence.

/**
 * Short example of conversions chaining, the PDF pages extracted and saved as
 * separated JPGs and then ZIP'ed
 * https://www.convertapi.com/doc/chaining
 */
public class ConversionChaining {

    public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {
        Config.setDefaultApiCredentials(getenv("CONVERTAPI_CREDENTIALS"));   //Get your api credentials at https://www.convertapi.com/a

        System.out.println("Converting PDF to JPG and compressing result files with ZIP");
        CompletableFuture<ConversionResult> jpgResult = ConvertApi.convert("docx", "jpg", new Param("file", Paths.get("files/test.docx")));
        System.out.println("ConvertApi.convert is not blocking method, proceeding to ZIP conversion");

        CompletableFuture<ConversionResult> zipResult = ConvertApi.convert("jpg", "zip", new Param("files", jpgResult));

        System.out.println("Saving result file (blocking operation)");
        Path tempDir = Paths.get(System.getProperty("java.io.tmpdir"));
        CompletableFuture<Path> path = zipResult.get().saveFile(tempDir);

        System.out.println("DOCX -> JPG conversion cost: " + jpgResult.get().conversionCost());
        System.out.println("DOCX -> JPG conversion result file count: " + jpgResult.get().fileCount());
        System.out.println("JPG -> ZIP conversion cost: " + zipResult.get().conversionCost());
        System.out.println("ZIP file saved to: " + path.get().toString());
    }
}

Advanced techniques

Below you will find some examples of advanced usage scenarios, including setting custom timeout and deleting the files from ConvertAPI servers manually.

Key Features:

  • Demonstrates setting custom conversion timeout.
  • Handles file deletion manually.
  • Showcases setting a proxy server.
/**
 * Example of HTTP client setup to use HTTP proxy server.
 */
public class Advanced {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Config.setDefaultApiCredentials(getenv("CONVERTAPI_CREDENTIALS"));   //Get your api credentials at https://www.convertapi.com/a

        // Advanced HTTP client setup
        Config.setDefaultHttpBuilder(builder -> {
            return builder
            //  .proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.0.0.1", 8888))) // Setting Proxy server
                .connectTimeout(3, TimeUnit.SECONDS);    // Setting connect timeout
            // More settings can be tuned here
        });

        // Conversion
        Param fileParam = new Param("file", "https://cdn.convertapi.com/cara/testfiles/presentation.pptx");
        System.out.println("Converting remote PPTX to PDF");
        CompletableFuture<ConversionResult> result = ConvertApi.convert("pptx", "pdf", fileParam);
        Path pdfFile = Paths.get(System.getProperty("java.io.tmpdir") + "/myfile.pdf");
        result.get().saveFile(pdfFile).get();

        // Leaving no files on convertapi.com server
        System.out.println("Deleting source file from convertapi.com server");
        fileParam.delete().get();
        System.out.println("Deleting result files from convertapi.com server");
        result.get().deleteSync();

        System.out.println("PDF file saved to: " + pdfFile.toString());
    }
}

Retrieve Account Information

The final example illustrates how to retrieve account information, such as usage statistics and remaining conversion credits, using the ConvertAPI Java SDK. It is important for monitoring account usage and managing conversion quotas programmatically.

Key Features:

  • Authenticates using API credentials.
  • Fetches user account details.
  • Displays information like conversion usage and balance.
/**
 * Retrieve user information
 * https://www.convertapi.com/doc/user
 */
public class UserInformation {

    public static void main(String[] args) {
        Config.setDefaultApiCredentials(getenv("CONVERTAPI_CREDENTIALS"));   //Get your api credentials at https://www.convertapi.com/a
        User user = ConvertApi.getUser();

        System.out.println("API Key: " + user.ApiKey);
        System.out.println("Email: " + user.Email);
        System.out.println("Name: " + user.FullName);
        System.out.println("Status: " + user.Status);
        System.out.println("Active: " + user.Active);
        System.out.println("Total Conversions: " + user.ConversionsTotal);
        System.out.println("Conversions Consumed: " + user.ConversionsConsumed);
    }
}
}

With our Java SDK, you’ll unlock a wide range of over 500+ converters and document management capabilities—conveniently accessible from a single, unified platform.

You can provide documents via URLs, use file streams, or reference local file paths, ensuring that file handling fits seamlessly into your existing environment. To further enhance efficiency, consider employing conversion workflows to manage multiple tasks concurrently.

For in-depth examples and expert tips, be sure to explore our GitHub repository.

Automate Your Document Management using Java

Take control of your documents with our Java document management SDK. From basic conversions to full workflow automation, we provide the expertise and tools you need to manage your documents efficiently.

Data security is our top priority

We ensure that all document processing is handled securely in the cloud, adhering to industry-leading standards like ISO 27001, GDPR, and HIPAA. To enhance security even further, we can ensure that no files or data are stored on our servers and never leave your country.

Learn more about security

Businesses trust us

Highest rated File Conversion API on major B2B software listing platforms: Capterra, G2, and Trustpilot.

"ConvertAPI has been a game-changer for our document automation workflows. Their conversion accuracy and API reliability are unmatched in the industry for over 7 years."

"ConvertAPI is a reliable, cost-effective solution with a proven track record of stability. It has grown significantly in maturity, adopting enterprise-grade practices over the years."

"We've integrated ConvertAPI across our entire document processing platform. The performance is exceptional and the support team is always responsive. Highly recommended!"

Frequently asked questions

What does the ConvertAPI Java library do?

The ConvertAPI Java library enables you to integrate powerful file conversion, manipulation, and document management capabilities directly into your Java applications. You can easily convert PDFs, Office documents, images, and many other file types with just a few lines of code.

How do I install the ConvertAPI Java library?

If it’s hosted on Maven Central or a similar repository, simply add the dependency to your pom.xml and run mvn clean install. If you have a local JAR, you can install it into your Maven repository and then include it as a dependency. Refer to our documentation for exact steps.

Which file formats are supported by ConvertAPI?

The library supports hundreds of file formats—ranging from common PDF and Office documents to various image, text, and eBook file types. This flexibility makes it an all-in-one solution for diverse document processing needs.

Can I fine-tune conversion parameters?

Absolutely. The ConvertAPI Java library provides customizable parameters like image quality, color spaces, page ranges, metadata handling, and more. This ensures you get precisely the output you require for each document conversion.

Does it support large documents or conversion workflows?

Yes. The library is optimized for handling large files and supports workflows to process the documents efficiently. Asynchronous and parallel processing options help maintain performance in high-load scenarios.

Where can I find examples or get help if I have questions?

You can explore our GitHub repository for code samples, advanced usage patterns, and best practices. For personalized assistance, our support team is ready to help with integration questions, troubleshooting, and guidance on optimizing performance.

Try our Java library for free!