Skip to main content

pdf-image


Use the pdf-image endpoint to convert pages from a PDF to images.

The pdf-image endpoint converts pages from a PDF to an image. The endpoint returns an array of base64 encoded images.

Parameters

The endpoint has the following parameters allowing customizing of the image output.

ParameterDescriptionDefault
startPageNumber1..n1
pageCount1..n0 (prints all pages)
imageFormatjpeg | gif | bmp | png | tiffpng
quality1..10060
ditheringPercent1..10025
ditheringAlgorithmfloydSteinberg | bayer | nonefloydSteinberg
colorFormatrgb | monochrome | indexdrgb
multiPagetrue | falsefalse
blackThreshold0..255na
quantizationAlgorithmoctree | webSafe | werner | wuoctree
imageSizedpi | fixed | max | percentagedpi
horizontalDpi0..n96
verticalDpi0..n96
height0..nna
width0..nna
unitmillimeter | inch | pointpoint
maxHeight0..nna
maxWidth0..nna
horizontalPercentage1..100100
verticalPercentage1..100100

Examples

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!