Foxit Quick PDF Library

Render a PDF as an image with an asymmetrical DPI

The current rendering engine is set up to use the same DPI setting for both the horizontal and vertical axis. So it isn’t possible to render an image with an asymmetrical DPI, however, it is possible to get the same effect though by stretching the page.

Here’s some pseudo code that shows how to do this:

QP.LoadFromFile("FaxTest-Letter.pdf", "");
QP.RenderPageToFile(204, 1, 5, "same-dpi.png");

// Get the original size of the page
double OriginalWidth = QP.PageWidth();
double OriginalHeight := QP.PageHeight();

// Add a new page

// Work out the asymmetrical scaling
double NewWidth = OriginalWidth;
double NewHeight = OriginalHeight * 196 / 204;

// Set the dimensions of the new page
QP.SetPageDimensions(NewWidth, NewHeight);

// Capture the original page (it will be removed
// from the document automatically)
int CaptureID = QP.CapturePage(1);

// Set the original to the top-left corner

// Draw the captured page onto the new page
QP.DrawCapturedPage(CaptureID, 0, 0, NewWidth, NewHeight);

// Render the page
QP.RenderPageToFile(204, 1, 5, "different-dpi.png");

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: