Set Field Script in C++
Contents
[
Hide
]
Use FormEditor for this task. The examples below retain the original C++ code and API Reference steps.
Set field script
Add an alert script to Script_Demo_Button, then replace it with a second alert script.
- Create FormEditor.
- Bind the PDF input with Facade::BindPdf().
- Add a field script with FormEditor::AddFieldScript().
- Replace the field script with FormEditor::SetFieldScript().
- Save the resulting PDF with SaveableFacade::Save().
#include <Aspose.PDF.Cpp/Facades/FormEditor.h>
#include <system/string.h>
namespace Facades::Examples::PDF_FormEditor
{
using namespace System;
using namespace Aspose::Pdf;
using namespace Aspose::Pdf::Facades;
void SetFieldScript(String inputFile, String outputFile)
{
auto editor = MakeObject<FormEditor>();
editor->BindPdf(inputFile);
editor->AddFieldScript(u"Script_Demo_Button", u"app.alert('Script 1 has been executed');");
editor->SetFieldScript(u"Script_Demo_Button", u"app.alert('Script 2 has been executed');");
editor->SaveableFacade::Save(outputFile);
}
} // namespace Facades::Examples::PDF_FormEditor