Skip to content

Commit

Permalink
Merge pull request #43 from datalogics-josepha/APDFL-5954
Browse files Browse the repository at this point in the history
APDFL-5954 - Add FormsExtension .NET Framework samples.
  • Loading branch information
datalogics-saharay authored Dec 9, 2024
2 parents c04fb9d + 7be8ad5 commit 7201a36
Show file tree
Hide file tree
Showing 14 changed files with 575 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Forms/ConvertXFAToAcroForms/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
55 changes: 55 additions & 0 deletions Forms/ConvertXFAToAcroForms/ConvertXFAToAcroForms.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
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);
}
}
}
}
}
53 changes: 53 additions & 0 deletions Forms/ConvertXFAToAcroForms/ConvertXFAToAcroForms.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x64</Platform>
<ProjectGuid>{7e090b4f-0db4-4c40-a48a-40c0111019d5}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>ConvertXFAToAcroForms</RootNamespace>
<AssemblyName>ConvertXFAToAcroForms</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
<PlatformTarget>x64</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
<PlatformTarget>x64</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<Compile Include="ConvertXFAToAcroForms.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Adobe.PDF.Library.FormsExtension.LM.NETFramework">
<Version>18.*</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
6 changes: 6 additions & 0 deletions Forms/ExportFormsData/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
83 changes: 83 additions & 0 deletions Forms/ExportFormsData/ExportFormsData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System;
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!");
}
}
}
}
}
}
53 changes: 53 additions & 0 deletions Forms/ExportFormsData/ExportFormsData.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x64</Platform>
<ProjectGuid>{7e090b4f-0db4-4c40-a48a-40c0111019d5}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>ExportFormsData</RootNamespace>
<AssemblyName>ExportFormsData</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
<PlatformTarget>x64</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
<PlatformTarget>x64</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<Compile Include="ExportFormsData.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Adobe.PDF.Library.FormsExtension.LM.NETFramework">
<Version>18.*</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
6 changes: 6 additions & 0 deletions Forms/FlattenForms/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
72 changes: 72 additions & 0 deletions Forms/FlattenForms/FlattenForms.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
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);
}
}
}
}
}
53 changes: 53 additions & 0 deletions Forms/FlattenForms/FlattenForms.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x64</Platform>
<ProjectGuid>{7e090b4f-0db4-4c40-a48a-40c0111019d5}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>FlattenForms</RootNamespace>
<AssemblyName>FlattenForms</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
<PlatformTarget>x64</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
<PlatformTarget>x64</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<Compile Include="FlattenForms.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Adobe.PDF.Library.FormsExtension.LM.NETFramework">
<Version>18.*</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Loading

0 comments on commit 7201a36

Please sign in to comment.