Edit in GitHubLog an issue

Compress PDFs

Reduce the size of PDF files by compressing to smaller sizes for lower bandwidth viewing, downloading, and sharing.

Support for multiple compression levels to retain the quality of images and graphics

Rest API

See our public API Reference for Compress PDF

Compress PDFs

Compress PDFs to reduce the file size prior to performing workflow operations that use bandwidth or memory.

Please refer the API usage guide to understand how to use our APIs.

Copied to your clipboard
// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples
// Run the sample:
// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.compresspdf.CompressPDF
public class CompressPDF {
// Initialize the logger.
private static final Logger LOGGER = LoggerFactory.getLogger(CompressPDF.class);
public static void main(String[] args) {
try {
// Initial setup, create credentials instance.
Credentials credentials = Credentials.servicePrincipalCredentialsBuilder()
.withClientId("PDF_SERVICES_CLIENT_ID")
.withClientSecret("PDF_SERVICES_CLIENT_SECRET")
.build();
// Create an ExecutionContext using credentials and create a new operation instance.
ExecutionContext executionContext = ExecutionContext.create(credentials);
CompressPDFOperation compressPDFOperation = CompressPDFOperation.createNew();
// Set operation input from a source file.
FileRef source = FileRef.createFromLocalFile("src/main/resources/compressPDFInput.pdf");
compressPDFOperation.setInput(source);
// Execute the operation
FileRef result = compressPDFOperation.execute(executionContext);
// Save the result at the specified location
result.saveAs("output/compressPDFOutput.pdf");
} catch (ServiceApiException | IOException | SdkException | ServiceUsageException ex) {
LOGGER.error("Exception encountered while executing operation", ex);
}
}
}

Compress PDFs with Compression Level

Compress PDFs to reduce the file size on the basis of provided compression level, prior to performing workflow operations that use bandwidth or memory. Refer to CompressionLevel in the API docs for a list of supported compression levels.

Please refer the API usage guide to understand how to use our APIs.

Copied to your clipboard
// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples
// Run the sample:
// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.compresspdf.CompressPDFWithOptions
public class CompressPDFWithOptions {
// Initialize the logger.
private static final Logger LOGGER = LoggerFactory.getLogger(CompressPDFWithOptions.class);
public static void main(String[] args) {
try {
// Initial setup, create credentials instance.
Credentials credentials = Credentials.servicePrincipalCredentialsBuilder()
.withClientId("PDF_SERVICES_CLIENT_ID")
.withClientSecret("PDF_SERVICES_CLIENT_SECRET")
.build();
// Create an ExecutionContext using credentials and create a new operation instance.
ExecutionContext executionContext = ExecutionContext.create(credentials);
CompressPDFOperation compressPDFOperation = CompressPDFOperation.createNew();
// Set operation input from a source file.
FileRef source = FileRef.createFromLocalFile("src/main/resources/compressPDFInput.pdf");
compressPDFOperation.setInput(source);
// Build CompressPDF options from supported compression levels and set them into the operation
CompressPDFOptions compressPDFOptions = CompressPDFOptions.compressPDFOptionsBuilder()
.withCompressionLevel(CompressionLevel.LOW)
.build();
compressPDFOperation.setOptions(compressPDFOptions);
// Execute the operation
FileRef result = compressPDFOperation.execute(executionContext);
// Save the result at the specified location
result.saveAs("output/compressPDFWithOptionsOutput.pdf");
} catch (ServiceApiException | IOException | SdkException | ServiceUsageException ex) {
LOGGER.error("Exception encountered while executing operation", ex);
}
}
}
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.