Get Field Values in C++

Use Form for this task. The examples below retain the original C++ code and API Reference steps.

Inspect form fields

Enumerate field names and print each field’s current value.

  1. Create Form.
  2. Bind the PDF input with Facade::BindPdf().
  3. Read field names through Form.
  4. Read each field value with Form::GetField().
  5. Print the results or diagnostic messages shown in the example.
#include <Aspose.PDF.Cpp/Facades/Form.h>
#include <iostream>
#include <system/string.h>

namespace Facades::Examples::PDF_Form
{
using namespace System;
using namespace Aspose::Pdf;
using namespace Aspose::Pdf::Facades;
using Form = Aspose::Pdf::Facades::Form;

void InspectFormFields(String inputFile)
{
    auto form = MakeObject<Form>();
    form->Facade::BindPdf(inputFile);

    for (auto fieldName : form->get_FieldNames())
    {
        std::cout << fieldName << " = " << form->GetField(fieldName) << std::endl;
    }
}
} // namespace Facades::Examples::PDF_Form