Convert PDF to Image in Linux
To convert a PDF file to an image, send a multipart request to the /render
API endpoint, including the source document as the input. In response, you’ll receive a ZIP archive containing all of the document’s pages as images.
Rendering a document requires you to provide dimensions for the rendered pages via a width
or height
option.
Note that either the width
or height
— but not both — is required. The other dimension is calculated before rendering, so as to preserve the page aspect ratio of the rendered image.
The format of the rendered images can be controlled via a format
option. Supported image formats are png
(default), jpeg
, webp
, and tiff
.
Before you get started, make sure Processor is up and running.
Converting a PDF File on Disk to an Image
Send a request to the /render
endpoint, attaching an input file and the options JSON:
curl -X POST http://localhost:5000/render \ -F file=@Example.pdf \ -F options='{ "options": { "width": 1000, "format": "png" } }' \ -o result.zip
POST /render HTTP/1.1 Content-Type: multipart/form-data; boundary=customboundary --customboundary Content-Disposition: form-data; name="file"; filename="Example.pdf" --customboundary Content-Disposition: form-data; name="options" Content-Type: application/json { "options": { "width": 1000, "format": "png" } } --customboundary--
Converting a PDF File from a URL to an Image
Send a request to the /render
endpoint, attaching a URL pointing to an input file and the options JSON:
curl -X POST http://localhost:5000/render \ -F url=https://pspdfkit.com/downloads/examples/paper.pdf \ -F options='{ "options": { "width": 1000, "format": "png" } }' \ -o result.zip
POST /render HTTP/1.1 Content-Type: multipart/form-data; boundary=customboundary --customboundary Content-Disposition: form-data; name="url" https://pspdfkit.com/downloads/examples/paper.pdf --customboundary Content-Disposition: form-data; name="options" Content-Type: application/json { "options": { "width": 1000, "format": "png" } } --customboundary--