A REST API Solution to Optimize PDF Documents

tilalahmad

Tilal Ahmad Sana

Posted on October 11, 2019

A REST API Solution to Optimize PDF Documents

A PDF document may sometimes contain additional data. Reducing the size of a PDF file will help you optimize the network transfer and storage. This is especially handy for publishing on web pages, sharing on social networks, sending by e-mail, or archiving in storage. Let me show you how easily you can use GroupDocs.Conversion Cloud to optimize PDF document for web or optimize the PDF file size. I will be using cURL in the following examples. You can use the SDK of your favorite programming language, without worrying about underlying REST API calls.

Optimize PDF Document for the Web

Optimization, or linearization for Web, refers to the process of making a PDF file suitable for online browsing using a web browser. The linearized PDF file loads faster over the Internet. Because, linearized PDF files contains information that allow a byte-streaming server to download the PDF file one page at a time. If the byte-streaming is disabled on the server or if the PDF file is not linearized, the entire PDF file must be downloaded before it can be viewed. Check the cURL API command to optimize a PDF file for web display:

// Retrieve access token JWT(JSON Web Token)
// TODO: Get your AppSID and AppKey at https://dashboard.groupdocs.cloud (free registration is required).
curl --request POST https://api.groupdocs.cloud/connect/token 
--header "Content-Type: application/x-www-form-urlencoded" 
--data "grant_type=client_credentials&client_id=[APP_SID]&client_secret=[APP_KEY]"

// Optimize PDF document for Web
curl -X POST "https://api.groupdocs.cloud/v2.0/conversion" 
-H "accept: application/json" 
-H "authorization: Bearer [Access_Token]" 
-H "Content-Type: application/json" 
-d "{ "FilePath": "Test.pdf", "Format": "pdf", "ConvertOptions": {"linearize": true }}" 
--output C:/Temp/Test_linerized.pdf

Optimize PDF File Size

To optimize PDF file size, we can use several techniques to optimize PDF. GroupDocs.Conversion Cloud provides following properties to optimize the file size:

  • compressImages
  • imageQuality
  • linkDuplicateStreams
  • unembedFonts
  • removeUnusedObjects
  • removeUnusedStreams
// Retrieve access token JWT(JSON Web Token)
// TODO: Get your AppSID and AppKey at https://dashboard.groupdocs.cloud (free registration is required).
curl --request POST https://api.groupdocs.cloud/connect/token 
--header "Content-Type: application/x-www-form-urlencoded" 
--data "grant_type=client_credentials&client_id=[APP_SID]&client_secret=[APP_KEY]"

// Optimize PDF document size
curl -X POST "https://api.groupdocs.cloud/v2.0/conversion" 
-H "accept: application/json" 
-H "authorization: Bearer [Acess_Token]" 
-H "Content-Type: application/json" 
-d "{ "FilePath": "Test.pdf", "Format": "pdf", "ConvertOptions": { "linkDuplicateStreams": true, "removeUnusedObjects": true, "removeUnusedStreams": true, "compressImages": true, "imageQuality": 10, "unembedFonts": false }}" 
--output C:/Temp/Test_optimized.pdf

All you need is to sign up with the groupdocs.cloud. Once you’ve signed up, you’re ready to try the powerful file processing features offered by groupdocs.cloud.

💖 💪 🙅 🚩
tilalahmad
Tilal Ahmad Sana

Posted on October 11, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related