From 92a06ec8d8db545f1a602c818e68d3fc1f573c44 Mon Sep 17 00:00:00 2001 From: Arnulfo Arroyo Date: Fri, 24 May 2024 11:55:20 -0500 Subject: [PATCH] Add samples for Forms Extension. These are set up to use the regular APDFL package. The modification to use the Forms Extesion package is yet to be done --- .../runConfigurations/ExportFormsData.xml | 14 ++ Forms/ExportFormsData/pom.xml | 160 ++++++++++++++++++ .../pdfl/samples/ExportFormsData.java | 88 ++++++++++ .../.idea/runConfigurations/FlattenForms.xml | 14 ++ Forms/FlattenForms/pom.xml | 160 ++++++++++++++++++ .../datalogics/pdfl/samples/FlattenForms.java | 76 +++++++++ .../runConfigurations/ImportFormsData.xml | 14 ++ Forms/ImportFormsData/pom.xml | 160 ++++++++++++++++++ .../pdfl/samples/ImportFormsData.java | 98 +++++++++++ 9 files changed, 784 insertions(+) create mode 100644 Forms/ExportFormsData/.idea/runConfigurations/ExportFormsData.xml create mode 100644 Forms/ExportFormsData/pom.xml create mode 100644 Forms/ExportFormsData/src/main/java/com/datalogics/pdfl/samples/ExportFormsData.java create mode 100644 Forms/FlattenForms/.idea/runConfigurations/FlattenForms.xml create mode 100644 Forms/FlattenForms/pom.xml create mode 100644 Forms/FlattenForms/src/main/java/com/datalogics/pdfl/samples/FlattenForms.java create mode 100644 Forms/ImportFormsData/.idea/runConfigurations/ImportFormsData.xml create mode 100644 Forms/ImportFormsData/pom.xml create mode 100644 Forms/ImportFormsData/src/main/java/com/datalogics/pdfl/samples/ImportFormsData.java diff --git a/Forms/ExportFormsData/.idea/runConfigurations/ExportFormsData.xml b/Forms/ExportFormsData/.idea/runConfigurations/ExportFormsData.xml new file mode 100644 index 00000000..41fe54a2 --- /dev/null +++ b/Forms/ExportFormsData/.idea/runConfigurations/ExportFormsData.xml @@ -0,0 +1,14 @@ + + + + + + + \ No newline at end of file diff --git a/Forms/ExportFormsData/pom.xml b/Forms/ExportFormsData/pom.xml new file mode 100644 index 00000000..1a8a7a22 --- /dev/null +++ b/Forms/ExportFormsData/pom.xml @@ -0,0 +1,160 @@ + + + 4.0.0 + com.datalogics.pdfl.samples + ExportFormsData + 1.0-SNAPSHOT + + 1.8 + 1.8 + + + + Windows64 + + + windows + amd64 + + + + win-x86-64-jni + + + + MacArm + + + mac + aarch64 + + + + mac-arm-64-jni + + + + Linux64 + + + + Linux + amd64 + + + + linux-x86-64-jni + + + + + + com.datalogics.pdfl + pdfl + 18.36.0 + pom + + + com.datalogics.pdfl + pdfl + 18.36.0 + + + com.datalogics.pdfl + pdfl + 18.36.0 + zip + ${jni.classifier} + + + com.datalogics.pdfl + pdfl + 18.36.0 + zip + resources + + + com.datalogics.pdfl + pdfl + 18.36.0 + javadoc + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.0.2 + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + unpack-resources + generate-resources + + unpack + + + + + com.datalogics.pdfl + pdfl + resources + zip + ${project.build.directory}/lib/Resources + + + + + + unpack-jni + generate-resources + + unpack + + + + + com.datalogics.pdfl + pdfl + ${jni.classifier} + zip + ${project.build.directory}/lib + + + + + + + + maven-assembly-plugin + + + package + + single + + + + + + + true + com.datalogics.pdfl.samples.ExportFormsData + + + + jar-with-dependencies + + + + + + diff --git a/Forms/ExportFormsData/src/main/java/com/datalogics/pdfl/samples/ExportFormsData.java b/Forms/ExportFormsData/src/main/java/com/datalogics/pdfl/samples/ExportFormsData.java new file mode 100644 index 00000000..442759bc --- /dev/null +++ b/Forms/ExportFormsData/src/main/java/com/datalogics/pdfl/samples/ExportFormsData.java @@ -0,0 +1,88 @@ + +package com.datalogics.pdfl.samples; + +/* + * The ExportFormsData sample demonstrates how to Export forms data from XFA and AcroForms documents: + * + * - Export data from a XFA (Dynamic or Static) document, the types supported include XDP, XML, or XFD + * - Export data from an AcroForms document, the types supported include XFDF, FDF, or XML + */ +import com.datalogics.PDFL.*; +import java.util.EnumSet; +public class ExportFormsData +{ + + public static void main(String[] args) throws Throwable { + System.out.println("ExportFormsData sample:"); + + Library lib = new Library(EnumSet.of(LibraryFlags.INIT_FORMS_EXTENSION)); + + try + { + if (!lib.isFormsExtensionAvailable()) + { + System.out.println("Forms Plugins were not properly loaded!"); + return; + } + + //Must be set to true to prevent default legacy behavior of PDFL + lib.setAllowOpeningXFA(true); + + System.out.println("Initialized the library."); + + //XFA document + String sInput = Library.getResourceDirectory() + "Sample_Input/DynamicXFA.pdf"; + String sOutput = "../ExportFormsDataXFA.xdp"; + + if (args.length > 0) + { + sOutput = args[0]; + } + + Document doc = new Document(sInput); + + //Export the data while specifying the type, in this case XDP + boolean result = doc.exportXFAFormsData(sOutput, XFAFormExportType.XDP); + + if (result) + { + System.out.println("Forms data was exported!"); + } + else + { + System.out.println("Exporting of Forms data failed!"); + } + + doc.delete(); + + //AcroForms document + sInput = Library.getResourceDirectory() + "Sample_Input/AcroForm.pdf"; + sOutput = "../ExportFormsDataAcroForms.xfdf"; + + if (args.length > 1) + { + sOutput = args[1]; + } + + doc = new Document(sInput); + + //Export the data while specifying the type, in this case XFDF + result = doc.exportAcroFormsData(sOutput, AcroFormExportType.XFDF); + + if (result) + { + System.out.println("Forms data was exported!"); + } + else + { + System.out.println("Exporting of Forms data failed!"); + } + + doc.delete(); + } + finally { + lib.delete(); + } + } +} + diff --git a/Forms/FlattenForms/.idea/runConfigurations/FlattenForms.xml b/Forms/FlattenForms/.idea/runConfigurations/FlattenForms.xml new file mode 100644 index 00000000..268218b4 --- /dev/null +++ b/Forms/FlattenForms/.idea/runConfigurations/FlattenForms.xml @@ -0,0 +1,14 @@ + + + + + + + \ No newline at end of file diff --git a/Forms/FlattenForms/pom.xml b/Forms/FlattenForms/pom.xml new file mode 100644 index 00000000..186f0027 --- /dev/null +++ b/Forms/FlattenForms/pom.xml @@ -0,0 +1,160 @@ + + + 4.0.0 + com.datalogics.pdfl.samples + FlattenForms + 1.0-SNAPSHOT + + 1.8 + 1.8 + + + + Windows64 + + + windows + amd64 + + + + win-x86-64-jni + + + + MacArm + + + mac + aarch64 + + + + mac-arm-64-jni + + + + Linux64 + + + + Linux + amd64 + + + + linux-x86-64-jni + + + + + + com.datalogics.pdfl + pdfl + 18.36.0 + pom + + + com.datalogics.pdfl + pdfl + 18.36.0 + + + com.datalogics.pdfl + pdfl + 18.36.0 + zip + ${jni.classifier} + + + com.datalogics.pdfl + pdfl + 18.36.0 + zip + resources + + + com.datalogics.pdfl + pdfl + 18.36.0 + javadoc + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.0.2 + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + unpack-resources + generate-resources + + unpack + + + + + com.datalogics.pdfl + pdfl + resources + zip + ${project.build.directory}/lib/Resources + + + + + + unpack-jni + generate-resources + + unpack + + + + + com.datalogics.pdfl + pdfl + ${jni.classifier} + zip + ${project.build.directory}/lib + + + + + + + + maven-assembly-plugin + + + package + + single + + + + + + + true + com.datalogics.pdfl.samples.FlattenForms + + + + jar-with-dependencies + + + + + + diff --git a/Forms/FlattenForms/src/main/java/com/datalogics/pdfl/samples/FlattenForms.java b/Forms/FlattenForms/src/main/java/com/datalogics/pdfl/samples/FlattenForms.java new file mode 100644 index 00000000..22429a3e --- /dev/null +++ b/Forms/FlattenForms/src/main/java/com/datalogics/pdfl/samples/FlattenForms.java @@ -0,0 +1,76 @@ + +package com.datalogics.pdfl.samples; + +/* + * + * The FlattenForms sample demonstrates how to Flatten XFA into AcroForms. + * + * - Flatten XFA (Dynamic or Static) to regular page content which converts and expands XFA fields to regular PDF content and removes the XFA fields. + * - Flatten AcroForms to regular page content which converts AcroForm fields to regular page content and removes the AcroForm fields. + * + * Copyright (c) 2024, Datalogics, Inc. All rights reserved. + */ +import com.datalogics.PDFL.*; +import java.util.EnumSet; +public class FlattenForms +{ + + public static void main(String[] args) throws Throwable { + System.out.println("FlattenForms sample:"); + + Library lib = new Library(EnumSet.of(LibraryFlags.INIT_FORMS_EXTENSION)); + + try + { + if (!lib.isFormsExtensionAvailable()) + { + System.out.println("Forms Plugins were not properly loaded!"); + return; + } + + //Must be set to true to prevent default legacy behavior of PDFL + lib.setAllowOpeningXFA(true); + + System.out.println("Initialized the library."); + + //XFA document + String sInput = Library.getResourceDirectory() + "Sample_Input/DynamicXFA.pdf"; + String sOutput = "../FlattenXFA-out.pdf"; + + if (args.length > 0) + { + sInput = args[0]; + } + + if (args.length > 1) + { + sOutput = args[1]; + } + + Document doc = new Document(sInput); + long pagesOutput = doc.flattenXFAFormFields(); + + System.out.println("XFA document was expanded into " + pagesOutput + " Flattened pages."); + + doc.save(EnumSet.of(SaveFlags.FULL, SaveFlags.LINEARIZED), sOutput); + + doc.delete(); + + //AcroForms document + sInput = Library.getResourceDirectory() + "Sample_Input/AcroForm.pdf"; + sOutput = "../FlattenAcroForms-out.pdf"; + + doc = new Document(sInput); + + doc.flattenAcroFormFields(); + + System.out.println("AcroForms document was Flattened."); + + doc.save(EnumSet.of(SaveFlags.FULL, SaveFlags.LINEARIZED), sOutput); + } + finally { + lib.delete(); + } + } +} + diff --git a/Forms/ImportFormsData/.idea/runConfigurations/ImportFormsData.xml b/Forms/ImportFormsData/.idea/runConfigurations/ImportFormsData.xml new file mode 100644 index 00000000..6fa2144d --- /dev/null +++ b/Forms/ImportFormsData/.idea/runConfigurations/ImportFormsData.xml @@ -0,0 +1,14 @@ + + + + + + + \ No newline at end of file diff --git a/Forms/ImportFormsData/pom.xml b/Forms/ImportFormsData/pom.xml new file mode 100644 index 00000000..2ccdc125 --- /dev/null +++ b/Forms/ImportFormsData/pom.xml @@ -0,0 +1,160 @@ + + + 4.0.0 + com.datalogics.pdfl.samples + ImportFormsData + 1.0-SNAPSHOT + + 1.8 + 1.8 + + + + Windows64 + + + windows + amd64 + + + + win-x86-64-jni + + + + MacArm + + + mac + aarch64 + + + + mac-arm-64-jni + + + + Linux64 + + + + Linux + amd64 + + + + linux-x86-64-jni + + + + + + com.datalogics.pdfl + pdfl + 18.36.0 + pom + + + com.datalogics.pdfl + pdfl + 18.36.0 + + + com.datalogics.pdfl + pdfl + 18.36.0 + zip + ${jni.classifier} + + + com.datalogics.pdfl + pdfl + 18.36.0 + zip + resources + + + com.datalogics.pdfl + pdfl + 18.36.0 + javadoc + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.0.2 + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + unpack-resources + generate-resources + + unpack + + + + + com.datalogics.pdfl + pdfl + resources + zip + ${project.build.directory}/lib/Resources + + + + + + unpack-jni + generate-resources + + unpack + + + + + com.datalogics.pdfl + pdfl + ${jni.classifier} + zip + ${project.build.directory}/lib + + + + + + + + maven-assembly-plugin + + + package + + single + + + + + + + true + com.datalogics.pdfl.samples.ImportFormsData + + + + jar-with-dependencies + + + + + + diff --git a/Forms/ImportFormsData/src/main/java/com/datalogics/pdfl/samples/ImportFormsData.java b/Forms/ImportFormsData/src/main/java/com/datalogics/pdfl/samples/ImportFormsData.java new file mode 100644 index 00000000..22f99700 --- /dev/null +++ b/Forms/ImportFormsData/src/main/java/com/datalogics/pdfl/samples/ImportFormsData.java @@ -0,0 +1,98 @@ + +package com.datalogics.pdfl.samples; + +/* + * + * The ImportFormsData sample demonstrates how to Import forms data into XFA and AcroForms documents: + * + * - Import data into a XFA (Dynamic or Static) document, the types supported include XDP, XML, or XFD + * - Import data into an AcroForms document, the types supported include XFDF, FDF, or XML + * + * Copyright (c) 2024, Datalogics, Inc. All rights reserved. + + */ +import com.datalogics.PDFL.*; +import java.util.EnumSet; +public class ImportFormsData +{ + + public static void main(String[] args) throws Throwable { + System.out.println("ImportFormsData sample:"); + + Library lib = new Library(EnumSet.of(LibraryFlags.INIT_FORMS_EXTENSION)); + + try + { + if (!lib.isFormsExtensionAvailable()) + { + System.out.println("Forms Plugins were not properly loaded!"); + return; + } + + //Must be set to true to prevent default legacy behavior of PDFL + lib.setAllowOpeningXFA(true); + + System.out.println("Initialized the library."); + + //XFA document + String sInput = Library.getResourceDirectory() + "Sample_Input/DynamicXFA.pdf"; + String sInputData = Library.getResourceDirectory() + "Sample_Input/DynamicXFA_data.xdp"; + String sOutput = "../ImportFormsDataXFA-out.pdf"; + + if (args.length > 0) + { + sOutput = args[0]; + } + + Document doc = new Document(sInput); + + //Import the data, acceptable types include XDP, XML, and XFD + boolean result = doc.importXFAFormsData(sInputData); + + if (result) + { + System.out.println("Forms data was imported!"); + + doc.save(EnumSet.of(SaveFlags.FULL, SaveFlags.LINEARIZED), sOutput); + } + else + { + System.out.println("Importing of Forms data failed!"); + } + + doc.delete(); + + //AcroForms document + sInput = Library.getResourceDirectory() + "Sample_Input/AcroForm.pdf"; + sInputData = Library.getResourceDirectory() + "Sample_Input/AcroForm_data.xfdf"; + sOutput = "../ImportFormsDataAcroForms.xfdf"; + + if (args.length > 1) + { + sOutput = args[1]; + } + + doc = new Document(sInput); + + //Import the data while specifying the type, in this case XFDF + result = doc.importAcroFormsData(sInputData, AcroFormImportType.XFDF); + + if (result) + { + System.out.println("Forms data was imported!"); + + doc.save(EnumSet.of(SaveFlags.FULL, SaveFlags.LINEARIZED), sOutput); + } + else + { + System.out.println("Importing of Forms data failed!"); + } + + doc.delete(); + } + finally { + lib.delete(); + } + } +} +