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
// 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.linearizepdf.LinearizePDF
public class LinearizePDF {
// Initialize the logger.
private static final Logger LOGGER = LoggerFactory.getLogger(LinearizePDF.class);
public static void main(String[] args) {
try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/linearizePDFInput.pdf").toPath())) {
// Initial setup, create credentials instance
Credentials credentials = new ServicePrincipalCredentials(
System.getenv("PDF_SERVICES_CLIENT_ID"),
System.getenv("PDF_SERVICES_CLIENT_SECRET"));
// Creates a PDF Services instance
PDFServices pdfServices = new PDFServices(credentials);
// Creates an asset(s) from source file(s) and upload
Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.PDF.getMediaType());
// Creates a new job instance
LinearizePDFJob linearizePDFJob = new LinearizePDFJob(asset);
// Submit the job and gets the job result
String location = pdfServices.submit(linearizePDFJob);
PDFServicesResponse<LinearizePDFResult> pdfServicesResponse = pdfServices.getJobResult(location, LinearizePDFResult.class);
// Get content from the resulting asset(s)
Asset resultAsset = pdfServicesResponse.getResult().getAsset();
StreamAsset streamAsset = pdfServices.getContent(resultAsset);
// Creates an output stream and copy stream asset's content to it
Files.createDirectories(Paths.get("output/"));
OutputStream outputStream = Files.newOutputStream(new File("output/linearizePDFOutput.pdf").toPath());
LOGGER.info("Saving asset at output/linearizePDFOutput.pdf");
IOUtils.copy(streamAsset.getInputStream(), outputStream);
outputStream.close();
} 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.