Skip to main content

Convert Images to PDFs


Convert images to PDF using the pdf endpoint.

The pdf endpoint makes converting images to PDF a breeze. Supported image types include the following nine common image types: JPEG, PNG, BMP, EMF, WMF, EXIF, JPEG2000, GIF, and TIFF.

The following examples illustrate converting a TIFF and a PNG image to a combined PDF.

info

You can also add an image to a PDF you create from scratch or add to an existing PDF.

tip

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

info

See the image input type documentation for more information.

   Follow us on social media for latest news!

Calling Endpoint Directly

The following JSON instructions document illustrates converting two different images to a combined PDF.

{
"author": "CeteSoftware",
"creator": "DynamicPDF Cloud Api",
"inputs": [
{
"type": "image",
"resourceName":"testimage.tif",
"pageWidth": 612,
"pageHeight":1008,
"expandToFit":false,
"align": "center",
"vAlign": "center"
},
{
"type": "image",
"resourceName":"dynamicpdfLogo.png",
"pageWidth": 1008,
"pageHeight":612,
"expandToFit":true,
"align": "center",
"vAlign": "center"
}
]
}

Run In Postman

curl --location 'https://api.dpdf.io/v1.0/pdf'
--header 'Authorization: Bearer DP.BKMFqqItEDZb9iBeSAJvzZAgqhH6oyY9SBiKezfyw+rTRosKxx0oD9f9'
--form 'Instructions=@C:/temp/solutions/image-conversion/instructions.json'
--form 'Resource=@C:/temp/solutions/image-conversion/testimage.tif'
--form 'Resource=@C:/temp/solutions/image-conversion/dynamicpdfLogo.png'

Calling Endpoint Using Client Library

The following examples illustrate converting two images to a combined PDF using the six different client libraries.

public static void Run(string apiKey, string basePath, string outputPath)
{
Pdf pdf = new Pdf();
pdf.ApiKey = apiKey;

ImageResource imageResource = new ImageResource(basePath + "testimage.tif");
ImageInput imageInput = pdf.AddImage(imageResource);
imageInput.Align = Align.Center;
imageInput.VAlign = VAlign.Center;
imageInput.ExpandToFit = false;
imageInput.PageHeight = 1008;
imageInput.PageWidth = 612;

ImageResource imageResourceTwo = new ImageResource(basePath + "dynamicpdfLogo.png");
ImageInput imageInputTwo = pdf.AddImage(imageResourceTwo);

imageInputTwo.Align = Align.Center;
imageInputTwo.VAlign = VAlign.Center;
imageInputTwo.ExpandToFit = true;
imageInputTwo.PageHeight = 612;
imageInputTwo.PageWidth = 1008;

PdfResponse pdfResponse = pdf.Process();

if (pdfResponse.IsSuccessful)
{
File.WriteAllBytes(outputPath + "/convert-img-to-pdf-output.pdf", pdfResponse.Content);
}
else
{
Console.WriteLine(pdfResponse.ErrorJson);
}
}
Source: ImageConversion.cs
info

The pdf endpoint takes a JSON instructions document that provides instructions for creating, transforming, merging, and formatting inputs into a combined PDF. Refer to documentation on the instructions schema for information on how to use the pdf endpoint.