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 token at https://www.convertapi.com/a/authentication
Add the following dependency to your pom.xml:
<dependency>
<groupId>com.convertapi.client</groupId>
<artifactId>convertapi</artifactId>
<version>2.13</version>
</dependency>You can get your token at https://www.convertapi.com/a/authentication
Config.setDefaultApiCredentials("api-token");Example to convert DOCX file to PDF. All supported formats and options can be found here.
CompletableFuture<ConversionResult> result = ConvertApi.convert("docx", "pdf", newParam("file", Paths.get("test.docx")));
// save to fileresult.get().saveFile(Paths.get("my_file.pdf")).get();Other result operations:
// save all result files to folderresult.get().saveFiles(Paths.get("/tmp"));
// get result fileConversionResultFilefile = result.get().getFile(0);
// get conversion costIntegercost = result.get().conversionCost();CompletableFuture<ConversionResult> result = ConvertApi.convert("pptx", "pdf",
newParam("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",
newParam("file", Paths.get("test.pdf")),
newParam("scaleimage", "true"),
newParam("scaleproportions", "true"),
newParam("imageheight", 300)
);You can always check the remaining conversions amount and other account information by fetching user information.
Useruser = ConvertApi.getUser();
intconversionsTotal = user.ConversionsTotal;
intconversionsConsumed = user.ConversionsConsumed;Create Config instance with the alternative domain and provide it in convert method. Dedicated to the region domain list.
Configconfig = newConfig(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:
importcom.convertapi.ConvertApi;
publicclassSimpleConversion {
publicstaticvoidmain(String[] args) {
ConvertApi.convert("source.docx", "result.pdf", "api-token");
}
}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 api-token with the token 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.