DynaPDF Manual - Page 30

Previous Page 29   Index   Next Page 31

Language Bindings
Page 30 of 818
// Include the DynaPDF header file (change the path if necessary)
#include "dynapdf.h"
// All data types and functions are declared in the namespace DynaPDF.
using namespace DynaPDF;
// First, we declare an error callback function that is called by
// DynaPDF if an error occurred.
SI32 PDF_CALL PDFError(const void* Data, SI32 ErrCode, const char*
ErrMessage, SI32 ErrType)
char errMsg[PDF_MAX_ERR_LEN + 30];
// An error message returned by DynaPDF is a pointer to a null-
// terminated static string.
sprintf(errMsg, "%s\n\nAbort processing?\n", ErrMessage);
if (MessageDlg(errMsg, mtError,
TMsgDlgButtons() << mbYes << mbNo, 0) == mrYes)
return -1; // break processing
return 0;
// ignore the error
// Place a button on the form and double click on it. Add the
// following code to the function.
void __fastcall TForm1::Button1Click(TObject *Sender)
void* pdf = pdfNewPDF(); // Create a new PDF instance
if (!pdf) return; // Out of memory?
// Set the error callback first
pdfSetOnErrorProc(pdf, NULL, PDFError);
pdfCreateNewPDF(pdf, "c:/myfirst.pdf");
pdfSetDocInfo(pdf, diSubject, "My first C++ output");
pdfSetDocInfo(pdf, diProducer, "C++ Builder test application");
pdfSetDocInfo(pdf, diTitle, "My first C++ output");
// We want to use top-down coordinates
pdfSetPageCoords(pdf, pcTopDown);
pdfSetFont(pdf, "Arial", DynaPDF::fsItalic, 40.0, true, cp1252);
pdfWriteFText(pdf, DynaPDF::taCenter, "My first C++ output!");
pdfCloseFile(pdf); // Close the file and free all used resources
pdfDeletePDF(pdf); // Do not forget to delete the PDF instance

Previous topic: Embarcadero C++ Builder

Next topic: Microsoft Visual C++

Start Chat