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 returns a JSON document where each rasterized image is converted to base64 and returned in the JSON document.

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

The image returns images as jpeg, gif, bmp, png, or tiff. Then endpoint returns png images if no image type is specified.

Request/Response

RequestRequest Data
POSTForm
ResponseResponse Type
A JSON document containing array of base64 encoded images.application/json

Parameters

The endpoint allows the following parameters to customize how you wish the image converted. Every rrquest must specify a PDF as multipart/form-data.

ParametersTypeDescriptionAbbreviatedDefault
Header
AuthorizationBearer DP.V9xxxxThe API key used to authenticate endpoint.REQUIRED
Content-Typeapplication/pdfThe PDF content type.
Form Field
pdfmultipart/form-dataThe PDF document.REQUIRED
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

Response JSON

The endpoint returns a JSON document where each page is base64encoded. The JSON has the following structure.

{
"images":
[
{
"pageNumber":"--numeric-text--",
"width":--numeric--,
"height":--numeric--,
"billedPage": --numeric--,
"data" : "--base64encoded-data--"
}
],
"contentType": image/--imagetype--
"horizontalDpi": --numeric--,
"verticalDpi": --numeric--
}

The horizontalDpi and verticalDpi are both returned a points.

Run In Postman

info

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

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

{
"images": [
{
"pageNumber": "1",
"width": 816,
"height": 1056,
"billedPages": 1,
"data": "--snip--",
"contentType": "image/png"
} ]
"horizontalDpi": 96,
"verticalDpi": 96
}

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": [
{
"pageNumber": "1",
"width": 816,
"height": 1056,
"billedPages": 1,
"data": "--snip--",
"contentType": "image/png"
},
{
"pageNumber": "1",
"width": 816,
"height": 1056,
"billedPages": 1,
"data": "--snip--",
"contentType": "image/png"
},
--- repeat for each image ---
]
"horizontalDpi": 96,
"verticalDpi": 96
}

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!