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.
Java
.NET
Node JS
Rest API
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples2// Run the sample:3// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.linearizepdf.LinearizePDF45 public class LinearizePDF {6 // Initialize the logger.7 private static final Logger LOGGER = LoggerFactory.getLogger(LinearizePDF.class);89 public static void main(String[] args) {1011 try {12 // Initial setup, create credentials instance.13 Credentials credentials = Credentials.servicePrincipalCredentialsBuilder()14 .withClientId("PDF_SERVICES_CLIENT_ID")15 .withClientSecret("PDF_SERVICES_CLIENT_SECRET")16 .build();1718 // Create an ExecutionContext using credentials and create a new operation instance.19 ExecutionContext executionContext = ExecutionContext.create(credentials);20 LinearizePDFOperation linearizePDFOperation = LinearizePDFOperation.createNew();2122 // Set operation input from a source file.23 FileRef source = FileRef.createFromLocalFile("src/main/resources/linearizePDFInput.pdf");24 linearizePDFOperation.setInput(source);2526 // Execute the operation27 FileRef result = linearizePDFOperation.execute(executionContext);2829 // Save the result at the specified location30 result.saveAs("output/linearizePDFOutput.pdf");3132 } catch (ServiceApiException | IOException | SdkException | ServiceUsageException ex) {33 LOGGER.error("Exception encountered while executing operation", ex);34 }35 }36 }
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples2// Run the sample:3// cd LinearizePDF/4// dotnet run LinearizePDF.csproj56 namespace LinearizePDF7 {8 class Program9 {10 private static readonly ILog log = LogManager.GetLogger(typeof(Program));11 static void Main()12 {13 //Configure the logging14 ConfigureLogging();15 try16 {17 // Initial setup, create credentials instance.18 Credentials credentials = Credentials.ServicePrincipalCredentialsBuilder()19 .WithClientId("PDF_SERVICES_CLIENT_ID")20 .WithClientSecret("PDF_SERVICES_CLIENT_SECRET")21 .Build();2223 // Create an ExecutionContext using credentials and create a new operation instance.24 ExecutionContext executionContext = ExecutionContext.Create(credentials);25 LinearizePDFOperation linearizePDFOperation = LinearizePDFOperation.CreateNew();2627 // Set operation input from a source file.28 FileRef sourceFileRef = FileRef.CreateFromLocalFile(@"linearizePDFInput.pdf");29 linearizePDFOperation.SetInput(sourceFileRef);3031 // Execute the operation.32 FileRef result = linearizePDFOperation.Execute(executionContext);3334 // Save the result to the specified location.35 result.SaveAs(Directory.GetCurrentDirectory() + "/output/linearizePDFOutput.pdf");36 }37 catch (ServiceUsageException ex)38 {39 log.Error("Exception encountered while executing operation", ex);40 }41 // Catch more errors here . . .42 }4344 static void ConfigureLogging()45 {46 ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());47 XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));48 }49 }50 }
Copied to your clipboard1// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample2// Run the sample:3// node src/linearizepdf/linearize-pdf.js45 const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');67 try {8 // Initial setup, create credentials instance.9 const credentials = PDFServicesSdk.Credentials10 .servicePrincipalCredentialsBuilder()11 .withClientId("PDF_SERVICES_CLIENT_ID")12 .withClientSecret("PDF_SERVICES_CLIENT_SECRET")13 .build();1415 // Create an ExecutionContext using credentials and create a new operation instance.16 const executionContext = PDFServicesSdk.ExecutionContext.create(credentials),17 linearizePDF = PDFServicesSdk.LinearizePDF,18 linearizePDFOperation = linearizePDF.Operation.createNew();1920 // Set operation input from a source file.21 const input = PDFServicesSdk.FileRef.createFromLocalFile('resources/linearizePDFInput.pdf');22 linearizePDFOperation.setInput(input);2324 // Execute the operation and Save the result to the specified location.25 linearizePDFOperation.execute(executionContext)26 .then(result => result.saveAsFile('output/linearizePDFOutput.pdf'))27 .catch(err => {28 if(err instanceof PDFServicesSdk.Error.ServiceApiError29 || err instanceof PDFServicesSdk.Error.ServiceUsageError) {30 console.log('Exception encountered while executing operation', err);31 } else {32 console.log('Exception encountered while executing operation', err);33 }34 });35 } catch (err) {36 console.log('Exception encountered while executing operation', err);37 }
Copied to your clipboard1// Please refer our Rest API docs for more information2// https://developer.adobe.com/document-services/docs/apis/#tag/Linearize-PDF34curl --location --request POST 'https://pdf-services.adobe.io/operation/linearizepdf' \5--header 'x-api-key: {{Placeholder for client_id}}' \6--header 'Content-Type: application/json' \7--header 'Authorization: Bearer {{Placeholder for token}}' \8--data-raw '{9 "assetID": "urn:aaid:AS:UE1:23c30ee0-2e4d-46d6-87f2-087832fca718"10}'1112// Legacy API can be found here13// https://documentcloud.adobe.com/document-services/index.html#post-linearizePDF