Processing PDF Form Fields in C++
Benefits
- Extract, insert, and update data in PDF Forms.
Sample Projects
Code Snippet
Download the input.pdf form (highlighted below)
// this example takes the first two fields in a PDF template
// which are Name and Address
// and populates them with values of "BCL Technologies" and "Santa Clara, CA"
EasyPDFDocument::IPDFDocumentPtr oDocument;
oDocument.CreateInstance("easyPDF.PDFDocument.7");
oDocument->Open("C:\\input.pdf");
// get all form fields from the PDF
EasyPDFDocument::IFormFieldsPtr oFormFields = oDocument->FormFields;
// get the first form field
EasyPDFDocument::IFormFieldPtr oFormField = oFormFields->Item[0];
EasyPDFDocument::ITextFieldPtr oTextField;
if (oFormField->Type == EasyPDFDocument::DOC_FRMTYPE_TEXT && oFormField->Name == _bstr_t("Name"))
{
// set Name to "BCL Technologies"
oTextField = oFormField;
oTextField->Value = "BCL Technologies";
}
// get the second form field
oFormField = oFormFields->Item[1];
if (oFormField->Type == EasyPDFDocument::DOC_FRMTYPE_TEXT && oFormField->Name == _bstr_t("Address"))
{
// set Address to "Santa Clara, CA"
oTextField = oFormField;
oTextField->Value = "Santa Clara, CA";
}
oDocument->SaveAs("C:\\output.pdf");