Skip to content

Commit 2ecf6ea

Browse files
Add FormsExtension .NET Framework samples.
1 parent c04fb9d commit 2ecf6ea

File tree

13 files changed

+578
-0
lines changed

13 files changed

+578
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
5+
</startup>
6+
</configuration>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using Datalogics.PDFL;
3+
4+
/*
5+
*
6+
* The ConvertXFAToAcroForms sample demonstrates how to convert XFA into AcroForms.
7+
* Converts XFA (Dynamic or Static) fields to AcroForms fields and removes XFA fields.
8+
* Copyright (c) 2024, Datalogics, Inc. All rights reserved.
9+
*
10+
*/
11+
namespace ConvertXFAToAcroForms
12+
{
13+
class ConvertXFAToAcroForms
14+
{
15+
static void Main(string[] args)
16+
{
17+
Console.WriteLine("ConvertXFAToAcroForms Sample:");
18+
19+
using (Library lib = new Library(LibraryFlags.InitFormsExtension))
20+
{
21+
if (!lib.IsFormsExtensionAvailable())
22+
{
23+
System.Console.Out.WriteLine("Forms Plugins were not properly loaded!");
24+
return;
25+
}
26+
27+
lib.AllowOpeningXFA = true;
28+
29+
Console.WriteLine("Initialized the library.");
30+
31+
String sInput = Library.ResourceDirectory + "Sample_Input/DynamicXFA.pdf";
32+
String sOutput = "../ConvertXFAToAcroForms-out.pdf";
33+
34+
if (args.Length > 0)
35+
{
36+
sInput = args[0];
37+
}
38+
39+
if (args.Length > 1)
40+
{
41+
sOutput = args[1];
42+
}
43+
44+
using (Document doc = new Document(sInput))
45+
{
46+
UInt32 pagesOutput = doc.ConvertXFAFieldsToAcroFormFields();
47+
48+
Console.WriteLine("XFA document was converted into an AcroForms document with {0} pages.", pagesOutput);
49+
50+
doc.Save(SaveFlags.Full | SaveFlags.Linearized, sOutput);
51+
}
52+
}
53+
}
54+
}
55+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">x64</Platform>
7+
<ProjectGuid>{7e090b4f-0db4-4c40-a48a-40c0111019d5}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>ConvertXFAToAcroForms</RootNamespace>
10+
<AssemblyName>ConvertXFAToAcroForms</AssemblyName>
11+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
<Deterministic>true</Deterministic>
15+
<NuGetPackageImportStamp>
16+
</NuGetPackageImportStamp>
17+
</PropertyGroup>
18+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
19+
<PlatformTarget>x64</PlatformTarget>
20+
<DebugSymbols>true</DebugSymbols>
21+
<DebugType>full</DebugType>
22+
<Optimize>false</Optimize>
23+
<OutputPath>bin\Debug\</OutputPath>
24+
<DefineConstants>DEBUG;TRACE</DefineConstants>
25+
<ErrorReport>prompt</ErrorReport>
26+
<WarningLevel>4</WarningLevel>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
29+
<PlatformTarget>x64</PlatformTarget>
30+
<DebugType>pdbonly</DebugType>
31+
<Optimize>false</Optimize>
32+
<OutputPath>bin\Release\</OutputPath>
33+
<DefineConstants>TRACE</DefineConstants>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
</PropertyGroup>
37+
<ItemGroup>
38+
<Reference Include="System" />
39+
<Reference Include="Microsoft.CSharp" />
40+
</ItemGroup>
41+
<ItemGroup>
42+
<Compile Include="ConvertXFAToAcroForms.cs" />
43+
<Compile Include="Properties\AssemblyInfo.cs" />
44+
</ItemGroup>
45+
<ItemGroup>
46+
<None Include="App.config" />
47+
</ItemGroup>
48+
<ItemGroup>
49+
<PackageReference Include="Adobe.PDF.Library.FormsExtension.LM.NETFramework">
50+
<Version>18.*</Version>
51+
</PackageReference>
52+
</ItemGroup>
53+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
54+
</Project>

Forms/ExportFormsData/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
5+
</startup>
6+
</configuration>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using System;
2+
using Datalogics.PDFL;
3+
4+
/*
5+
* The ExportFormsData sample demonstrates how to Export forms data from XFA and AcroForms documents:
6+
*
7+
* - Export data from a XFA (Dynamic or Static) document, the types supported include XDP, XML, or XFD
8+
* - Export data from an AcroForms document, the types supported include XFDF, FDF, or XML
9+
*
10+
* Copyright (c) 2024, Datalogics, Inc. All rights reserved.
11+
*
12+
*/
13+
namespace ExportFormsData
14+
{
15+
class ExportFormsData
16+
{
17+
static void Main(string[] args)
18+
{
19+
Console.WriteLine("ExportFormsData 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+
//XFA document
34+
String sInput = Library.ResourceDirectory + "Sample_Input/DynamicXFA.pdf";
35+
String sOutput = "../ExportFormsDataXFA.xdp";
36+
37+
if (args.Length > 0)
38+
{
39+
sOutput = args[0];
40+
}
41+
42+
using (Document doc = new Document(sInput))
43+
{
44+
//Export the data while specifying the type, in this case XDP
45+
bool result = doc.ExportXFAFormsData(sOutput, XFAFormExportType.XDP);
46+
47+
if (result)
48+
{
49+
Console.Out.WriteLine("Forms data was exported!");
50+
}
51+
else
52+
{
53+
Console.Out.WriteLine("Exporting of Forms data failed!");
54+
}
55+
}
56+
57+
//AcroForms document
58+
sInput = Library.ResourceDirectory + "Sample_Input/AcroForm.pdf";
59+
sOutput = "../ExportFormsDataAcroForms.xfdf";
60+
61+
if (args.Length > 1)
62+
{
63+
sOutput = args[1];
64+
}
65+
66+
using (Document doc = new Document(sInput))
67+
{
68+
//Export the data while specifying the type, in this case XFDF
69+
bool result = doc.ExportAcroFormsData(sOutput, AcroFormExportType.XFDF);
70+
71+
if (result)
72+
{
73+
Console.Out.WriteLine("Forms data was exported!");
74+
}
75+
else
76+
{
77+
Console.Out.WriteLine("Exporting of Forms data failed!");
78+
}
79+
}
80+
}
81+
}
82+
}
83+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">x64</Platform>
7+
<ProjectGuid>{7e090b4f-0db4-4c40-a48a-40c0111019d5}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>ExportFormsData</RootNamespace>
10+
<AssemblyName>ExportFormsData</AssemblyName>
11+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
<Deterministic>true</Deterministic>
15+
<NuGetPackageImportStamp>
16+
</NuGetPackageImportStamp>
17+
</PropertyGroup>
18+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
19+
<PlatformTarget>x64</PlatformTarget>
20+
<DebugSymbols>true</DebugSymbols>
21+
<DebugType>full</DebugType>
22+
<Optimize>false</Optimize>
23+
<OutputPath>bin\Debug\</OutputPath>
24+
<DefineConstants>DEBUG;TRACE</DefineConstants>
25+
<ErrorReport>prompt</ErrorReport>
26+
<WarningLevel>4</WarningLevel>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
29+
<PlatformTarget>x64</PlatformTarget>
30+
<DebugType>pdbonly</DebugType>
31+
<Optimize>false</Optimize>
32+
<OutputPath>bin\Release\</OutputPath>
33+
<DefineConstants>TRACE</DefineConstants>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
</PropertyGroup>
37+
<ItemGroup>
38+
<Reference Include="System" />
39+
<Reference Include="Microsoft.CSharp" />
40+
</ItemGroup>
41+
<ItemGroup>
42+
<Compile Include="ExportFormsData.cs" />
43+
<Compile Include="Properties\AssemblyInfo.cs" />
44+
</ItemGroup>
45+
<ItemGroup>
46+
<None Include="App.config" />
47+
</ItemGroup>
48+
<ItemGroup>
49+
<PackageReference Include="Adobe.PDF.Library.FormsExtension.LM.NETFramework">
50+
<Version>18.*</Version>
51+
</PackageReference>
52+
</ItemGroup>
53+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
54+
</Project>

Forms/FlattenForms/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
5+
</startup>
6+
</configuration>

Forms/FlattenForms/FlattenForms.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System;
2+
using Datalogics.PDFL;
3+
4+
/*
5+
*
6+
* The FlattenForms sample demonstrates how to Flatten XFA into AcroForms.
7+
*
8+
* - Flatten XFA (Dynamic or Static) to regular page content which converts and expands XFA fields to regular PDF content and removes the XFA fields.
9+
* - Flatten AcroForms to regular page content which converts AcroForm fields to regular page content and removes the AcroForm fields.
10+
* Copyright (c) 2024, Datalogics, Inc. All rights reserved.
11+
*
12+
*/
13+
namespace FlattenForms
14+
{
15+
class FlattenForms
16+
{
17+
static void Main(string[] args)
18+
{
19+
Console.WriteLine("FlattenForms 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+
//Must be set to true to prevent default legacy behavior of PDFL
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 sOutput = "../FlattenXFA-out.pdf";
37+
38+
if (args.Length > 0)
39+
{
40+
sInput = args[0];
41+
}
42+
43+
if (args.Length > 1)
44+
{
45+
sOutput = args[1];
46+
}
47+
48+
using (Document doc = new Document(sInput))
49+
{
50+
UInt32 pagesOutput = doc.FlattenXFAFormFields();
51+
52+
Console.WriteLine("XFA document was expanded into {0} Flattened pages.", pagesOutput);
53+
54+
doc.Save(SaveFlags.Full | SaveFlags.Linearized, sOutput);
55+
}
56+
57+
//AcroForms document
58+
sInput = Library.ResourceDirectory + "Sample_Input/AcroForm.pdf";
59+
sOutput = "../FlattenAcroForms-out.pdf";
60+
61+
using (Document doc = new Document(sInput))
62+
{
63+
doc.FlattenAcroFormFields();
64+
65+
Console.WriteLine("AcroForms document was Flattened.");
66+
67+
doc.Save(SaveFlags.Full | SaveFlags.Linearized, sOutput);
68+
}
69+
}
70+
}
71+
}
72+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">x64</Platform>
7+
<ProjectGuid>{7e090b4f-0db4-4c40-a48a-40c0111019d5}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>FlattenForms</RootNamespace>
10+
<AssemblyName>FlattenForms</AssemblyName>
11+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
<Deterministic>true</Deterministic>
15+
<NuGetPackageImportStamp>
16+
</NuGetPackageImportStamp>
17+
</PropertyGroup>
18+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
19+
<PlatformTarget>x64</PlatformTarget>
20+
<DebugSymbols>true</DebugSymbols>
21+
<DebugType>full</DebugType>
22+
<Optimize>false</Optimize>
23+
<OutputPath>bin\Debug\</OutputPath>
24+
<DefineConstants>DEBUG;TRACE</DefineConstants>
25+
<ErrorReport>prompt</ErrorReport>
26+
<WarningLevel>4</WarningLevel>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
29+
<PlatformTarget>x64</PlatformTarget>
30+
<DebugType>pdbonly</DebugType>
31+
<Optimize>false</Optimize>
32+
<OutputPath>bin\Release\</OutputPath>
33+
<DefineConstants>TRACE</DefineConstants>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
</PropertyGroup>
37+
<ItemGroup>
38+
<Reference Include="System" />
39+
<Reference Include="Microsoft.CSharp" />
40+
</ItemGroup>
41+
<ItemGroup>
42+
<Compile Include="FlattenForms.cs" />
43+
<Compile Include="Properties\AssemblyInfo.cs" />
44+
</ItemGroup>
45+
<ItemGroup>
46+
<None Include="App.config" />
47+
</ItemGroup>
48+
<ItemGroup>
49+
<PackageReference Include="Adobe.PDF.Library.FormsExtension.LM.NETFramework">
50+
<Version>18.*</Version>
51+
</PackageReference>
52+
</ItemGroup>
53+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
54+
</Project>

0 commit comments

Comments
 (0)