Fill PDF form fields in C++

Fill selected named fields

Only matching field names are filled. The sample does not inspect the Boolean result of FillField().

  1. Create a Aspose::Pdf::Facades::Form facade for the input PDF.
  2. Prepare the supplied names and values for First Name, Last Name, City, and Country.
  3. Iterate through FieldNames and match the four target names.
  4. Call FillField() on Aspose::Pdf::Facades::Form for matching fields.
  5. 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();
}