DynaPDF Manual - Page 814

Previous Page 813   Index   Next Page 815

Function Reference
Page 814 of 818
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;
}
}
// First we declare an error callback function.
SI32 PDF_CALL PDFError(const void* Data, SI32 ErrCode, const char* ErrMessage, SI32 ErrType)
{
printf("%s\n", ErrMessage); return 0;
}
int main(int argc, char* argv[])
{
// The structure TOutRect holds all required variables to calculate
// the output rectangle.
TOutRect r;
// The text is stored in a text file
FILE* f = fopen("c:/sample.txt", "rb");
if (f == NULL) return 2;
char* fText;
UI32 bufSize;
fseek(f, 0, SEEK_END);
bufSize = ftell(f);
fseek(f, 0, SEEK_SET);
// allocate one more character for the null-terminator
fText = (char*)malloc(bufSize +1);
fread(fText, 1, bufSize, f);
fclose(f);
fText[bufSize] = 0;
// Do NOT forget to add a null-terminator!!!
r.iPDF = pdfNewPDF(); // Get a new PDF instance
if (!r.iPDF)
// Out of memory?
{
free(fText);
return 2;
}
pdfSetOnErrorProc(r.iPDF, NULL, PDFError);
 

Previous topic: Escape Sequences, How to create multi-column text?

Next topic: WriteFTextEx, WriteText


Start Chat