Foxit Quick PDF Library

Convert an image to PDF programmatically

Converting an image to PDF is simple using Foxit Quick PDF Library. The key functions involved are AddImageFromFile and DrawImage. The size of the image drawn onto the PDF is determined by the DPI value of the image (if present). The ImageHorizontalResolution and ImageVerticalResolution functions return the necessary DPI information.

PNG and GIF image files do not have a DPI setting, however, image types such as BMP, JPEG and TIFF all do. A DPI value of 72 is presumed if a DPI setting is not found in the image.

int id = DPL.AddImageFromFile("example_image.jpg", 0);

DPL.SelectImage(id);

int dpix = DPL.ImageHorizontalResolution();
int dpiy = DPL.ImageVerticalResolution();

if (dpix == 0) dpix = 72;
if (dpiy == 0) dpiy = 72;

double ImageWidthInPoints = (double)DPL.ImageWidth() / dpix * 72.0; // assumming dpi units
double ImageHeightInPoints = (double)DPL.ImageHeight() / dpiy * 72.0;

DPL.SetPageDimensions(ImageWidthInPoints, ImageHeightInPoints);
DPL.SetOrigin(1);
DPL.DrawImage(0, 0, ImageWidthInPoints, ImageHeightInPoints);

DPL.SaveToFile("converted_image.pdf");

This article refers to a deprecated product. If you are looking for support for Foxit PDF SDK, please click here.

Updated on May 16, 2022

Was this article helpful?
Thanks for your feedback. If you have a comment on how to improve the article, you can write it here: