DynaPDF Manual - Page 673
Previous Page 672 Index Next Page 674
Function Reference
Page 673 of 860
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().
Remarks:
The function outputs errors and warnings into the error log of the corresponding PDF instance. The
caller should check for errors by calling GetErrLogMessageCount() when the function returns. The
error log can be cleared when the messages were processed with ClearErrorLog().
Return values:
When the page was fully rendered the return value is 1. When the page was not fully processed, e.g.
due to errors, the return value is 0.
Example (C#):
int PDFError(IntPtr Data, int ErrCode, IntPtr ErrMessage, int ErrType)
{
MessageBox.Show(System.Runtime.InteropServices.Marshal.PtrToStringAnsi(ErrMessage));
return 0;
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
m_PDF.SetOnErrorProc(IntPtr.Zero, new TErrorProc(PDFError));
Previous topic: UpdateOnImageCoverage limit, The return value, Multi-Threading strategies
Next topic: RenderPageEx (Rendering Engine)