Edit in GitHubLog an issue

Linearize PDFs

Optimize PDFs for quick viewing on the web, especially for mobile clients. Linearization allows your end users to view large PDF documents incrementally so that they can view pages much faster in lower bandwidth conditions.

REST API

See our public API Reference for Linearize PDF

Linearize PDF

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

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

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 (InputStream inputStream = Files.newInputStream(new File("src/main/resources/linearizePDFInput.pdf").toPath())) {
12 // Initial setup, create credentials instance
13 Credentials credentials = new ServicePrincipalCredentials(
14 System.getenv("PDF_SERVICES_CLIENT_ID"),
15 System.getenv("PDF_SERVICES_CLIENT_SECRET"));
16
17 // Creates a PDF Services instance
18 PDFServices pdfServices = new PDFServices(credentials);
19
20 // Creates an asset(s) from source file(s) and upload
21 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.PDF.getMediaType());
22
23 // Creates a new job instance
24 LinearizePDFJob linearizePDFJob = new LinearizePDFJob(asset);
25
26 // Submit the job and gets the job result
27 String location = pdfServices.submit(linearizePDFJob);
28 PDFServicesResponse<LinearizePDFResult> pdfServicesResponse = pdfServices.getJobResult(location, LinearizePDFResult.class);
29
30 // Get content from the resulting asset(s)
31 Asset resultAsset = pdfServicesResponse.getResult().getAsset();
32 StreamAsset streamAsset = pdfServices.getContent(resultAsset);
33
34 // Creates an output stream and copy stream asset's content to it
35 Files.createDirectories(Paths.get("output/"));
36 OutputStream outputStream = Files.newOutputStream(new File("output/linearizePDFOutput.pdf").toPath());
37 LOGGER.info("Saving asset at output/linearizePDFOutput.pdf");
38 IOUtils.copy(streamAsset.getInputStream(), outputStream);
39 outputStream.close();
40 } catch (ServiceApiException | IOException | SDKException | ServiceUsageException ex) {
41 LOGGER.error("Exception encountered while executing operation", ex);
42 }
43 }
44 }
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.