|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Text; |
| 4 | +using Datalogics.PDFL; |
| 5 | + |
| 6 | +/* |
| 7 | + * The ImportFormsData sample demonstrates how to Import forms data into XFA and AcroForms documents: |
| 8 | + * |
| 9 | + * - Import data into a XFA (Dynamic or Static) document, the types supported include XDP, XML, or XFD |
| 10 | + * - Import data into an AcroForms document, the types supported include XFDF, FDF, or XML |
| 11 | + * |
| 12 | + * Copyright (c) 2024, Datalogics, Inc. All rights reserved. |
| 13 | + */ |
| 14 | +namespace ImportFormsData |
| 15 | +{ |
| 16 | + class ImportFormsData |
| 17 | + { |
| 18 | + static void Main(string[] args) |
| 19 | + { |
| 20 | + Console.WriteLine("ImportFormsData Sample:"); |
| 21 | + |
| 22 | + using (Library lib = new Library(LibraryFlags.InitFormsExtension)) |
| 23 | + { |
| 24 | + if (!lib.IsFormsExtensionAvailable()) |
| 25 | + { |
| 26 | + System.Console.Out.WriteLine("Forms Plugins were not properly loaded!"); |
| 27 | + return; |
| 28 | + } |
| 29 | + |
| 30 | + lib.AllowOpeningXFA = true; |
| 31 | + |
| 32 | + Console.WriteLine("Initialized the library."); |
| 33 | + |
| 34 | + //XFA document |
| 35 | + String sInput = Library.ResourceDirectory + "Sample_Input/DynamicXFA.pdf"; |
| 36 | + String sInputData = Library.ResourceDirectory + "Sample_Input/DynamicXFA_data.xdp"; |
| 37 | + String sOutput = "../ImportFormsDataXFA-out.pdf"; |
| 38 | + |
| 39 | + if (args.Length > 0) |
| 40 | + { |
| 41 | + sOutput = args[0]; |
| 42 | + } |
| 43 | + |
| 44 | + using (Document doc = new Document(sInput)) |
| 45 | + { |
| 46 | + //Import the data, acceptable types include XDP, XML, and XFD |
| 47 | + bool result = doc.ImportXFAFormsData(sInputData); |
| 48 | + |
| 49 | + if (result) |
| 50 | + { |
| 51 | + Console.Out.WriteLine("Forms data was imported!"); |
| 52 | + |
| 53 | + doc.Save(SaveFlags.Full | SaveFlags.Linearized, sOutput); |
| 54 | + } |
| 55 | + else |
| 56 | + { |
| 57 | + Console.Out.WriteLine("Importing of Forms data failed!"); |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + //AcroForms document |
| 62 | + sInput = Library.ResourceDirectory + "Sample_Input/AcroForm.pdf"; |
| 63 | + sInputData = Library.ResourceDirectory + "Sample_Input/AcroForm_data.xfdf"; |
| 64 | + sOutput = "../ImportFormsDataAcroForms-out.pdf"; |
| 65 | + |
| 66 | + if (args.Length > 1) |
| 67 | + { |
| 68 | + sOutput = args[1]; |
| 69 | + } |
| 70 | + |
| 71 | + using (Document doc = new Document(sInput)) |
| 72 | + { |
| 73 | + //Import the data while specifying the type, in this case XFDF |
| 74 | + bool result = doc.ImportAcroFormsData(sInputData, AcroFormImportType.XFDF); |
| 75 | + |
| 76 | + if (result) |
| 77 | + { |
| 78 | + Console.Out.WriteLine("Forms data was imported!"); |
| 79 | + |
| 80 | + doc.Save(SaveFlags.Full | SaveFlags.Linearized, sOutput); |
| 81 | + } |
| 82 | + else |
| 83 | + { |
| 84 | + Console.Out.WriteLine("Importing of Forms data failed!"); |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | +} |
0 commit comments