In tutorial 2 we rendered the page into a fixed size rectangle. This is simple; however, it’s not that useful. In most cases, you want to show the PDF page in its original size, or zoom in/zoom out for larger/smaller display. All these operations can be achieved by adjustment of the size parameters (the fifth and sixth parameters) of FPDF_RenderPage function.
If you want to show the page in its original size, you first need to know the original size of the page, this is easy, and you can call one of the following functions to get width and height of a page:
double page_width, page_height;
…
page_width = FPDF_GetPageWidth(pdf_page);
page_height = FPDF_GetPageHeight(pdf_page);
Please note the page width and height returned from the above two functions and are measured in typographic POINTS. In typography, one point equals to 1/72 inch, which is about 0.35 milli-miter. You can not directly pass the width or height in points into FPDF_RenderPage function, because FPDF_RenderPage accepts only pixels for screen size. Fortunately you can convert the points to pixels if you know the size of one pixel on your computer screen:
int logpixelsx, logpixelsy, size_x, size_y;
HDC hDC;
…
// get number of pixels per inch (horizontally and vertically)
logpixelsx = GetDeviceCaps(hDC, LOGPIXELSX);
logpixelsy = GetDeviceCaps(hDC, LOGPIXELSY);
// convert points into pixels
Size_x = page_width / 72 * logpixelsx;
size_y = page_height / 72 * logpixelsy;
After you get the original page size in pixels, you can use it in the FPDF_RenderPage to display the page in its original size:
…
FPDF_RenderPage(hDC, pdf_page, 10, 10, size_x, size_y, 0, 0);
Now, you may want to zoom in or out of the page on the screen. Note you can zoom both vertically and in a horizontal direction, with separate zoom factors. Again, all you need to do is to adjust the size_x and size_y parameter when you call the FPDF_RenderPage function.
The following call shows the page with 200% zoom factor:
…
FPDF_RenderPage(hDC, pdf_page, 10, 10, size_x * 2, size_y * 2, 0, 0);
While the following call shrink the page by 50%:
…
FPDF_RenderPage(hDC, pdf_page, 10, 10, size_x / 2, size_y / 2, 0, 0);