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
The image returns images as jpeg, gif, bmp, png, or tiff. Then endpoint returns png images if no image type is specified.
Request/Response
Request | Request Data |
---|---|
POST | Form |
Response | Response 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.
Parameters | Type | Description | Abbreviated | Default |
---|---|---|---|---|
Header | ||||
Authorization | Bearer DP.V9xxxx | The API key used to authenticate endpoint. | REQUIRED | |
Content-Type | application/pdf | The PDF content type. | ||
Form Field | ||||
pdf | multipart/form-data | The PDF document. | REQUIRED | |
URL | ||||
startPageNumber | 1..n | sp | 1 | |
pageCount | 1..n | pc | 0 (prints all pages) | |
imageFormat | jpeg | gif | bmp | png | tiff | if | png | |
quality | 1..100 | qt | 60 | |
ditheringPercent | 1..100 | dp | 25 | |
ditheringAlgorithm | floydSteinberg | bayer | none | da | floydSteinberg | |
colorFormat | rgb | monochrome | indexd | cf | rgb | |
multiPage | true | false | mp | false | |
blackThreshold | 0..255 | bt | na | |
quantizationAlgorithm | octree | webSafe | werner | wu | qa | octree | |
imageSize | dpi | fixed | max | percentage | - | dpi | |
horizontalDpi | 0..n | hd | 96 | |
verticalDpi | 0..n | vd | 96 | |
height | 0..n | ht | na | |
width | 0..n | wd | na | |
unit | millimeter | inch | point | ut | point | |
maxHeight | 0..n | mh | na | |
maxWidth | 0..n | mw | na | |
horizontalPercentage | 1..100 | hp | 100 | |
verticalPercentage | 1..100 | vp | 100 |
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.
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
}
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:
- DynamicPDF API's Endpoints - (cloud-api-overview), and
- DynamicPDF API's Client Libraries - (cloud-api-client-libraries).