The pdfRest Linearize PDF API Tool is an invaluable resource for optimizing PDFs for fast web view. Linearization restructures a PDF document so that its pages can be displayed or streamed one at a time without needing to download the entire file first. This tutorial will guide you through the process of sending an API call to the Linearize PDF endpoint using cURL, a powerful and versatile command-line tool for transferring data with URLs.
Linearizing a PDF is particularly useful for improving user experience on websites where large PDF files are available for viewing. For instance, if a user wants to read a lengthy report or e-book, linearizing the PDF allows the initial pages to be displayed quickly while the rest of the document continues to download in the background. This means no long waits and a smoother reading experience for the end user.
curl -X POST "https://api.pdfrest.com/linearized-pdf" \ -H "Accept: application/json" \ -H "Content-Type: multipart/form-data" \ -H "Api-Key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \ -F "file=@/path/to/file" \ -F "output=example_out"
Reference to the code: pdf-rest-api-samples
The above cURL command is composed of several parts that together create a POST request to the pdfRest API:
-X POST "https://api.pdfrest.com/linearized-pdf"
This specifies the HTTP method (POST) and the API endpoint URL for linearizing a PDF.
-H "Accept: application/json"
This header tells the server that the client expects a response in JSON format.
-H "Content-Type: multipart/form-data"
This header indicates that the data being sent in the request is multipart form data, which is necessary for file uploads.
-H "Api-Key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
Here you must replace 'xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' with your actual API key provided by pdfRest.
-F "file=@/path/to/file"
This form field is used to upload the PDF file that you want to linearize. Replace '/path/to/file' with the actual file path to your PDF.
-F "output=example_out"
This form field specifies the name of the output file that will be created after the linearization process.
By following the steps outlined above, you've successfully made an API call to linearize a PDF using cURL. This allows for quicker access to PDF content over the web, enhancing the user experience. To explore the full capabilities of the pdfRest API and to see live examples, you can visit the API Lab. For a deeper understanding of all the available features and detailed documentation, refer to the API Reference Guide.
Note: This is an example of a multipart API call. Additional code samples using JSON payloads for the Linearize PDF API and other endpoints can be found at pdf-rest-api-samples.
Create your FREE API Key to start processing PDFs in seconds, only possible with pdfRest.