DynaPDF Manual - Page 652
Previous Page 651 Index Next Page 653
Function Reference
Page 652 of 839
m_Pages[m_PageNum-1] = pdfGetPageObject(m_PDF, m_PageNum);
}
• Inititialize the structure TPDFRastertImage and create a new thread in the priority lower or
normal.
• Now you can start the thread. The thread executes only the function RenderPage(), finish!
The window must be updated via the TOnUpdateWindow callback function.
• When the user requests to load another page or PDF file then call rasAbort(m_RasPtr); from
the main thread (m_RasPtr represents the instance pointer of the rasterizer), wait until the
thread returns and delete it.
• Now you can load another file, page, or change the zoom settings and so on.
Make sure that you don't execute non-thread-safe code in the TOnUpdateWindow callback function
or in the error callback function.
Especially the error callback function should not directly add the error message to a list component
or something similar when the component is not thread-safe. Note that such components try to
render the text when it is added to the list. Such an action is critical when performed from another
thread. It is mostly better to copy the message into an array and to add it to the list component when
the error form is displayed. Such details can avoid a lot of possible multi-threading issues which are
very often difficult to reproduce.
In the previous description there is only one thread running at a time. The current implementation
of RenderPage() does definitely not allow the usage in multiple threads simultaneously. If possible
this limitation will be removed in future versions but due to the many possible collusions it is
currently not sure whether this makes sense. There are also not many situations in which it would
be useful to render pages in background since you don't know what the user wants to do next. In
most cases additional threads waste processing time and memory and the application becomes often
slower and not faster.
How to save the image on disk?
DynaPDF contains a few helper functions to store the rendered image in a proprietary image format
when necessary. These functions are CreateImage(), AddRasImage(), CloseImage(), and
GetImageBuffer(). These functions support the creation of single- and multi-page images, as well as
in-memory or file output.
The image buffer should be created in the correct pixel format because AddRasImage() performs no
color conversion. For example, Windows Bitmaps support the pixel formats BGR and BGRA but no
RGB or RGBA. All other image formats require pixels in the natural component order, e.g. RGB or
RGBA.
AddRasImage() accepts also image buffers in a wrong component order but the caller is responsible
to convert the buffer if necessary before calling the function.
The entire PDF file can be converted to an arbitrary image format with RenderPDFFile().
Previous topic: Multi-Threading strategies
Next topic: RenderPageEx (Rendering Engine)