Resize a PDF Document using Java

Businesses don’t always fit into a standard design, so it makes sense to employ a file format that can be as dynamic as you are; PDFs are widely used and the perfect option for distributing documents to clients. Now let’s say you have a PDF of a brochure you want to make printable; to maximize its readability and usage, we have an API that can automatically and efficiently perform the operation for you.

To begin the process, install the Maven SDK by adding a reference to the repository in pom.xml:

Then, we will add a reference to the dependency:

With the installation complete, we are now able to add the imports and call the EditPDFResize function:

ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//Apikey.setApiKeyPrefix("Token");
EditPdfApi apiInstance = new EditPdfApi();
File inputFile = new File("/path/to/inputfile"); // File | Input file to perform the operation on.
String paperSize = "paperSize_example"; // String | The desired paper size for the resized PDF document. Size ranges from A7 (smallest) to A0 (largest).
try {
byte[] result = apiInstance.editPdfResize(inputFile, paperSize);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling EditPdfApi#editPdfResize");
e.printStackTrace();
}

Now your newly resized PDF document is ready to rock. In order to retrieve your personal API key, register for a free account on the Cloudmersive website to gain access to 800 API calls/month.

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store