Skip to main content

Convert PDF to Image


Easily convert PDFs to images using The DynamicPDF API's pdf-image endpoint.

Convert PDFs to images using the pdf-image endpoint. Call the pdf-image endpoint directly or use one of our client libraries.

tip

Check out Getting Started and Task Roadmap if you are new to The DynamicPDF API.

Calling Endpoint Directly​

Call the pdf-image endpoint directly using a tool such as cURL or Postman. You can convert one or more pages of a PDF to one or more images using this endpoint. Each page from a PDF is rasterized and the endpoint returns a JSON document, where each image is a base64 encoded string.

info

Refer to the documentation for complete information on the pdf-image endpoint.

Single Page PDF​

The following examples illustrate converting a PDF to an image. In the first example it converts a single page PDF to an image. In the second example it converts only the second page from a multi-page PDF.

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

Run In Postman

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

Multi-Page PDF​

The following example illustrates converting a multi-page PDF to an image.

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

Calling Endpoint Using Client Library​

Easily convert a PDF to an image using the xxxx class or its equivalent using the C#, Java, Node.js, PHP, Go, or Python.

info

Refer to the documentation for complete information on the pdf-image endpoint.

The following example illustrates converting both a single page PDF to a png image and converting a multi-page PDF to multiple png images.

using DynamicPDF.Api;
using DynamicPDF.Api.Imaging;
using System;
using System.IO;

namespace DynamicPdfClientLibraryExamples.Examples
{
public class PdfImageExample
{
public static void Run(string apiKey, string basePath, string outputPath)
{
Process(apiKey, basePath + "onepage.pdf", outputPath + "png_single-output_");
Process(apiKey, basePath + "pdfnumberedinput.pdf", outputPath + "png_multi-output_");

}

public static void Process(string apiKey, string basePath, string outputPath)
{

PdfResource resource = new PdfResource(basePath);
PdfImage pdfImage = new PdfImage(resource);

PngImageFormat pngImageFormat = new PngImageFormat();
pdfImage.ImageFormat = pngImageFormat;
pdfImage.ApiKey = apiKey;
PdfImageResponse response = pdfImage.Process();

if (response.IsSuccessful)
{
for (int i = 0; i < response.Images.Count; i++)
{
File.WriteAllBytes(outputPath + i + ".png", Convert.FromBase64String(response.Images[i].Data));
}
}
else
{
Console.WriteLine(response.ErrorJson);
}
}
}
}
Source: PdfImageExample.cs
   Follow us on social media for latest news!