Add Document Action in C++

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

Add document action

Assign an alert script to the document-open additional action.

  1. Create PdfContentEditor.
  2. Bind the PDF input with Facade::BindPdf().
  3. Set the document action with PdfContentEditor::AddDocumentAdditionalAction().
  4. Save the resulting PDF with PdfContentEditor::Save().
#include <Aspose.PDF.Cpp/Facades/PdfContentEditor.h>
#include <system/string.h>

namespace Facades::Examples::PDF_ContentEditor
{
using namespace System;
using namespace Aspose::Pdf;
using namespace Aspose::Pdf::Facades;

void AddDocumentAction(String inputFile, String outputFile)
{
    auto editor = MakeObject<PdfContentEditor>();

    editor->BindPdf(inputFile);
    editor->AddDocumentAdditionalAction(PdfContentEditor::DocumentOpen,
                                        u"app.alert('Document opened with PdfContentEditor action');");
    editor->Save(outputFile);
}
} // namespace Facades::Examples::PDF_ContentEditor