The ConvertAPI helps converting various file formats. Creating PDF and Images from various sources like Word, Excel, Powerpoint, images, web pages or raw HTML codes. Merge, Encrypt, Split, Repair and Decrypt PDF files. And many others files manipulations. In just few minutes you can integrate it into your application and use it easily.
The ConvertAPI-Java library makes it easier to use the Convert API from your Java 8 projects without having to build your own API calls. You can get your free API credentials at https://www.convertapi.com/a
Add the following dependency to your pom.xml:
<dependency>
<groupId>com.convertapi.client</groupId>
<artifactId>convertapi</artifactId>
<version>2.12</version>
</dependency>
You can get your credentials at https://www.convertapi.com/a
Config.setDefaultApiCredentials("your-api-credentials");
Example to convert DOCX file to PDF. All supported formats and options can be found here.
CompletableFuture<ConversionResult> result = ConvertApi.convert("docx", "pdf", new Param("file", Paths.get("test.docx")));
// save to file
result.get().saveFile(Paths.get("my_file.pdf")).get();
Other result operations:
// save all result files to folder
result.get().saveFiles(Paths.get("/tmp"));
// get result file
ConversionResultFile file = result.get().getFile(0);
// get conversion cost
Integer cost = result.get().conversionCost();
CompletableFuture<ConversionResult> result = ConvertApi.convert("pptx", "pdf",
new Param("file", "https://cdn.convertapi.com/cara/testfiles/presentation.pptx")
);
ConvertAPI accepts extra conversion parameters depending on converted formats. All conversion parameters and explanations can be found here.
CompletableFuture<ConversionResult> result = ConvertApi.convert("pdf", "jpg",
new Param("file", Paths.get("test.pdf")),
new Param("scaleimage", "true"),
new Param("scaleproportions", "true"),
new Param("imageheight", 300)
);
You can always check the remaining conversions amount and other account information by fetching user information.
User user = ConvertApi.getUser();
int conversionsTotal = user.ConversionsTotal;
int conversionsConsumed = user.ConversionsConsumed;
Create Config
instance with the alternative domain and provide it in convert
method. Dedicated to the region domain list.
Config config = new Config(credentials, "https", "eu-v2.convertapi.com", 0, httpClientBuilder);
You can find more advanced examples in the examples folder.
ConvertAPI is designed to make converting file super easy, the following snippet shows how easy it is to get started. Let's convert WORD DOCX file to PDF:
import com.convertapi.ConvertApi;
public class SimpleConversion {
public static void main(String[] args) {
ConvertApi.convert("source.docx", "result.pdf", "your-api-credentials");
}
}
This is the bare-minimum to convert a file using the ConvertAPI client, but you can do a great deal more with the ConvertAPI Java library.
Take special note that you should replace your-api-credentials
with the credentials you obtained in item two of the pre-requisites.
Please leave all comments, bugs, requests, and issues on the Issues page. We'll respond to your request ASAP!
The ConvertAPI Java Library is licensed under the MIT license. Refer to the LICENSE file for more information.