DynaPDF Manual - Page 648

Previous Page 647   Index   Next Page 649

Function Reference
Page 648 of 839
Whether a frame rectangle should be drawn or not depends on the way how a page is rendered into
the destination window. If the viewer processes mainly simple PDF files then it is possible to render
pages simply on demand. The page can then directly be scaled into the destination image and in this
case it is usually best to draw the page into a frame rectangle.
However, scrolling and zooming becomes too slow when more complex pages must be rendered. To
achieve optimal processing speed as well as smoth and flicker free scrolling the viewer should
render the page into an image in the size of the scaled page format so that the finish image can be
scrolled. The background or the frame rectangle must be drawn by the viewer application in this
To calculate the required image size in pixels the rendering engine provides helper functions to
access the page's bounding boxes as well as the page orientation fast as possible (see GetPageBBox()
and GetPageOrientation()).
The image size can be calculated as follows (C++):
UI32 w = 0, h = 0;
UI32 fw = 2540, fh = 1440; // Size of output rectangle in pixels
// Get a pointer of the page object to enable fast access to the page
// properties.
IPGE* pagePtr = pdfGetPageObject(m_PDF, pageNum);
// CalcPagePixelSize() returns the height of the image in this example.
// RenderPage() calculates the image size in the exact same way when
// called with the same parameters.
// Now you can allocate the image buffer or check whether the existing
// one is large enough.
if (w != lastWidth || h != lastHeight)
Calculating the size of the image buffer is easy, and scrolling is easy too when the zoom factor is
100%. The handling of other zoom factors is the most complex part in a viewer application. For
zoom factors between 10% and 200% it is usually best to render the entire page as described above
but larger zoom factors cannot be handled in this way because at some point the image becomes too
large and the rendering time would become too long.
For larger zoom factors it is mostly better to render the page directly with the required zoom factor
into the client rectangle since the rasterizer can then skip invisible objects to speed up processing.
The Transformation Matrix
The transformation matrix can be used to scroll the page up and down, and to scale it with an
arbitrary zoom factor, or to rotate it if necessary. The matrix must be defined in device space, that is

Previous topic: Rendering PDF Pages

Next topic: The OnUpdateWindow Event