Back to Blog

    Developer Blog

    Render a PDF as an image with an asymmetrical DPI

    Foxit Quick PDF Library

    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");
    

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