DynaPDF Manual - Page 834

Previous Page 833   Index   Next Page 835

Function Reference
Page 834 of 839
incomming text cannot contain alignment or command tags. Line breaks and so on are still
processed as usual but all kinds of alignment and command tags will be interpreted as plain text.
How to create multi-column text?
WriteFText() supports a callback function which can be used to create various formattings. The
callback function is required to print text into multiple columns.
The Visual Basic and VB .Net interfaces use events instead of callback functions. However, the usage
is identical but the event must be manually connected with the function ConnectPageBreakEvent()
so that the event can be raised.
A good example to demonstrate the usage of the callback function is the output of multi-column
text. In the following example we have a text file that contains the text that should be printed. The
text that we use in this example is not of interest, it must only be large enough so that WriteFText()
generates an OnPageBreak event. Note that it is also possible to create this event manually with the
command tag \np#.
Example (C++):
First, we define a structure which contains all variables we need to calculate the output rectangle.
We pass this structure to the SetOnPageBreakProc() function so that we don't need any global data.
struct TOutRect
{
void* iPDF;
// Active PDF instance
double PosX;
// X-coordinate of first output rectangle
double PosY;
// Y-coordinate of first output rectangle
double Width;
// Original width of the output rectangle
double Height;
// Original height of the output rectangle
double Distance; // Space between columns
SI32 Column;
// Current column
SI32 ColCount; // Number of columns
};
// This is our callback function
SI32 PDF_CALL OnPageBreakProc(const void* Data, double LastPosX, double LastPosY, SI32 PageBreak)
{
TOutRect* r = (TOutRect*)Data; // get a pointer to our structure
pdfSetPageCoords(r->iPDF, pcTopDown); // we use top-down coordinates
if (!PageBreak && r->Column < r->ColCount -1)
{
++r->Column;
// Calculate the x-coordinate of the column
double posX = r->PosX + r->Column * (r->Width + r->Distance);
// change the output rectangle, do not close the page!
pdfSetTextRect(r->iPDF, posX, r->PosY, r->Width, r->Height);
switch(r->Column)
{
case 1: return NEW_ALIGN_JUSTIFY;
case 2: return NEW_ALIGN_RIGHT;
default: return 0; // do not change the alignment
}
}else
{
// the page is full, close the current one and append a new page
pdfEndPage(r->iPDF);
pdfAppend(r->iPDF);
pdfSetTextRect(r->iPDF, r->PosX, r->PosY, r->Width, r->Height);
r->Column = 0;
return NEW_ALIGN_LEFT;
 

Previous topic: Escape Sequences

Next topic: WriteFTextEx, WriteText