Skip to content

Commit ee00b8e

Browse files
Merge pull request #44 from datalogics-aarroyo/fe_samples
Initial set up of Forms Extension Samples
2 parents 4e05049 + 9165e8c commit ee00b8e

File tree

8 files changed

+362
-0
lines changed

8 files changed

+362
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Datalogics.PDFL;
5+
6+
/*
7+
*
8+
* The ConvertXFAToAcroForms sample demonstrates how to convert XFA into AcroForms.
9+
* Converts XFA (Dynamic or Static) fields to AcroForms fields and removes XFA fields.
10+
* Copyright (c) 2024, Datalogics, Inc. All rights reserved.
11+
*
12+
*/
13+
namespace ConvertXFAToAcroForms
14+
{
15+
class ConvertXFAToAcroForms
16+
{
17+
static void Main(string[] args)
18+
{
19+
Console.WriteLine("ConvertXFAToAcroForms Sample:");
20+
21+
using (Library lib = new Library(LibraryFlags.InitFormsExtension))
22+
{
23+
if (!lib.IsFormsExtensionAvailable())
24+
{
25+
System.Console.Out.WriteLine("Forms Plugins were not properly loaded!");
26+
return;
27+
}
28+
29+
lib.AllowOpeningXFA = true;
30+
31+
Console.WriteLine("Initialized the library.");
32+
33+
String sInput = Library.ResourceDirectory + "Sample_Input/DynamicXFA.pdf";
34+
String sOutput = "../ConvertXFAToAcroForms-out.pdf";
35+
36+
if (args.Length > 0)
37+
{
38+
sInput = args[0];
39+
}
40+
41+
if (args.Length > 1)
42+
{
43+
sOutput = args[1];
44+
}
45+
46+
using (Document doc = new Document(sInput))
47+
{
48+
UInt32 pagesOutput = doc.ConvertXFAFieldsToAcroFormFields();
49+
50+
Console.WriteLine("XFA document was converted into an AcroForms document with {0} pages.", pagesOutput);
51+
52+
doc.Save(SaveFlags.Full | SaveFlags.Linearized, sOutput);
53+
}
54+
}
55+
}
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Adobe.PDF.Library.FormsExtension.LM.NET" Version="1.*" />
12+
</ItemGroup>
13+
14+
</Project>
+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Datalogics.PDFL;
5+
6+
/*
7+
* The ExportFormsData sample demonstrates how to Export forms data from XFA and AcroForms documents:
8+
*
9+
* - Export data from a XFA (Dynamic or Static) document, the types supported include XDP, XML, or XFD
10+
* - Export data from an AcroForms document, the types supported include XFDF, FDF, or XML
11+
*
12+
* Copyright (c) 2024, Datalogics, Inc. All rights reserved.
13+
*
14+
*/
15+
namespace ExportFormsData
16+
{
17+
class ExportFormsData
18+
{
19+
static void Main(string[] args)
20+
{
21+
Console.WriteLine("ExportFormsData Sample:");
22+
23+
using (Library lib = new Library(LibraryFlags.InitFormsExtension))
24+
{
25+
if (!lib.IsFormsExtensionAvailable())
26+
{
27+
System.Console.Out.WriteLine("Forms Plugins were not properly loaded!");
28+
return;
29+
}
30+
31+
lib.AllowOpeningXFA = true;
32+
33+
Console.WriteLine("Initialized the library.");
34+
35+
//XFA document
36+
String sInput = Library.ResourceDirectory + "Sample_Input/DynamicXFA.pdf";
37+
String sOutput = "../ExportFormsDataXFA.xdp";
38+
39+
if (args.Length > 0)
40+
{
41+
sOutput = args[0];
42+
}
43+
44+
using (Document doc = new Document(sInput))
45+
{
46+
//Export the data while specifying the type, in this case XDP
47+
bool result = doc.ExportXFAFormsData(sOutput, XFAFormExportType.XDP);
48+
49+
if (result)
50+
{
51+
Console.Out.WriteLine("Forms data was exported!");
52+
}
53+
else
54+
{
55+
Console.Out.WriteLine("Exporting of Forms data failed!");
56+
}
57+
}
58+
59+
//AcroForms document
60+
sInput = Library.ResourceDirectory + "Sample_Input/AcroForm.pdf";
61+
sOutput = "../ExportFormsDataAcroForms.xfdf";
62+
63+
if (args.Length > 1)
64+
{
65+
sOutput = args[1];
66+
}
67+
68+
using (Document doc = new Document(sInput))
69+
{
70+
//Export the data while specifying the type, in this case XFDF
71+
bool result = doc.ExportAcroFormsData(sOutput, AcroFormExportType.XFDF);
72+
73+
if (result)
74+
{
75+
Console.Out.WriteLine("Forms data was exported!");
76+
}
77+
else
78+
{
79+
Console.Out.WriteLine("Exporting of Forms data failed!");
80+
}
81+
}
82+
}
83+
}
84+
}
85+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Adobe.PDF.Library.FormsExtension.LM.NET" Version="1.*" />
12+
</ItemGroup>
13+
14+
</Project>

Forms/FlattenForms/FlattenForms.cs

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Datalogics.PDFL;
5+
6+
/*
7+
*
8+
* The FlattenForms sample demonstrates how to Flatten XFA into AcroForms.
9+
*
10+
* - Flatten XFA (Dynamic or Static) to regular page content which converts and expands XFA fields to regular PDF content and removes the XFA fields.
11+
* - Flatten AcroForms to regular page content which converts AcroForm fields to regular page content and removes the AcroForm fields.
12+
* Copyright (c) 2024, Datalogics, Inc. All rights reserved.
13+
*
14+
*/
15+
namespace FlattenForms
16+
{
17+
class FlattenForms
18+
{
19+
static void Main(string[] args)
20+
{
21+
Console.WriteLine("FlattenForms Sample:");
22+
23+
using (Library lib = new Library(LibraryFlags.InitFormsExtension))
24+
{
25+
if (!lib.IsFormsExtensionAvailable())
26+
{
27+
System.Console.Out.WriteLine("Forms Plugins were not properly loaded!");
28+
return;
29+
}
30+
31+
//Must be set to true to prevent default legacy behavior of PDFL
32+
lib.AllowOpeningXFA = true;
33+
34+
Console.WriteLine("Initialized the library.");
35+
36+
//XFA document
37+
String sInput = Library.ResourceDirectory + "Sample_Input/DynamicXFA.pdf";
38+
String sOutput = "../FlattenXFA-out.pdf";
39+
40+
if (args.Length > 0)
41+
{
42+
sInput = args[0];
43+
}
44+
45+
if (args.Length > 1)
46+
{
47+
sOutput = args[1];
48+
}
49+
50+
using (Document doc = new Document(sInput))
51+
{
52+
UInt32 pagesOutput = doc.FlattenXFAFormFields();
53+
54+
Console.WriteLine("XFA document was expanded into {0} Flattened pages.", pagesOutput);
55+
56+
doc.Save(SaveFlags.Full | SaveFlags.Linearized, sOutput);
57+
}
58+
59+
//AcroForms document
60+
sInput = Library.ResourceDirectory + "Sample_Input/AcroForm.pdf";
61+
sOutput = "../FlattenAcroForms-out.pdf";
62+
63+
using (Document doc = new Document(sInput))
64+
{
65+
doc.FlattenAcroFormFields();
66+
67+
Console.WriteLine("AcroForms document was Flattened.");
68+
69+
doc.Save(SaveFlags.Full | SaveFlags.Linearized, sOutput);
70+
}
71+
}
72+
}
73+
}
74+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Adobe.PDF.Library.FormsExtension.LM.NET" Version="1.*" />
12+
</ItemGroup>
13+
14+
</Project>
+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Adobe.PDF.Library.FormsExtension.LM.NET" Version="1.*" />
12+
</ItemGroup>
13+
14+
</Project>

0 commit comments

Comments
 (0)