Skip to main content

pdf-image


Use the pdf-image endpoint to rasterize a PDF into an image.

The pdf-image endpoint takes an HTTP POST form submission, where a PDF is sent as multipart/form-data. The PDF is then rasterized into one or more images and returned from the endpoint.

POST https://api.dpdf.io/v1.0/pdf-image HTTP/1.1
Authorization: Bearer DP.xxx-api-key-xxx

A single-page PDF rasterizes into a single image which is returned as a byte-array. A multi-page PDF returns a JSON document where each rasterized image is converted to base64 and returned in the JSON document.

info

Refer to pdf-image in the Client Libraries section of the Users Guide for this endpoint using the DynamicPDF API's client libraries.

Request/Response

RequestRequest Data
POSTForm
ResponseResponse Type
The expected image format and the image as binary.image/image-typeimage/png, image/tiff, image/bmp, etc.
-OR-
A JSON document containing array of base64 encoded images.application/json
info

A PDF can have multiple pages. If the PDF consists of a single page, then the image is returned as a byte-array. If the PDF consists of multiple pages, then each image is returned as a base64 encoded string in a JSON document.

{
"images": [
"base64string image data page1",
"base64string image data page2",
"base64string image data page3"
],
"contentType": "image/png"
}

Parameters

ParametersTypeDescriptionAbbreviatedDefault
Header
AuthorizationBearer DP.V9xxxxThe API key used to authenticate endpoint.
Content-Typeapplication/pdfThe PDF content type.
Form Field
pdfmultipart/form-dataThe PDF document.
URL
startPageNumber1..nsp1
pageCount1..npc0 (prints all pages)
imageFormatjpeg | gif | bmp | png | tiffifpng
quality1..100qt60
ditheringPercent1..100dp25
ditheringAlgorithmfloydSteinberg | bayer | nonedafloydSteinberg
colorFormatrgb | monochrome | indexdcfrgb
multiPagetrue | falsempfalse
blackThreshold0..255btna
quantizationAlgorithmoctree | webSafe | werner | wuqaoctree
imageSizedpi | fixed | max | percentage-dpi
horizontalDpi0..nhd96
verticalDpi0..nvd96
height0..nhtna
width0..nwdna
unitmillimeter | inch | pointutpoint
maxHeight0..nmhna
maxWidth0..nmwna
horizontalPercentage1..100hp100
verticalPercentage1..100vp100

Run In Postman

Example Request/Response

The following example illustrates calling the pdf-image endpoint using a single-page PDF followed by a multi-page PDF.

Single Image

A PDF consisting of a single page returns a binary-array.

Example Request

curl https://api.dpdf.io/v1.0/pdf-image 
-H"Authorization:Bearer DP--api-key--"
-F "pdf=@C:/temp/dynamicpdf-api-samples/pdf-image/onepage.pdf"
-o simple-image.png

Example Response

Multiple Images

A PDF consisting of multiple pages results in a JSON document where each rasterized page is a base64 encoded string.

Example Request

curl https://api.dpdf.io/v1.0/pdf-image 
-H"Authorization:Bearer DP--api-key--"
-F "pdf=@C:/temp/dynamicpdf-api-samples/pdf-image/multipage.pdf"
-o images.json

Example Response

{
"images":["--snip--","--snip--"],
"contentType":"image/png"
}

tip

Use the startPage and pageCount query string parameters to extract a single-page from a multi-page PDF. For example, the following cURL command extracts and converts only the second page from the PDF in the previous example.

curl "https://api.dpdf.io/v1.0/pdf-image?sp=2&pc=1" 
-H"Authorization:Bearer DP--api-key--"
-F "pdf=@C:/temp/dynamicpdf-api-samples/pdf-image/multipage.pdf"
-o simple-image.png

Further Information

You can also use one of DynamicPDF's provided client libraries to integrate the endpoints into your client applications if you prefer. For more information, refer to the relevant Users Guide sections:

   Follow us on social media for latest news!