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:

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

Then, we will add a reference to the dependency:

<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v3.54</version>
</dependency>
</dependencies>

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

// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.EditPdfApi;
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.