Add Document Action

Add a document-open action

  1. Bind the source PDF to the PdfContentEditor facade.
  2. Call addDocumentAdditionalAction(...) with the DOCUMENT_OPEN event and the JavaScript action text.
  3. Save the updated PDF document.
public static void addDocumentAction(Path inputFile, Path outputFile) {
    PdfContentEditor editor = new PdfContentEditor();
    try {
        editor.bindPdf(inputFile.toString());
        editor.addDocumentAdditionalAction(PdfContentEditor.DOCUMENT_OPEN, "app.alert('Document opened with PdfContentEditor action');");
        editor.save(outputFile.toString());
    } finally {
        editor.close();
    }
}