PDF Forms. Manage via C++

Manage Acroforms in PDF document using Aspose.PDF for C++ Library

Most popular actions with Acroforms in C++

How to Manage PDF Forms Using C++ Library

In order to add PDF Forms (Acroforms) in PDF file, we’ll use Aspose.PDF for C++ API which is a feature-rich, powerful and easy to use document manipulation API for cpp platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Package Manager Console

PM > Install-Package Aspose.PDF.Cpp

How to Create PDF Forms using C++


You need Aspose.PDF for C++ to try the code in your environment.

  1. Load PDF in an instance of Document class.
  2. Access the Page via its index.
  3. Call the Form collection’s Add method.
  4. Create the form field you want to add.
  5. Save the PDF file.

Create PDF Forms in PDF - C++

This sample code shows how to Create PDF Forms in PDF using C++

    // Open document
    auto document = MakeObject<Document>(_dataDir + u"TextField.pdf");

    // Create a field
    auto textBoxField = MakeObject<TextBoxField>(document->get_Pages()->idx_get(1), MakeObject<Aspose::Pdf::Rectangle>(100, 200, 300, 300));
    textBoxField->set_PartialName (u"textbox1");
    textBoxField->set_Value (u"Text Box");

    // TextBoxField.Border = new Border(
    auto border = MakeObject<Aspose::Pdf::Annotations::Border>(textBoxField);
    border->set_Width(5);
    border->set_Dash (MakeObject<Aspose::Pdf::Annotations::Dash>(1, 1));
    textBoxField->set_Border(border);

    textBoxField->set_Color(Aspose::Pdf::Color::get_Green());

    // Add field to the document
    document->get_Form()->Add(textBoxField, 1);

    // Save modified PDF
    document->Save(_dataDir + u"TextBox_out.pdf");