Edit in GitHubLog an issue

Linearize PDFs

Linearize PDF#

Linearizing a PDF creates a web-optimized PDF file which supports incremental access in network environments.

Copied to your clipboard
1// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples
2// Run the sample:
3// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.linearizepdf.LinearizePDF
4
5 public class LinearizePDF {
6 // Initialize the logger.
7 private static final Logger LOGGER = LoggerFactory.getLogger(LinearizePDF.class);
8
9 public static void main(String[] args) {
10
11 try {
12 // Initial setup, create credentials instance.
13 Credentials credentials = Credentials.serviceAccountCredentialsBuilder()
14 .fromFile("pdfservices-api-credentials.json")
15 .build();
16
17 // Create an ExecutionContext using credentials and create a new operation instance.
18 ExecutionContext executionContext = ExecutionContext.create(credentials);
19 LinearizePDFOperation linearizePDFOperation = LinearizePDFOperation.createNew();
20
21 // Set operation input from a source file.
22 FileRef source = FileRef.createFromLocalFile("src/main/resources/linearizePDFInput.pdf");
23 linearizePDFOperation.setInput(source);
24
25 // Execute the operation
26 FileRef result = linearizePDFOperation.execute(executionContext);
27
28 // Save the result at the specified location
29 result.saveAs("output/linearizePDFOutput.pdf");
30
31 } catch (ServiceApiException | IOException | SdkException | ServiceUsageException ex) {
32 LOGGER.error("Exception encountered while executing operation", ex);
33 }
34 }
35 }
Was this helpful?
  • Privacy
  • Terms of Use
  • Do not sell my personal information
  • AdChoices
Copyright © 2022 Adobe. All rights reserved.