Fill PDF form fields in C++
Contents
[
Hide
]
Fill selected named fields
Only matching field names are filled. The sample does not inspect the Boolean result of FillField().
- Create a Aspose::Pdf::Facades::Form facade for the input PDF.
- Prepare the supplied names and values for First Name, Last Name, City, and Country.
- Iterate through FieldNames and match the four target names.
- Call FillField() on Aspose::Pdf::Facades::Form for matching fields.
- Save the facade to outputFile and close it.
#include <Aspose.PDF.Cpp/Facades/Form.h>
#include <system/io/file.h>
#include <system/io/path.h>
using namespace System;
using namespace Aspose::Pdf;
void FormExamples::FillForm(String inputFile, String outputFile)
{
auto form = MakeObject<Aspose::Pdf::Facades::Form>(inputFile);
const String names[] = {u"First Name", u"Last Name", u"City", u"Country"};
const String values[] = {u"Alexander_New", u"Greenfield_New", u"Yellowtown_New", u"Redland_New"};
for (const auto &fieldName : form->get_FieldNames())
for (int i = 0; i < 4; ++i)
if (fieldName == names[i])
form->FillField(fieldName, values[i]);
form->Save(outputFile);
form->Close();
}