DynaPDF Manual - Page 835

Previous Page 834   Index   Next Page 836

Function Reference
Page 835 of 839
}
}
// 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);
pdfSetDocInfo(r.iPDF, diCreator, "C++ test app");
pdfSetDocInfo(r.iPDF, diSubject, "Multi-column text");
pdfSetDocInfo(r.iPDF, diTitle, " Multi-column text ");
// We use top-down coordinates
pdfSetPageCoords(r.iPDF, pcTopDown);
pdfCreateNewPDF(r.iPDF, "c:/cppout.pdf");
pdfAppend(r.iPDF);
pdfSetFont(r.iPDF, "Arial", fsNone, 8.0, true, cp1252);
r.ColCount = 3;
r.Column
= 0;
r.Distance = 5.0;
r.PosX
= 50.0;
r.PosY
= 50.0;
r.Height
= 150.0;
r.Width
= (pdfGetPageWidth(r.iPDF) - 100.0 - (r.ColCount -1) * r.Distance) / r.ColCount;
// The structure is passed to the callback function now
pdfSetOnPageBreakProc(r.iPDF, &r, OnPageBreakProc);
// Set the output rectangle first
pdfSetTextRect(r.iPDF, r.PosX, r.PosY, r.Width, r.Height);
pdfWriteFText(r.iPDF, taLeft, fText); // Now we can print the text
free(fText);
// free the text buffer
pdfEndPage(r.iPDF);
// Close the last page
pdfCloseFile(r.iPDF); // Close the file
pdfDeletePDF(r.iPDF); // Delete the PDF instance
}
 

Previous topic: How to create multi-column text?

Next topic: WriteFTextEx, WriteText