1. Home
  2. Foxit Quick PDF Library
  3. Render a PDF as an image with an asymmetrical DPI

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
QP.NewPage();
 
// 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
QP.SetOrigin(1);  
 
// 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");
Updated on March 26, 2017

Was this article helpful?

Related Articles

Ready to try Foxit PDF SDK?
Click the link below to download your trial
Free Trial