Convert XFA forms to AcroForms in C++

Convert a dynamic XFA form

  1. Open the input PDF as a Document.
  2. Get Aspose::Pdf::Forms::Form and set its Type to FormType::Standard.
  3. Save the PDF with Save().
#include <Aspose.PDF.Cpp/Document.h>
#include <Aspose.PDF.Cpp/InteractiveFeatures/Forms/Form.h>
#include <Aspose.PDF.Cpp/InteractiveFeatures/Forms/FormType.h>

using namespace System;
using namespace Aspose::Pdf;
using namespace Aspose::Pdf::Forms;

void FormExamples::ConvertDynamicXfaToAcroform(String inputFile, String outputFile)
{
    auto document = MakeObject<Document>(inputFile);
    document->get_Form()->set_Type(FormType::Standard);
    document->Save(outputFile);
}

Convert with an XFA rendering-flag check

Review the converted fields and appearance for your input, especially when ignoring a rendering requirement.

  1. Open the input PDF as a Document.
  2. Get Aspose::Pdf::Forms::Form and check that it is not null.
  3. When HasXfa and NeedsRendering are true, set IgnoreNeedsRendering to true.
  4. Set Type to FormType::Standard.
  5. Save the PDF with Save().
#include <Aspose.PDF.Cpp/Document.h>
#include <Aspose.PDF.Cpp/InteractiveFeatures/Forms/Form.h>
#include <Aspose.PDF.Cpp/InteractiveFeatures/Forms/FormType.h>

using namespace System;
using namespace Aspose::Pdf;
using namespace Aspose::Pdf::Forms;
using namespace Aspose::Pdf::Annotations;
using namespace Aspose::Pdf::Text;

void FormExamples::ConvertXfaFormWithIgnoreNeedsRendering(String inputFile, String outputFile)
{
    auto document = MakeObject<Document>(inputFile);
    auto form = document->get_Form();

    if (form != nullptr)
    {
        if (form->get_HasXfa() && form->get_NeedsRendering())
        {
            form->set_IgnoreNeedsRendering(true);
        }
        form->set_Type(FormType::Standard);
    }

    document->Save(outputFile);
}