DynaPDF Manual - Page 285

Previous Page 284   Index   Next Page 286

Function Reference
Page 285 of 839
pdfSetOnErrorProc(pdf, NULL, PDFError);
pdfSetDocInfo(pdf, diAuthor, "Jens Boschulte");
pdfSetDocInfo(pdf, diCreator, "C sample project");
pdfSetDocInfo(pdf, diSubject, "How to create a PDF file in memory?");
pdfCreateNewPDF(pdf, NULL);
pdfAppend(pdf);
pdfSetFont(pdf, "Arial", fsItalic, 40.0, true, cp1252);
pdfWriteFText(pdf, taCenter, "My first memory based PDF...");
pdfEndPage(pdf);
pdfCloseFile(pdf);
// The file must be opened in binary mode!
if ((f = fopen("c:/cout.pdf", "wb")) == NULL)
{
pdfDeletePDF(pdf);
printf("Cannot open output file!");
return 3;
}
buffer = pdfGetBuffer(pdf, &bufSize); // Get the file buffer
if (buffer)
{
// We write the buffer as it is to the file.
fwrite(buffer, 1, bufSize, f);
fclose(f);
}
// We created a new PDF instance inside the function. When the
// instance is deleted all used resources are freed. However, in most
// cases it is a better way to use one PDF instance for multiple PDF
// files to improve processing speed. In the latter case we must call
// pdfFreePDF(pdf); to free the internal used resources.
pdfDeletePDF(pdf); // Delete the PDF instance
return 0;
}
Example 2: Usage of OpenOutputFile()
int main(int argc, char* argv[])
{
PPDF* pdf = pdfNewPDF();
if (!pdf) return 2; // Out of memory?
// No need to check return values.
pdfSetOnErrorProc(pdf, NULL, PDFError);
pdfSetDocInfo(pdf, diSubject, "Usage of OpenOutputFile()...");
pdfCreateNewPDF(pdf, NULL);
pdfAppend(pdf);
pdfSetFont(pdf, "Arial", fsItalic, 40.0, true, cp1252);
 

Previous topic: CreateNewPDF

Next topic: CreateOCG