diff --git a/Forms/ConvertXFAToAcroForms/ConvertXFAToAcroForms.cs b/Forms/ConvertXFAToAcroForms/ConvertXFAToAcroForms.cs new file mode 100644 index 0000000..05800f2 --- /dev/null +++ b/Forms/ConvertXFAToAcroForms/ConvertXFAToAcroForms.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Datalogics.PDFL; + +/* + * + * The ConvertXFAToAcroForms sample demonstrates how to convert XFA into AcroForms. + * Converts XFA (Dynamic or Static) fields to AcroForms fields and removes XFA fields. + * Copyright (c) 2024, Datalogics, Inc. All rights reserved. + * + */ +namespace ConvertXFAToAcroForms +{ + class ConvertXFAToAcroForms + { + static void Main(string[] args) + { + Console.WriteLine("ConvertXFAToAcroForms Sample:"); + + using (Library lib = new Library(LibraryFlags.InitFormsExtension)) + { + if (!lib.IsFormsExtensionAvailable()) + { + System.Console.Out.WriteLine("Forms Plugins were not properly loaded!"); + return; + } + + lib.AllowOpeningXFA = true; + + Console.WriteLine("Initialized the library."); + + String sInput = Library.ResourceDirectory + "Sample_Input/DynamicXFA.pdf"; + String sOutput = "../ConvertXFAToAcroForms-out.pdf"; + + if (args.Length > 0) + { + sInput = args[0]; + } + + if (args.Length > 1) + { + sOutput = args[1]; + } + + using (Document doc = new Document(sInput)) + { + UInt32 pagesOutput = doc.ConvertXFAFieldsToAcroFormFields(); + + Console.WriteLine("XFA document was converted into an AcroForms document with {0} pages.", pagesOutput); + + doc.Save(SaveFlags.Full | SaveFlags.Linearized, sOutput); + } + } + } + } +} diff --git a/Forms/ConvertXFAToAcroForms/ConvertXFAToAcroForms.csproj b/Forms/ConvertXFAToAcroForms/ConvertXFAToAcroForms.csproj new file mode 100644 index 0000000..8ea29b4 --- /dev/null +++ b/Forms/ConvertXFAToAcroForms/ConvertXFAToAcroForms.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + diff --git a/Forms/ExportFormsData/ExportFormsData.cs b/Forms/ExportFormsData/ExportFormsData.cs new file mode 100644 index 0000000..901f0a8 --- /dev/null +++ b/Forms/ExportFormsData/ExportFormsData.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Datalogics.PDFL; + +/* + * 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 + * + * Copyright (c) 2024, Datalogics, Inc. All rights reserved. + * + */ +namespace ExportFormsData +{ + class ExportFormsData + { + static void Main(string[] args) + { + Console.WriteLine("ExportFormsData Sample:"); + + using (Library lib = new Library(LibraryFlags.InitFormsExtension)) + { + if (!lib.IsFormsExtensionAvailable()) + { + System.Console.Out.WriteLine("Forms Plugins were not properly loaded!"); + return; + } + + lib.AllowOpeningXFA = true; + + Console.WriteLine("Initialized the library."); + + //XFA document + String sInput = Library.ResourceDirectory + "Sample_Input/DynamicXFA.pdf"; + String sOutput = "../ExportFormsDataXFA.xdp"; + + if (args.Length > 0) + { + sOutput = args[0]; + } + + using (Document doc = new Document(sInput)) + { + //Export the data while specifying the type, in this case XDP + bool result = doc.ExportXFAFormsData(sOutput, XFAFormExportType.XDP); + + if (result) + { + Console.Out.WriteLine("Forms data was exported!"); + } + else + { + Console.Out.WriteLine("Exporting of Forms data failed!"); + } + } + + //AcroForms document + sInput = Library.ResourceDirectory + "Sample_Input/AcroForm.pdf"; + sOutput = "../ExportFormsDataAcroForms.xfdf"; + + if (args.Length > 1) + { + sOutput = args[1]; + } + + using (Document doc = new Document(sInput)) + { + //Export the data while specifying the type, in this case XFDF + bool result = doc.ExportAcroFormsData(sOutput, AcroFormExportType.XFDF); + + if (result) + { + Console.Out.WriteLine("Forms data was exported!"); + } + else + { + Console.Out.WriteLine("Exporting of Forms data failed!"); + } + } + } + } + } +} diff --git a/Forms/ExportFormsData/ExportFormsData.csproj b/Forms/ExportFormsData/ExportFormsData.csproj new file mode 100644 index 0000000..8ea29b4 --- /dev/null +++ b/Forms/ExportFormsData/ExportFormsData.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + diff --git a/Forms/FlattenForms/FlattenForms.cs b/Forms/FlattenForms/FlattenForms.cs new file mode 100644 index 0000000..6f198bb --- /dev/null +++ b/Forms/FlattenForms/FlattenForms.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Datalogics.PDFL; + +/* + * + * 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. + * + */ +namespace FlattenForms +{ + class FlattenForms + { + static void Main(string[] args) + { + Console.WriteLine("FlattenForms Sample:"); + + using (Library lib = new Library(LibraryFlags.InitFormsExtension)) + { + if (!lib.IsFormsExtensionAvailable()) + { + System.Console.Out.WriteLine("Forms Plugins were not properly loaded!"); + return; + } + + //Must be set to true to prevent default legacy behavior of PDFL + lib.AllowOpeningXFA = true; + + Console.WriteLine("Initialized the library."); + + //XFA document + String sInput = Library.ResourceDirectory + "Sample_Input/DynamicXFA.pdf"; + String sOutput = "../FlattenXFA-out.pdf"; + + if (args.Length > 0) + { + sInput = args[0]; + } + + if (args.Length > 1) + { + sOutput = args[1]; + } + + using (Document doc = new Document(sInput)) + { + UInt32 pagesOutput = doc.FlattenXFAFormFields(); + + Console.WriteLine("XFA document was expanded into {0} Flattened pages.", pagesOutput); + + doc.Save(SaveFlags.Full | SaveFlags.Linearized, sOutput); + } + + //AcroForms document + sInput = Library.ResourceDirectory + "Sample_Input/AcroForm.pdf"; + sOutput = "../FlattenAcroForms-out.pdf"; + + using (Document doc = new Document(sInput)) + { + doc.FlattenAcroFormFields(); + + Console.WriteLine("AcroForms document was Flattened."); + + doc.Save(SaveFlags.Full | SaveFlags.Linearized, sOutput); + } + } + } + } +} diff --git a/Forms/FlattenForms/FlattenForms.csproj b/Forms/FlattenForms/FlattenForms.csproj new file mode 100644 index 0000000..8ea29b4 --- /dev/null +++ b/Forms/FlattenForms/FlattenForms.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + diff --git a/Forms/ImportFormsData/ImportFormsData.cs b/Forms/ImportFormsData/ImportFormsData.cs new file mode 100644 index 0000000..16b9c53 --- /dev/null +++ b/Forms/ImportFormsData/ImportFormsData.cs @@ -0,0 +1,90 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Datalogics.PDFL; + +/* + * 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. + */ +namespace ImportFormsData +{ + class ImportFormsData + { + static void Main(string[] args) + { + Console.WriteLine("ImportFormsData Sample:"); + + using (Library lib = new Library(LibraryFlags.InitFormsExtension)) + { + if (!lib.IsFormsExtensionAvailable()) + { + System.Console.Out.WriteLine("Forms Plugins were not properly loaded!"); + return; + } + + lib.AllowOpeningXFA = true; + + Console.WriteLine("Initialized the library."); + + //XFA document + String sInput = Library.ResourceDirectory + "Sample_Input/DynamicXFA.pdf"; + String sInputData = Library.ResourceDirectory + "Sample_Input/DynamicXFA_data.xdp"; + String sOutput = "../ImportFormsDataXFA-out.pdf"; + + if (args.Length > 0) + { + sOutput = args[0]; + } + + using (Document doc = new Document(sInput)) + { + //Import the data, acceptable types include XDP, XML, and XFD + bool result = doc.ImportXFAFormsData(sInputData); + + if (result) + { + Console.Out.WriteLine("Forms data was imported!"); + + doc.Save(SaveFlags.Full | SaveFlags.Linearized, sOutput); + } + else + { + Console.Out.WriteLine("Importing of Forms data failed!"); + } + } + + //AcroForms document + sInput = Library.ResourceDirectory + "Sample_Input/AcroForm.pdf"; + sInputData = Library.ResourceDirectory + "Sample_Input/AcroForm_data.xfdf"; + sOutput = "../ImportFormsDataAcroForms-out.pdf"; + + if (args.Length > 1) + { + sOutput = args[1]; + } + + using (Document doc = new Document(sInput)) + { + //Import the data while specifying the type, in this case XFDF + bool result = doc.ImportAcroFormsData(sInputData, AcroFormImportType.XFDF); + + if (result) + { + Console.Out.WriteLine("Forms data was imported!"); + + doc.Save(SaveFlags.Full | SaveFlags.Linearized, sOutput); + } + else + { + Console.Out.WriteLine("Importing of Forms data failed!"); + } + } + } + } + } +} diff --git a/Forms/ImportFormsData/ImportFormsData.csproj b/Forms/ImportFormsData/ImportFormsData.csproj new file mode 100644 index 0000000..8ea29b4 --- /dev/null +++ b/Forms/ImportFormsData/ImportFormsData.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + +