Agregar archivos de proyecto.

This commit is contained in:
2026-05-27 17:09:59 +02:00
parent 73b30b7de7
commit 03813aff5a
9144 changed files with 4026729 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("TSpdf.Forms.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("TSpdf")]
[assembly: AssemblyProduct("TSpdf")]
[assembly: AssemblyCopyright("Copyright (c) 1987-2023 TSpdf")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("6fe2f714-6b3e-4b20-8c70-28bfce084ed2")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0.0")]
#if !NETSTANDARD2_0
[assembly: NUnit.Framework.Timeout(300000)]
#endif

View File

@@ -0,0 +1,66 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup Label="Globals">
<SccProjectName>SAK</SccProjectName>
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<SignAssembly>True</SignAssembly>
<DelaySign>False</DelaySign>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net461;net48</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net461' ">
<OutputType>library</OutputType>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
<OutputType>Library</OutputType>
<DefineConstants>NETSTANDARD2_0</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>TSpdf.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<ApplicationIcon />
<OutputTypeEx>library</OutputTypeEx>
<StartupObject />
<AssemblyName>TSpdf.forms.tests</AssemblyName>
<RootNamespace />
</PropertyGroup>
<PropertyGroup>
<NoWarn>1701;1702;1591;1570;1572;1573;1574;1580;1584;1658</NoWarn>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="TeamCity.VSTest.TestAdapter" Version="1.0.0" />
<PackageReference Include="NUnit" Version="3.7.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\TSpdf\TSpdf.forms\TSpdf.forms.csproj" />
<ProjectReference Include="..\..\TSpdf\TSpdf.io\TSpdf.io.csproj" />
<ProjectReference Include="..\..\TSpdf\TSpdf.kernel\TSpdf.kernel.csproj" />
<ProjectReference Include="..\..\TSpdf\TSpdf.layout\TSpdf.layout.csproj" />
<ProjectReference Include="..\..\TSpdf\TSpdf.pdftest\TSpdf.pdftest.csproj" />
<ProjectReference Include="..\..\TSpdf\TSpdf.font-asian\TSpdf.font-asian.csproj" />
<ProjectReference Include="..\..\TSpdf\TSpdf.bouncy-castle-adapter\TSpdf.bouncy-castle-adapter.csproj" />
<ProjectReference Include="..\..\TSpdf\TSpdf.bouncy-castle-fips-adapter\TSpdf.bouncy-castle-fips-adapter.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<PackageReference Include="Microsoft.NET.Test.Sdk">
<Version>15.0.0</Version>
</PackageReference>
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation">
<Version>4.3.0</Version>
</PackageReference>
</ItemGroup>
</Project>

Binary file not shown.

View File

@@ -0,0 +1,88 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Commons.Utils;
using TSpdf.Forms.Fields;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Utils;
using TSpdf.Test;
namespace TSpdf.Forms {
[NUnit.Framework.Category("IntegrationTest")]
public class FlatteningRotatedTest : ExtendedTSpdfTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/forms/FlatteningRotatedTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/forms/FlatteningRotatedTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
CreateOrClearDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void FormFlatteningTest_DefaultAppearanceGeneration_Rot() {
String srcFilePatternPattern = "FormFlatteningDefaultAppearance_{0}_";
String destPatternPattern = "FormFlatteningDefaultAppearance_{0}_";
String[] rotAngle = new String[] { "0", "90", "180", "270" };
foreach (String angle in rotAngle) {
String srcFilePattern = MessageFormatUtil.Format(srcFilePatternPattern, angle);
String destPattern = MessageFormatUtil.Format(destPatternPattern, angle);
for (int i = 0; i < 360; i += 90) {
String src = sourceFolder + srcFilePattern + i + ".pdf";
String dest = destinationFolder + destPattern + i + "_flattened.pdf";
String cmp = sourceFolder + "cmp_" + srcFilePattern + i + ".pdf";
PdfDocument doc = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
foreach (PdfFormField field in form.GetAllFormFields().Values) {
field.SetValue("Test");
}
form.FlattenFields();
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(dest, cmp, destinationFolder, "diff_"));
}
}
}
}
}

View File

@@ -0,0 +1,88 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Forms.Logs;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Utils;
using TSpdf.Test;
using TSpdf.Test.Attributes;
namespace TSpdf.Forms {
[NUnit.Framework.Category("IntegrationTest")]
public class FlatteningTest : ExtendedTSpdfTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/forms/FlatteningTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/forms/FlatteningTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
CreateOrClearDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void FlatteningFormFieldNoSubtypeInAPTest() {
String src = sourceFolder + "formFieldNoSubtypeInAPTest.pdf";
String dest = destinationFolder + "flatteningFormFieldNoSubtypeInAPTest.pdf";
String cmp = sourceFolder + "cmp_flatteningFormFieldNoSubtypeInAPTest.pdf";
PdfDocument doc = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
PdfAcroForm.GetAcroForm(doc, false).FlattenFields();
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(dest, cmp, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(FormsLogMessageConstants.N_ENTRY_IS_REQUIRED_FOR_APPEARANCE_DICTIONARY)]
public virtual void FormFlatteningTestWithoutNEntry() {
String filename = "formFlatteningTestWithoutNEntry";
String src = sourceFolder + filename + ".pdf";
String dest = destinationFolder + filename + "_flattened.pdf";
String cmp = sourceFolder + "cmp_" + filename + "_flattened.pdf";
PdfDocument doc = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
PdfAcroForm.GetAcroForm(doc, false).FlattenFields();
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(dest, cmp, destinationFolder, "diff_"));
}
}
}

View File

@@ -0,0 +1,78 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Kernel.Pdf;
using TSpdf.Test;
namespace TSpdf.Forms {
[NUnit.Framework.Category("IntegrationTest")]
public class FlatteningWithNullKidElementTest : ExtendedTSpdfTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/forms/FlatteningWithNullKidElementTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/forms/FlatteningWithNullKidElementTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void FormFlatteningTestWithNullKidElement() {
String filename = "Form_NullKidElement";
String src = sourceFolder + filename + ".pdf";
String temp = destinationFolder + "temp.pdf";
PdfDocument doc = new PdfDocument(new PdfReader(src), new PdfWriter(temp));
bool fail = false;
try {
PdfAcroForm.GetAcroForm(doc, true).FlattenFields();
doc.Close();
}
catch (Exception) {
fail = true;
}
NUnit.Framework.Assert.IsFalse(fail);
}
}
}

View File

@@ -0,0 +1,118 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.IO;
using TSpdf.Forms.Fields;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Utils;
using TSpdf.Test;
namespace TSpdf.Forms {
[NUnit.Framework.Category("IntegrationTest")]
public class FormFieldAppendTest : ExtendedTSpdfTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/forms/FormFieldAppendTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/forms/FormFieldAppendTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void FormFillingAppend_form_empty_Test() {
String srcFilename = sourceFolder + "Form_Empty.pdf";
String temp = destinationFolder + "temp_empty.pdf";
String filename = destinationFolder + "formFillingAppend_form_empty.pdf";
StampingProperties props = new StampingProperties();
props.UseAppendMode();
PdfDocument doc = new PdfDocument(new PdfReader(srcFilename), new PdfWriter(temp), props);
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
foreach (PdfFormField field in form.GetAllFormFields().Values) {
field.SetValue("Test");
}
doc.Close();
Flatten(temp, filename);
FileInfo toDelete = new FileInfo(temp);
toDelete.Delete();
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(filename, sourceFolder + "cmp_formFillingAppend_form_empty.pdf"
, destinationFolder, "diff_");
if (errorMessage != null) {
NUnit.Framework.Assert.Fail(errorMessage);
}
}
[NUnit.Framework.Test]
public virtual void FormFillingAppend_form_filled_Test() {
String srcFilename = sourceFolder + "Form_Empty.pdf";
String temp = destinationFolder + "temp_filled.pdf";
String filename = destinationFolder + "formFillingAppend_form_filled.pdf";
StampingProperties props = new StampingProperties();
props.UseAppendMode();
PdfDocument doc = new PdfDocument(new PdfReader(srcFilename), new PdfWriter(temp), props);
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
foreach (PdfFormField field in form.GetAllFormFields().Values) {
field.SetValue("Different");
}
doc.Close();
Flatten(temp, filename);
new FileInfo(temp).Delete();
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(filename, sourceFolder + "cmp_formFillingAppend_form_filled.pdf"
, destinationFolder, "diff_");
if (errorMessage != null) {
NUnit.Framework.Assert.Fail(errorMessage);
}
}
private void Flatten(String src, String dest) {
PdfDocument doc = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
form.FlattenFields();
doc.Close();
}
}
}

View File

@@ -0,0 +1,253 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.IO;
using TSpdf.Forms.Fields;
using TSpdf.Forms.Logs;
using TSpdf.Kernel.Colors;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Utils;
using TSpdf.Test;
using TSpdf.Test.Attributes;
namespace TSpdf.Forms {
[NUnit.Framework.Category("IntegrationTest")]
public class FormFieldFlatteningTest : ExtendedTSpdfTest {
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/forms/FormFieldFlatteningTest/";
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/forms/FormFieldFlatteningTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
CreateOrClearDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void GetFieldsForFlatteningTest() {
String outPdfName = destinationFolder + "flattenedFormField.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfReader(sourceFolder + "formFieldFile.pdf"), new PdfWriter(outPdfName
));
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, false);
NUnit.Framework.Assert.AreEqual(0, form.GetFieldsForFlattening().Count);
form.PartialFormFlattening("radioName");
form.PartialFormFlattening("Text1");
PdfFormField radioNameField = form.GetField("radioName");
PdfFormField text1Field = form.GetField("Text1");
NUnit.Framework.Assert.AreEqual(2, form.GetFieldsForFlattening().Count);
NUnit.Framework.Assert.IsTrue(form.GetFieldsForFlattening().Contains(radioNameField));
NUnit.Framework.Assert.IsTrue(form.GetFieldsForFlattening().Contains(text1Field));
form.FlattenFields();
pdfDoc.Close();
PdfDocument outPdfDoc = new PdfDocument(new PdfReader(outPdfName));
PdfAcroForm outPdfForm = PdfAcroForm.GetAcroForm(outPdfDoc, false);
NUnit.Framework.Assert.AreEqual(2, outPdfForm.GetAllFormFields().Count);
outPdfDoc.Close();
}
[NUnit.Framework.Test]
public virtual void FormFlatteningTest01() {
String srcFilename = "formFlatteningSource.pdf";
String filename = "formFlatteningTest01.pdf";
FlattenFieldsAndCompare(srcFilename, filename);
}
[NUnit.Framework.Test]
public virtual void FormFlatteningChoiceFieldTest01() {
String srcFilename = "formFlatteningSourceChoiceField.pdf";
String filename = "formFlatteningChoiceFieldTest01.pdf";
FlattenFieldsAndCompare(srcFilename, filename);
}
[NUnit.Framework.Test]
public virtual void MultiLineFormFieldClippingTest() {
String src = sourceFolder + "multiLineFormFieldClippingTest.pdf";
String dest = destinationFolder + "multiLineFormFieldClippingTest_flattened.pdf";
String cmp = sourceFolder + "cmp_multiLineFormFieldClippingTest_flattened.pdf";
PdfDocument doc = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
form.GetField("Text1").SetValue("Tall letters: T I J L R E F");
form.FlattenFields();
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(dest, cmp, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void RotatedFieldAppearanceTest01() {
String srcFilename = "src_rotatedFieldAppearanceTest01.pdf";
String filename = "rotatedFieldAppearanceTest01.pdf";
FlattenFieldsAndCompare(srcFilename, filename);
}
[NUnit.Framework.Test]
public virtual void RotatedFieldAppearanceTest02() {
String srcFilename = "src_rotatedFieldAppearanceTest02.pdf";
String filename = "rotatedFieldAppearanceTest02.pdf";
FlattenFieldsAndCompare(srcFilename, filename);
}
[NUnit.Framework.Test]
public virtual void DegeneratedRectTest01() {
String srcFilename = "src_degeneratedRectTest01.pdf";
String filename = "degeneratedRectTest01.pdf";
FlattenFieldsAndCompare(srcFilename, filename);
}
[NUnit.Framework.Test]
public virtual void DegeneratedRectTest02() {
String srcFilename = "src_degeneratedRectTest02.pdf";
String filename = "degeneratedRectTest02.pdf";
FlattenFieldsAndCompare(srcFilename, filename);
}
[NUnit.Framework.Test]
public virtual void ScaledRectTest01() {
String srcFilename = "src_scaledRectTest01.pdf";
String filename = "scaledRectTest01.pdf";
FlattenFieldsAndCompare(srcFilename, filename);
}
private static void FlattenFieldsAndCompare(String srcFile, String outFile) {
PdfReader reader = new PdfReader(sourceFolder + srcFile);
PdfWriter writer = new PdfWriter(destinationFolder + outFile);
PdfDocument document = new PdfDocument(reader, writer);
PdfAcroForm.GetAcroForm(document, false).FlattenFields();
document.Close();
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(destinationFolder + outFile, sourceFolder + "cmp_" + outFile
, destinationFolder, "diff_");
if (errorMessage != null) {
NUnit.Framework.Assert.Fail(errorMessage);
}
}
[NUnit.Framework.Test]
public virtual void FieldsJustificationTest01() {
FillTextFieldsThenFlattenThenCompare("fieldsJustificationTest01");
}
[NUnit.Framework.Test]
[LogMessage(FormsLogMessageConstants.ANNOTATION_IN_ACROFORM_DICTIONARY, Count = 2)]
public virtual void FieldsJustificationTest02() {
FillTextFieldsThenFlattenThenCompare("fieldsJustificationTest02");
}
private static void FillTextFieldsThenFlattenThenCompare(String testName) {
String src = sourceFolder + "src_" + testName + ".pdf";
String dest = destinationFolder + testName + ".pdf";
String cmp = sourceFolder + "cmp_" + testName + ".pdf";
PdfDocument doc = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
foreach (PdfFormField field in form.GetAllFormFields().Values) {
if (field is PdfTextFormField) {
String newValue;
if (field.IsMultiline()) {
newValue = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, " + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "
+ "Lorem ipsum dolor sit amet, consectetur adipiscing elit, " + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
field.SetFontSize(0);
}
else {
newValue = "HELLO!";
}
int? justification = field.GetJustification();
if (null == justification || 0 == (int)justification) {
// reddish
foreach (PdfFormAnnotation annot in field.GetChildFormAnnotations()) {
annot.SetBackgroundColor(new DeviceRgb(255, 200, 200));
}
}
else {
if (1 == (int)justification) {
// greenish
foreach (PdfFormAnnotation annot in field.GetChildFormAnnotations()) {
annot.SetBackgroundColor(new DeviceRgb(200, 255, 200));
}
}
else {
if (2 == (int)justification) {
// blueish
foreach (PdfFormAnnotation annot in field.GetChildFormAnnotations()) {
annot.SetBackgroundColor(new DeviceRgb(200, 200, 255));
}
}
}
}
field.SetValue(newValue);
}
}
form.FlattenFields();
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(dest, cmp, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, Count = 5)]
public virtual void FlattenReadOnly() {
//Logging is expected since there are duplicate field names
//isReadOnly should be true after DEVSIX-2156
PdfWriter writer = new PdfWriter(new MemoryStream());
PdfDocument pdfDoc = new PdfDocument(writer);
PdfReader reader = new PdfReader(sourceFolder + "readOnlyForm.pdf");
PdfDocument pdfInnerDoc = new PdfDocument(reader);
pdfInnerDoc.CopyPagesTo(1, pdfInnerDoc.GetNumberOfPages(), pdfDoc, new PdfPageFormCopier());
pdfInnerDoc.Close();
reader = new PdfReader(sourceFolder + "readOnlyForm.pdf");
pdfInnerDoc = new PdfDocument(reader);
pdfInnerDoc.CopyPagesTo(1, pdfInnerDoc.GetNumberOfPages(), pdfDoc, new PdfPageFormCopier());
pdfInnerDoc.Close();
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, false);
bool isReadOnly = true;
foreach (PdfFormField field in form.GetAllFormFields().Values) {
isReadOnly = (isReadOnly && field.IsReadOnly());
}
pdfDoc.Close();
NUnit.Framework.Assert.IsFalse(isReadOnly);
}
[NUnit.Framework.Test]
public virtual void FieldsRegeneratePushButtonWithoutCaption() {
FillTextFieldsThenFlattenThenCompare("pushbutton_without_caption");
}
}
}

View File

@@ -0,0 +1,203 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Forms.Fields;
using TSpdf.Kernel.Geom;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Pdf.Tagging;
using TSpdf.Kernel.Pdf.Tagutils;
using TSpdf.Kernel.Utils;
using TSpdf.Test;
namespace TSpdf.Forms {
[NUnit.Framework.Category("IntegrationTest")]
public class FormFieldsTaggingTest : ExtendedTSpdfTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/forms/FormFieldsTaggingTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/forms/FormFieldsTaggingTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
CreateOrClearDestinationFolder(destinationFolder);
}
/// <summary>Form fields addition to the tagged document.</summary>
[NUnit.Framework.Test]
public virtual void FormFieldTaggingTest01() {
String outFileName = destinationFolder + "taggedPdfWithForms01.pdf";
String cmpFileName = sourceFolder + "cmp_taggedPdfWithForms01.pdf";
PdfWriter writer = new PdfWriter(outFileName);
PdfDocument pdfDoc = new PdfDocument(writer);
pdfDoc.SetTagged();
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
AddFormFieldsToDocument(pdfDoc, form);
pdfDoc.Close();
CompareOutput(outFileName, cmpFileName);
}
/// <summary>Form fields copying from the tagged document.</summary>
[NUnit.Framework.Test]
public virtual void FormFieldTaggingTest02() {
String outFileName = destinationFolder + "taggedPdfWithForms02.pdf";
String cmpFileName = sourceFolder + "cmp_taggedPdfWithForms02.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outFileName));
pdfDoc.SetTagged();
pdfDoc.InitializeOutlines();
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(pdfDoc, true);
acroForm.AddField(new CheckBoxFormFieldBuilder(pdfDoc, "TestCheck").SetWidgetRectangle(new Rectangle(36, 560
, 20, 20)).CreateCheckBox().SetValue("1", true));
PdfDocument docToCopyFrom = new PdfDocument(new PdfReader(sourceFolder + "cmp_taggedPdfWithForms07.pdf"));
docToCopyFrom.CopyPagesTo(1, docToCopyFrom.GetNumberOfPages(), pdfDoc, new PdfPageFormCopier());
pdfDoc.Close();
CompareOutput(outFileName, cmpFileName);
}
/// <summary>Form fields flattening in the tagged document.</summary>
[NUnit.Framework.Test]
public virtual void FormFieldTaggingTest03() {
String outFileName = destinationFolder + "taggedPdfWithForms03.pdf";
String cmpFileName = sourceFolder + "cmp_taggedPdfWithForms03.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfReader(sourceFolder + "cmp_taggedPdfWithForms01.pdf"), new PdfWriter
(outFileName));
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(pdfDoc, false);
acroForm.FlattenFields();
pdfDoc.Close();
CompareOutput(outFileName, cmpFileName);
}
/// <summary>Removing fields from tagged document.</summary>
[NUnit.Framework.Test]
public virtual void FormFieldTaggingTest04() {
String outFileName = destinationFolder + "taggedPdfWithForms04.pdf";
String cmpFileName = sourceFolder + "cmp_taggedPdfWithForms04.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfReader(sourceFolder + "cmp_taggedPdfWithForms01.pdf"), new PdfWriter
(outFileName));
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(pdfDoc, false);
acroForm.RemoveField("TestCheck");
acroForm.RemoveField("push");
pdfDoc.Close();
CompareOutput(outFileName, cmpFileName);
}
/// <summary>Form fields flattening in the tagged document (writer mode).</summary>
[NUnit.Framework.Test]
public virtual void FormFieldTaggingTest05() {
String outFileName = destinationFolder + "taggedPdfWithForms05.pdf";
String cmpFileName = sourceFolder + "cmp_taggedPdfWithForms05.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outFileName));
pdfDoc.SetTagged();
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
AddFormFieldsToDocument(pdfDoc, form);
form.FlattenFields();
pdfDoc.Close();
CompareOutput(outFileName, cmpFileName);
}
/// <summary>Removing fields from tagged document (writer mode).</summary>
[NUnit.Framework.Test]
public virtual void FormFieldTaggingTest06() {
String outFileName = destinationFolder + "taggedPdfWithForms06.pdf";
String cmpFileName = sourceFolder + "cmp_taggedPdfWithForms06.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outFileName));
pdfDoc.SetTagged();
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
AddFormFieldsToDocument(pdfDoc, form);
form.RemoveField("TestCheck");
form.RemoveField("push");
pdfDoc.Close();
CompareOutput(outFileName, cmpFileName);
}
/// <summary>Addition of the form field at the specific position in tag structure.</summary>
[NUnit.Framework.Test]
public virtual void FormFieldTaggingTest07() {
String outFileName = destinationFolder + "taggedPdfWithForms07.pdf";
String cmpFileName = sourceFolder + "cmp_taggedPdfWithForms07.pdf";
PdfWriter writer = new PdfWriter(outFileName);
PdfReader reader = new PdfReader(sourceFolder + "taggedDocWithFields.pdf");
PdfDocument pdfDoc = new PdfDocument(reader, writer);
// Original document is already tagged, so there is no need to mark it as tagged again
// pdfDoc.setTagged();
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(pdfDoc, true);
PdfButtonFormField pushButton = new PushButtonFormFieldBuilder(pdfDoc, "push").SetWidgetRectangle(new Rectangle
(36, 650, 40, 20)).SetCaption("Capcha").CreatePushButton();
TagTreePointer tagPointer = pdfDoc.GetTagStructureContext().GetAutoTaggingPointer();
tagPointer.MoveToKid(StandardRoles.DIV);
acroForm.AddField(pushButton);
pdfDoc.Close();
CompareOutput(outFileName, cmpFileName);
}
private void AddFormFieldsToDocument(PdfDocument pdfDoc, PdfAcroForm acroForm) {
Rectangle rect = new Rectangle(36, 700, 20, 20);
Rectangle rect1 = new Rectangle(36, 680, 20, 20);
PdfButtonFormField group = new RadioFormFieldBuilder(pdfDoc, "TestGroup").CreateRadioGroup();
group.SetValue("1", true);
new RadioFormFieldBuilder(pdfDoc).SetWidgetRectangle(rect).CreateRadioButton(group, "1");
new RadioFormFieldBuilder(pdfDoc).SetWidgetRectangle(rect1).CreateRadioButton(group, "2");
acroForm.AddField(group);
PdfButtonFormField pushButton = new PushButtonFormFieldBuilder(pdfDoc, "push").SetWidgetRectangle(new Rectangle
(36, 650, 40, 20)).SetCaption("Capcha").CreatePushButton();
PdfButtonFormField checkBox = new CheckBoxFormFieldBuilder(pdfDoc, "TestCheck").SetWidgetRectangle(new Rectangle
(36, 560, 20, 20)).CreateCheckBox();
checkBox.SetValue("1", true);
acroForm.AddField(pushButton);
acroForm.AddField(checkBox);
}
private void CompareOutput(String outFileName, String cmpFileName) {
CompareTool compareTool = new CompareTool();
String compareResult = compareTool.CompareTagStructures(outFileName, cmpFileName);
if (compareResult != null) {
NUnit.Framework.Assert.Fail(compareResult);
}
compareResult = compareTool.CompareByContent(outFileName, cmpFileName, destinationFolder, "diff" + outFileName
);
if (compareResult != null) {
NUnit.Framework.Assert.Fail(compareResult);
}
}
}
}

View File

@@ -0,0 +1,169 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using TSpdf.Forms.Fields;
using TSpdf.Kernel.Geom;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Utils;
using TSpdf.Test;
namespace TSpdf.Forms {
[NUnit.Framework.Category("IntegrationTest")]
public class PdfAcroFormInAppendModeTest : ExtendedTSpdfTest {
private const String TEST_NAME = "PdfAcroFormInAppendModeTest/";
private static readonly String DESTINATION_DIR = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/forms/" + TEST_NAME;
private static readonly String SOURCE_DIR = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/forms/" + TEST_NAME;
private static readonly String INPUT_FILE_WITH_TWO_FORM_FIELDS = SOURCE_DIR + "inputFileWithTwoFormFields.pdf";
private static readonly String INPUT_FILE_WITH_INDIRECT_FIELDS_ARRAY = SOURCE_DIR + "inputFileWithIndirectFieldsArray.pdf";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
CreateDestinationFolder(DESTINATION_DIR);
}
[NUnit.Framework.Test]
public virtual void AddFieldTest() {
String outputFile = "addFieldTest.pdf";
PdfDocument outputDoc = new PdfDocument(new PdfReader(INPUT_FILE_WITH_TWO_FORM_FIELDS), new PdfWriter(DESTINATION_DIR
+ outputFile), new StampingProperties().UseAppendMode());
PdfFormField field = new CheckBoxFormFieldBuilder(outputDoc, "checkboxname").SetWidgetRectangle(new Rectangle
(10, 10, 24, 24)).CreateCheckBox().SetCheckType(PdfFormField.TYPE_CHECK).SetValue("On");
PdfAcroForm.GetAcroForm(outputDoc, true).AddField(field);
outputDoc.Close();
CompareWithCmp(outputFile);
}
[NUnit.Framework.Test]
public virtual void RemoveFieldTest() {
String outputFile = "removeFieldTest.pdf";
PdfDocument outputDoc = new PdfDocument(new PdfReader(INPUT_FILE_WITH_TWO_FORM_FIELDS), new PdfWriter(DESTINATION_DIR
+ outputFile), new StampingProperties().UseAppendMode());
PdfAcroForm.GetAcroForm(outputDoc, true).RemoveField("textfield2");
outputDoc.Close();
CompareWithCmp(outputFile);
}
[NUnit.Framework.Test]
public virtual void RemoveKidTest() {
// Creating input document
String inputFile = "in_removeKidTest.pdf";
PdfDocument inDoc = new PdfDocument(new PdfWriter(DESTINATION_DIR + inputFile));
inDoc.AddNewPage();
PdfFormField root = new NonTerminalFormFieldBuilder(inDoc, "root").CreateNonTerminalFormField();
PdfFormField child = new NonTerminalFormFieldBuilder(inDoc, "child").CreateNonTerminalFormField();
root.AddKid(child);
PdfAcroForm.GetAcroForm(inDoc, true).AddField(root);
inDoc.Close();
// Creating stamping document
String outputFile = "removeKidTest.pdf";
PdfReader reader = new PdfReader(DESTINATION_DIR + inputFile);
PdfWriter writer = new PdfWriter(DESTINATION_DIR + outputFile);
PdfDocument outputDoc = new PdfDocument(reader, writer, new StampingProperties().UseAppendMode());
PdfAcroForm.GetAcroForm(outputDoc, true).RemoveField("root.child");
outputDoc.Close();
CompareWithCmp(outputFile);
}
[NUnit.Framework.Test]
public virtual void ReplaceFieldTest() {
String outputFile = "replaceFieldTest.pdf";
PdfDocument outputDoc = new PdfDocument(new PdfReader(INPUT_FILE_WITH_TWO_FORM_FIELDS), new PdfWriter(DESTINATION_DIR
+ outputFile), new StampingProperties().UseAppendMode());
PdfFormField newField = new TextFormFieldBuilder(outputDoc, "newfield").SetWidgetRectangle(new Rectangle(20
, 160, 100, 20)).CreateText().SetValue("new field");
PdfAcroForm.GetAcroForm(outputDoc, true).ReplaceField("textfield1", newField);
outputDoc.Close();
CompareWithCmp(outputFile);
}
[NUnit.Framework.Test]
public virtual void AddFieldToIndirectFieldsArrayTest() {
String outputFile = "addFieldToIndirectFieldsArrayTest.pdf";
PdfDocument document = new PdfDocument(new PdfReader(INPUT_FILE_WITH_INDIRECT_FIELDS_ARRAY), new PdfWriter
(DESTINATION_DIR + outputFile), new StampingProperties().UseAppendMode());
PdfFormField field = new CheckBoxFormFieldBuilder(document, "checkboxname").SetWidgetRectangle(new Rectangle
(10, 10, 24, 24)).CreateCheckBox().SetCheckType(PdfFormField.TYPE_CHECK).SetValue("On");
// Get an existing acroform and add new field to it
PdfAcroForm.GetAcroForm(document, false).AddField(field);
document.Close();
CompareWithCmp(outputFile);
}
[NUnit.Framework.Test]
public virtual void RemoveFieldFromIndirectFieldsArrayTest() {
String outputFile = "removeFieldFromIndirectFieldsArrayTest.pdf";
PdfDocument outputDoc = new PdfDocument(new PdfReader(INPUT_FILE_WITH_INDIRECT_FIELDS_ARRAY), new PdfWriter
(DESTINATION_DIR + outputFile), new StampingProperties().UseAppendMode());
PdfAcroForm.GetAcroForm(outputDoc, true).RemoveField("textfield2");
outputDoc.Close();
CompareWithCmp(outputFile);
}
[NUnit.Framework.Test]
public virtual void RemoveKidFromIndirectKidsArrayTest() {
String inputFile = "in_removeKidFromIndirectKidsArrayTest.pdf";
String outputFile = "removeKidFromIndirectKidsArrayTest.pdf";
// Creating input document
PdfDocument inDoc = new PdfDocument(new PdfWriter(DESTINATION_DIR + inputFile));
inDoc.AddNewPage();
PdfFormField root = new NonTerminalFormFieldBuilder(inDoc, "root").CreateNonTerminalFormField();
PdfFormField child = new NonTerminalFormFieldBuilder(inDoc, "child").CreateNonTerminalFormField();
root.AddKid(child);
PdfAcroForm.GetAcroForm(inDoc, true).AddField(root);
// make kids array indirect
PdfAcroForm.GetAcroForm(inDoc, true).GetField("root").GetKids().MakeIndirect(inDoc);
inDoc.Close();
// Creating stamping document
PdfReader reader = new PdfReader(DESTINATION_DIR + inputFile);
PdfWriter writer = new PdfWriter(DESTINATION_DIR + outputFile);
PdfDocument outputDoc = new PdfDocument(reader, writer, new StampingProperties().UseAppendMode());
PdfAcroForm.GetAcroForm(outputDoc, true).RemoveField("root.child");
outputDoc.Close();
CompareWithCmp(outputFile);
}
[NUnit.Framework.Test]
public virtual void AddFieldToDirectAcroFormTest() {
String inputFile = SOURCE_DIR + "inputFileWithDirectAcroForm.pdf";
String outputFile = "addFieldToDirectAcroFormTest.pdf";
PdfDocument outputDoc = new PdfDocument(new PdfReader(inputFile), new PdfWriter(DESTINATION_DIR + outputFile
), new StampingProperties().UseAppendMode());
PdfFormField field = new CheckBoxFormFieldBuilder(outputDoc, "checkboxname").SetWidgetRectangle(new Rectangle
(10, 10, 24, 24)).CreateCheckBox().SetCheckType(PdfFormField.TYPE_CHECK).SetValue("On");
PdfAcroForm.GetAcroForm(outputDoc, true).AddField(field);
outputDoc.Close();
CompareWithCmp(outputFile);
}
private static void CompareWithCmp(String outputFile) {
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(DESTINATION_DIR + outputFile, SOURCE_DIR
+ "cmp_" + outputFile, DESTINATION_DIR, "diff_"));
}
}
}

View File

@@ -0,0 +1,45 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using TSpdf.Forms.Logs;
using TSpdf.Kernel.Pdf;
using TSpdf.Test;
using TSpdf.Test.Attributes;
namespace TSpdf.Forms {
[NUnit.Framework.Category("IntegrationTest")]
public class PdfAcroFormIntegrationTest : ExtendedTSpdfTest {
public static readonly String SOURCE_FOLDER = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/forms/PdfAcroFormIntegrationTest/";
[NUnit.Framework.Test]
[LogMessage(FormsLogMessageConstants.CANNOT_CREATE_FORMFIELD)]
public virtual void OrphandNamelessFormFieldTest() {
using (PdfDocument pdfDoc = new PdfDocument(new PdfReader(SOURCE_FOLDER + "orphanedFormField.pdf"))) {
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
// 2 out of 3 have been gathered
NUnit.Framework.Assert.AreEqual(2, form.GetDirectFormFields().Count);
}
}
}
}

View File

@@ -0,0 +1,480 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using TSpdf.Forms.Exceptions;
using TSpdf.Forms.Fields;
using TSpdf.Forms.Logs;
using TSpdf.IO.Source;
using TSpdf.Kernel.Exceptions;
using TSpdf.Kernel.Geom;
using TSpdf.Kernel.Pdf;
using TSpdf.Test;
using TSpdf.Test.Attributes;
namespace TSpdf.Forms {
[NUnit.Framework.Category("UnitTest")]
public class PdfAcroFormTest : ExtendedTSpdfTest {
[NUnit.Framework.Test]
public virtual void SetSignatureFlagsTest() {
using (PdfDocument outputDoc = CreateDocument()) {
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(outputDoc, true);
acroForm.SetSignatureFlags(65);
bool isModified = acroForm.GetPdfObject().IsModified();
bool isReleaseForbidden = acroForm.GetPdfObject().IsReleaseForbidden();
PdfObject sigFlags = acroForm.GetPdfObject().Get(PdfName.SigFlags);
outputDoc.Close();
NUnit.Framework.Assert.AreEqual(new PdfNumber(65), sigFlags);
NUnit.Framework.Assert.IsTrue(isModified);
NUnit.Framework.Assert.IsTrue(isReleaseForbidden);
}
}
[NUnit.Framework.Test]
public virtual void AddChildToFormFieldTest() {
using (PdfDocument outputDoc = CreateDocument()) {
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(outputDoc, true);
PdfFormField field = new TextFormFieldBuilder(outputDoc, "text1").SetWidgetRectangle(new Rectangle(100, 700
, 200, 20)).CreateText();
acroForm.AddField(field);
PdfFormField root = new TextFormFieldBuilder(outputDoc, "root").SetWidgetRectangle(new Rectangle(100, 600,
200, 20)).CreateText();
PdfFormField child = new TextFormFieldBuilder(outputDoc, "child").SetWidgetRectangle(new Rectangle(100, 300
, 200, 20)).CreateText();
root.AddKid(child);
acroForm.AddField(root);
NUnit.Framework.Assert.AreEqual(2, acroForm.fields.Count);
PdfArray fieldKids = root.GetKids();
NUnit.Framework.Assert.AreEqual(2, fieldKids.Size());
}
}
[NUnit.Framework.Test]
public virtual void AddChildToWidgetTest() {
using (PdfDocument outputDoc = CreateDocument()) {
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(outputDoc, true);
PdfArray options = new PdfArray();
options.Add(new PdfString("1"));
options.Add(new PdfString("2"));
PdfTextFormField text = new TextFormFieldBuilder(outputDoc, "text").SetWidgetRectangle(new Rectangle(36, 696
, 20, 20)).CreateText();
PdfTextFormField childText = new TextFormFieldBuilder(outputDoc, "childText").SetWidgetRectangle(new Rectangle
(36, 696, 20, 20)).CreateText();
text.AddKid(childText);
acroForm.AddField(text);
NUnit.Framework.Assert.AreEqual(1, acroForm.fields.Count);
IList<AbstractPdfFormField> fieldKids = text.GetChildFields();
NUnit.Framework.Assert.AreEqual(2, fieldKids.Count);
}
}
[NUnit.Framework.Test]
public virtual void GetFormFieldChildTest() {
using (PdfDocument outputDoc = CreateDocument()) {
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(outputDoc, true);
PdfFormField field = new TextFormFieldBuilder(outputDoc, "text1").SetWidgetRectangle(new Rectangle(100, 700
, 200, 20)).CreateText();
acroForm.AddField(field);
PdfFormField root = new TextFormFieldBuilder(outputDoc, "root").SetWidgetRectangle(new Rectangle(100, 600,
200, 20)).CreateText();
PdfFormField child = new TextFormFieldBuilder(outputDoc, "child").SetWidgetRectangle(new Rectangle(100, 600
, 200, 20)).CreateText();
root.AddKid(child);
acroForm.AddField(root);
PdfFormField childField = acroForm.GetField("root.child");
NUnit.Framework.Assert.AreEqual("root.child", childField.GetFieldName().ToString());
}
}
[NUnit.Framework.Test]
public virtual void GetFormFieldWithEqualChildNamesTest() {
using (PdfDocument outputDoc = CreateDocument()) {
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(outputDoc, true);
PdfFormField field = new TextFormFieldBuilder(outputDoc, "text1").SetWidgetRectangle(new Rectangle(100, 700
, 200, 20)).CreateText();
acroForm.AddField(field);
PdfFormField root = new TextFormFieldBuilder(outputDoc, "root").SetWidgetRectangle(new Rectangle(100, 600,
200, 20)).CreateText();
PdfFormField child = new TextFormFieldBuilder(outputDoc, "field").SetWidgetRectangle(new Rectangle(100, 300
, 200, 20)).CreateText();
PdfFormField child1 = new TextFormFieldBuilder(outputDoc, "field").SetWidgetRectangle(new Rectangle(100, 300
, 200, 20)).CreateText();
PdfFormField child2 = new TextFormFieldBuilder(outputDoc, "another_name").SetWidgetRectangle(new Rectangle
(100, 300, 200, 20)).CreateText();
child1.AddKid(child2);
child.AddKid(child1);
root.AddKid(child);
acroForm.AddField(root);
PdfFormField childField = acroForm.GetField("root.field.field.another_name");
NUnit.Framework.Assert.AreEqual("root.field.field.another_name", childField.GetFieldName().ToString());
}
}
[NUnit.Framework.Test]
public virtual void ChangeFieldNameTest() {
using (PdfDocument outputDoc = CreateDocument()) {
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(outputDoc, true);
PdfFormField field = new TextFormFieldBuilder(outputDoc, "text1").SetWidgetRectangle(new Rectangle(100, 700
, 200, 20)).CreateText();
acroForm.AddField(field);
PdfFormField root = new TextFormFieldBuilder(outputDoc, "root").SetWidgetRectangle(new Rectangle(100, 600,
200, 20)).CreateText();
PdfFormField child = new TextFormFieldBuilder(outputDoc, "child").SetWidgetRectangle(new Rectangle(100, 300
, 200, 20)).CreateText();
root.AddKid(child);
acroForm.AddField(root);
acroForm.GetField("root").SetFieldName("diff");
PdfFormField childField = PdfAcroForm.GetAcroForm(outputDoc, true).GetField("diff.child");
NUnit.Framework.Assert.AreEqual("diff.child", childField.GetFieldName().ToString());
}
}
[NUnit.Framework.Test]
public virtual void RemoveChildFromFormFieldTest() {
using (PdfDocument outputDoc = CreateDocument()) {
outputDoc.AddNewPage();
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(outputDoc, true);
PdfFormField field = new TextFormFieldBuilder(outputDoc, "text1").SetWidgetRectangle(new Rectangle(100, 700
, 200, 20)).CreateText().SetValue("text1");
acroForm.AddField(field);
PdfFormField root = new TextFormFieldBuilder(outputDoc, "root").SetWidgetRectangle(new Rectangle(100, 600,
200, 20)).CreateText().SetValue("root");
PdfFormField child = new TextFormFieldBuilder(outputDoc, "child").SetWidgetRectangle(new Rectangle(100, 300
, 200, 20)).CreateText().SetValue("child");
PdfFormField child1 = new TextFormFieldBuilder(outputDoc, "aaaaa").SetWidgetRectangle(new Rectangle(100, 400
, 200, 20)).CreateText().SetValue("aaaaa");
PdfFormField child2 = new TextFormFieldBuilder(outputDoc, "bbbbb").SetWidgetRectangle(new Rectangle(100, 500
, 200, 20)).CreateText().SetValue("bbbbb");
child1.AddKid(child2);
child.AddKid(child1);
root.AddKid(child);
acroForm.AddField(root);
acroForm.RemoveField("root.child.aaaaa");
NUnit.Framework.Assert.AreEqual(2, acroForm.fields.Count);
NUnit.Framework.Assert.AreEqual(2, root.GetKids().Size());
}
}
[NUnit.Framework.Test]
public virtual void GetChildFromFormFieldWithDifferentAmountOfChildrenTest() {
using (PdfDocument outputDoc = CreateDocument()) {
outputDoc.AddNewPage();
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(outputDoc, true);
PdfFormField field = new TextFormFieldBuilder(outputDoc, "text1").SetWidgetRectangle(new Rectangle(100, 700
, 200, 20)).CreateText().SetValue("text1");
acroForm.AddField(field);
PdfFormField root = new TextFormFieldBuilder(outputDoc, "root").SetWidgetRectangle(new Rectangle(100, 600,
200, 20)).CreateText().SetValue("root");
PdfFormField child = new TextFormFieldBuilder(outputDoc, "child").SetWidgetRectangle(new Rectangle(100, 300
, 200, 20)).CreateText().SetValue("child");
PdfFormField child1 = new TextFormFieldBuilder(outputDoc, "aaaaa").SetWidgetRectangle(new Rectangle(100, 400
, 200, 20)).CreateText().SetValue("aaaaa");
PdfFormField child2 = new TextFormFieldBuilder(outputDoc, "bbbbb").SetWidgetRectangle(new Rectangle(100, 500
, 200, 20)).CreateText().SetValue("bbbbb");
PdfFormField child3 = new TextFormFieldBuilder(outputDoc, "child1").SetWidgetRectangle(new Rectangle(100,
500, 200, 20)).CreateText().SetValue("child1");
PdfFormField child4 = new TextFormFieldBuilder(outputDoc, "child2").SetWidgetRectangle(new Rectangle(100,
500, 200, 20)).CreateText().SetValue("child2");
PdfFormField child5 = new TextFormFieldBuilder(outputDoc, "child2").SetWidgetRectangle(new Rectangle(100,
500, 200, 20)).CreateText().SetValue("child2");
child1.AddKid(child2);
child1.AddKid(child3);
child1.AddKid(child4);
child4.AddKid(child5);
child.AddKid(child1);
root.AddKid(child);
acroForm.AddField(root);
PdfFormField childField = acroForm.GetField("root.child.aaaaa.child2");
NUnit.Framework.Assert.AreEqual("root.child.aaaaa.child2", childField.GetFieldName().ToString());
NUnit.Framework.Assert.AreEqual(2, acroForm.fields.Count);
NUnit.Framework.Assert.AreEqual(2, root.GetKids().Size());
}
}
[NUnit.Framework.Test]
public virtual void CheckFormFieldsSizeTest() {
using (PdfDocument outputDoc = CreateDocument()) {
outputDoc.AddNewPage();
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(outputDoc, true);
NUnit.Framework.Assert.AreEqual(0, acroForm.GetAllFormFields().Count);
NUnit.Framework.Assert.AreEqual(0, acroForm.GetAllFormFieldsAndAnnotations().Count);
PdfDictionary fieldDict = new PdfDictionary();
fieldDict.Put(PdfName.FT, PdfName.Tx);
PdfFormField field = PdfFormField.MakeFormField(fieldDict.MakeIndirect(outputDoc), outputDoc);
field.SetFieldName("Field1");
acroForm.AddField(field);
NUnit.Framework.Assert.AreEqual(1, acroForm.GetAllFormFields().Count);
NUnit.Framework.Assert.AreEqual(1, acroForm.GetAllFormFieldsAndAnnotations().Count);
PdfDictionary annotDict = new PdfDictionary();
annotDict.Put(PdfName.Subtype, PdfName.Widget);
field.AddKid(PdfFormAnnotation.MakeFormAnnotation(annotDict, outputDoc));
NUnit.Framework.Assert.AreEqual(1, acroForm.GetAllFormFields().Count);
NUnit.Framework.Assert.AreEqual(2, acroForm.GetAllFormFieldsAndAnnotations().Count);
}
}
[NUnit.Framework.Test]
public virtual void NamelessFieldTest() {
using (PdfDocument outputDoc = CreateDocument()) {
outputDoc.AddNewPage();
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(outputDoc, true);
PdfDictionary fieldDict = new PdfDictionary();
fieldDict.Put(PdfName.FT, PdfName.Tx);
PdfFormField field = PdfFormField.MakeFormField(fieldDict.MakeIndirect(outputDoc), outputDoc);
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => acroForm.AddField(field));
NUnit.Framework.Assert.AreEqual(FormsExceptionMessageConstant.FORM_FIELD_MUST_HAVE_A_NAME, e.Message);
outputDoc.AddNewPage();
PdfPage page = outputDoc.GetLastPage();
e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => acroForm.AddField(field, page));
NUnit.Framework.Assert.AreEqual(FormsExceptionMessageConstant.FORM_FIELD_MUST_HAVE_A_NAME, e.Message);
NUnit.Framework.Assert.AreEqual(0, acroForm.GetDirectFormFields().Count);
}
}
[NUnit.Framework.Test]
public virtual void SetCalculationOrderTest() {
using (PdfDocument outputDoc = CreateDocument()) {
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(outputDoc, true);
PdfArray calculationOrderArray = new PdfArray(new int[] { 1, 0 });
acroForm.SetCalculationOrder(calculationOrderArray);
bool isModified = acroForm.GetPdfObject().IsModified();
bool isReleaseForbidden = acroForm.GetPdfObject().IsReleaseForbidden();
PdfObject calculationOrder = acroForm.GetPdfObject().Get(PdfName.CO);
outputDoc.Close();
NUnit.Framework.Assert.AreEqual(calculationOrderArray, calculationOrder);
NUnit.Framework.Assert.IsTrue(isModified);
NUnit.Framework.Assert.IsTrue(isReleaseForbidden);
}
}
[NUnit.Framework.Test]
public virtual void SetDefaultAppearanceTest() {
using (PdfDocument outputDoc = CreateDocument()) {
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(outputDoc, true);
acroForm.SetDefaultAppearance("default appearance");
bool isModified = acroForm.GetPdfObject().IsModified();
bool isReleaseForbidden = acroForm.GetPdfObject().IsReleaseForbidden();
PdfObject calculationOrder = acroForm.GetPdfObject().Get(PdfName.DA);
outputDoc.Close();
NUnit.Framework.Assert.AreEqual(new PdfString("default appearance"), calculationOrder);
NUnit.Framework.Assert.IsTrue(isModified);
NUnit.Framework.Assert.IsTrue(isReleaseForbidden);
}
}
[NUnit.Framework.Test]
public virtual void SetDefaultJustificationTest() {
using (PdfDocument outputDoc = CreateDocument()) {
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(outputDoc, true);
acroForm.SetDefaultJustification(14);
bool isModified = acroForm.GetPdfObject().IsModified();
bool isReleaseForbidden = acroForm.GetPdfObject().IsReleaseForbidden();
PdfObject defaultJustification = acroForm.GetPdfObject().Get(PdfName.Q);
outputDoc.Close();
NUnit.Framework.Assert.AreEqual(new PdfNumber(14), defaultJustification);
NUnit.Framework.Assert.IsTrue(isModified);
NUnit.Framework.Assert.IsTrue(isReleaseForbidden);
}
}
[NUnit.Framework.Test]
public virtual void SetDefaultResourcesTest() {
using (PdfDocument outputDoc = CreateDocument()) {
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(outputDoc, true);
PdfDictionary dictionary = new PdfDictionary();
PdfAcroForm.GetAcroForm(outputDoc, true).SetDefaultResources(dictionary);
bool isModified = acroForm.GetPdfObject().IsModified();
bool isReleaseForbidden = acroForm.GetPdfObject().IsReleaseForbidden();
PdfObject defaultResourcesDict = acroForm.GetPdfObject().Get(PdfName.DR);
outputDoc.Close();
NUnit.Framework.Assert.AreEqual(dictionary, defaultResourcesDict);
NUnit.Framework.Assert.IsTrue(isModified);
NUnit.Framework.Assert.IsTrue(isReleaseForbidden);
}
}
[NUnit.Framework.Test]
public virtual void SetNeedAppearancesTest() {
using (PdfDocument outputDoc = CreateDocument()) {
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(outputDoc, true);
acroForm.SetNeedAppearances(false);
bool isModified = acroForm.GetPdfObject().IsModified();
bool isReleaseForbidden = acroForm.GetPdfObject().IsReleaseForbidden();
PdfObject needAppearance = acroForm.GetPdfObject().Get(PdfName.NeedAppearances);
outputDoc.Close();
NUnit.Framework.Assert.AreEqual(new PdfBoolean(false), needAppearance);
NUnit.Framework.Assert.IsTrue(isModified);
NUnit.Framework.Assert.IsTrue(isReleaseForbidden);
}
}
[NUnit.Framework.Test]
[LogMessage("NeedAppearances has been deprecated in PDF 2.0. Appearance streams are required in PDF 2.0.")]
public virtual void SetNeedAppearancesInPdf2Test() {
PdfDocument outputDoc = new PdfDocument(new PdfWriter(new ByteArrayOutputStream(), new WriterProperties().
SetPdfVersion(PdfVersion.PDF_2_0)));
outputDoc.AddNewPage();
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(outputDoc, true);
acroForm.SetNeedAppearances(false);
bool isModified = acroForm.GetPdfObject().IsModified();
bool isReleaseForbidden = acroForm.GetPdfObject().IsReleaseForbidden();
PdfObject needAppearance = acroForm.GetPdfObject().Get(PdfName.NeedAppearances);
outputDoc.Close();
NUnit.Framework.Assert.IsNull(needAppearance);
NUnit.Framework.Assert.IsTrue(isModified);
NUnit.Framework.Assert.IsTrue(isReleaseForbidden);
}
[NUnit.Framework.Test]
public virtual void SetGenerateAppearanceTest() {
using (PdfDocument outputDoc = CreateDocument()) {
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(outputDoc, true);
acroForm.SetNeedAppearances(false);
acroForm.SetGenerateAppearance(true);
bool isModified = acroForm.GetPdfObject().IsModified();
bool isReleaseForbidden = acroForm.GetPdfObject().IsReleaseForbidden();
bool isGenerateAppearance = acroForm.IsGenerateAppearance();
Object needAppearances = acroForm.GetPdfObject().Get(PdfName.NeedAppearances);
outputDoc.Close();
NUnit.Framework.Assert.IsNull(needAppearances);
NUnit.Framework.Assert.IsTrue(isGenerateAppearance);
NUnit.Framework.Assert.IsTrue(isModified);
NUnit.Framework.Assert.IsTrue(isReleaseForbidden);
}
}
[NUnit.Framework.Test]
public virtual void SetXFAResourcePdfArrayTest() {
using (PdfDocument outputDoc = CreateDocument()) {
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(outputDoc, true);
PdfArray array = new PdfArray();
acroForm.SetXFAResource(array);
bool isModified = acroForm.GetPdfObject().IsModified();
bool isReleaseForbidden = acroForm.GetPdfObject().IsReleaseForbidden();
PdfObject xfaObject = acroForm.GetPdfObject().Get(PdfName.XFA);
outputDoc.Close();
NUnit.Framework.Assert.AreEqual(array, xfaObject);
NUnit.Framework.Assert.IsTrue(isModified);
NUnit.Framework.Assert.IsTrue(isReleaseForbidden);
}
}
[NUnit.Framework.Test]
public virtual void SetXFAResourcePdfStreamTest() {
using (PdfDocument outputDoc = CreateDocument()) {
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(outputDoc, true);
PdfStream stream = new PdfStream();
acroForm.SetXFAResource(stream);
bool isModified = acroForm.GetPdfObject().IsModified();
bool isReleaseForbidden = acroForm.GetPdfObject().IsReleaseForbidden();
PdfObject xfaObject = acroForm.GetPdfObject().Get(PdfName.XFA);
outputDoc.Close();
NUnit.Framework.Assert.AreEqual(stream, xfaObject);
NUnit.Framework.Assert.IsTrue(isModified);
NUnit.Framework.Assert.IsTrue(isReleaseForbidden);
}
}
[NUnit.Framework.Test]
public virtual void ReplaceFormFieldRootLevelReplacesExistingFieldTest() {
using (PdfDocument outputDoc = CreateDocument()) {
outputDoc.AddNewPage();
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(outputDoc, true);
PdfDictionary fieldDict = new PdfDictionary();
fieldDict.Put(PdfName.FT, PdfName.Tx);
fieldDict.Put(PdfName.T, new PdfString("field1"));
PdfFormField field = PdfFormField.MakeFormField(fieldDict.MakeIndirect(outputDoc), outputDoc);
System.Diagnostics.Debug.Assert(field != null);
acroForm.AddField(field);
NUnit.Framework.Assert.AreEqual(1, acroForm.GetDirectFormFields().Count);
PdfDictionary fieldDictReplace = new PdfDictionary();
fieldDictReplace.Put(PdfName.FT, PdfName.Tx);
fieldDictReplace.Put(PdfName.T, new PdfString("field2"));
PdfFormField fieldReplace = PdfFormField.MakeFormField(fieldDictReplace.MakeIndirect(outputDoc), outputDoc
);
acroForm.ReplaceField("field1", fieldReplace);
NUnit.Framework.Assert.AreEqual(1, acroForm.GetDirectFormFields().Count);
NUnit.Framework.Assert.AreEqual("field2", acroForm.GetField("field2").GetFieldName().ToUnicodeString());
}
}
[NUnit.Framework.Test]
[LogMessage(FormsLogMessageConstants.PROVIDE_FORMFIELD_NAME, Count = 1)]
public virtual void ReplaceWithNullNameLogsErrorTest() {
using (PdfDocument outputDoc = CreateDocument()) {
outputDoc.AddNewPage();
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(outputDoc, true);
PdfDictionary fieldDict = new PdfDictionary();
fieldDict.Put(PdfName.FT, PdfName.Tx);
fieldDict.Put(PdfName.T, new PdfString("field1"));
PdfFormField field = PdfFormField.MakeFormField(fieldDict.MakeIndirect(outputDoc), outputDoc);
System.Diagnostics.Debug.Assert(field != null);
acroForm.AddField(field);
NUnit.Framework.Assert.AreEqual(1, acroForm.GetDirectFormFields().Count);
PdfDictionary fieldDictReplace = new PdfDictionary();
fieldDictReplace.Put(PdfName.FT, PdfName.Tx);
fieldDictReplace.Put(PdfName.T, new PdfString("field2"));
PdfFormField fieldReplace = PdfFormField.MakeFormField(fieldDictReplace.MakeIndirect(outputDoc), outputDoc
);
acroForm.ReplaceField(null, fieldReplace);
NUnit.Framework.Assert.AreEqual(1, acroForm.GetDirectFormFields().Count);
}
}
[NUnit.Framework.Test]
public virtual void ReplaceFormFieldOneDeepReplacesExistingFieldTest() {
using (PdfDocument outputDoc = CreateDocument()) {
outputDoc.AddNewPage();
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(outputDoc, true);
PdfDictionary fieldDict = new PdfDictionary();
fieldDict.Put(PdfName.FT, PdfName.Tx);
fieldDict.Put(PdfName.T, new PdfString("field1"));
PdfFormField field = PdfFormField.MakeFormField(fieldDict.MakeIndirect(outputDoc), outputDoc);
PdfDictionary fieldDictChild = new PdfDictionary();
fieldDictChild.Put(PdfName.FT, PdfName.Tx);
fieldDictChild.Put(PdfName.T, new PdfString("child1"));
PdfFormField fieldChild = PdfFormField.MakeFormField(fieldDictChild.MakeIndirect(outputDoc), outputDoc);
System.Diagnostics.Debug.Assert(field != null);
System.Diagnostics.Debug.Assert(fieldChild != null);
field.AddKid(fieldChild);
acroForm.AddField(field);
NUnit.Framework.Assert.AreEqual(1, acroForm.GetDirectFormFields().Count);
PdfDictionary fieldDictReplace = new PdfDictionary();
fieldDictReplace.Put(PdfName.FT, PdfName.Tx);
fieldDictReplace.Put(PdfName.T, new PdfString("field2"));
PdfFormField fieldReplace = PdfFormField.MakeFormField(fieldDictReplace.MakeIndirect(outputDoc), outputDoc
);
acroForm.ReplaceField("field1.child1", fieldReplace);
NUnit.Framework.Assert.AreEqual(1, acroForm.GetDirectFormFields().Count);
NUnit.Framework.Assert.AreEqual("field1.field2", acroForm.GetField("field1.field2").GetFieldName().ToUnicodeString
());
}
}
private static PdfDocument CreateDocument() {
PdfDocument outputDoc = new PdfDocument(new PdfWriter(new ByteArrayOutputStream()));
outputDoc.AddNewPage();
return outputDoc;
}
}
}

View File

@@ -0,0 +1,217 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Commons.Utils;
using TSpdf.Forms.Fields;
using TSpdf.Kernel.Colors;
using TSpdf.Kernel.Font;
using TSpdf.Kernel.Geom;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Pdf.Canvas;
using TSpdf.Kernel.Utils;
using TSpdf.Test;
namespace TSpdf.Forms {
[NUnit.Framework.Category("IntegrationTest")]
public class PdfCheckBoxFieldTest : ExtendedTSpdfTest {
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/forms/PdfCheckBoxFieldTest/";
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/forms/PdfCheckBoxFieldTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
CreateOrClearDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void CheckBoxFontSizeTest01() {
String outPdf = destinationFolder + "checkBoxFontSizeTest01.pdf";
String cmpPdf = sourceFolder + "cmp_checkBoxFontSizeTest01.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outPdf));
pdfDoc.AddNewPage();
AddCheckBox(pdfDoc, 6, 750, 7, 7);
pdfDoc.Close();
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_");
if (errorMessage != null) {
NUnit.Framework.Assert.Fail(errorMessage);
}
}
[NUnit.Framework.Test]
public virtual void CheckBoxFontSizeTest02() {
String outPdf = destinationFolder + "checkBoxFontSizeTest02.pdf";
String cmpPdf = sourceFolder + "cmp_checkBoxFontSizeTest02.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outPdf));
pdfDoc.AddNewPage();
AddCheckBox(pdfDoc, 0, 730, 7, 7);
// fallback to default fontsize — 12 is expected.
AddCheckBox(pdfDoc, -1, 710, 7, 7);
AddCheckBox(pdfDoc, 0, 640, 20, 20);
AddCheckBox(pdfDoc, 0, 600, 40, 20);
AddCheckBox(pdfDoc, 0, 550, 20, 40);
AddCheckBox(pdfDoc, 0, 520, 5, 5);
AddCheckBox(pdfDoc, 0, 510, 5, 3);
AddCheckBox(pdfDoc, 0, 500, 3, 5);
pdfDoc.Close();
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_");
if (errorMessage != null) {
NUnit.Framework.Assert.Fail(errorMessage);
}
}
[NUnit.Framework.Test]
public virtual void CheckBoxFontSizeTest03() {
String outPdf = destinationFolder + "checkBoxFontSizeTest03.pdf";
String cmpPdf = sourceFolder + "cmp_checkBoxFontSizeTest03.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outPdf));
pdfDoc.AddNewPage();
AddCheckBox(pdfDoc, 2, 730, 7, 7);
pdfDoc.Close();
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_");
if (errorMessage != null) {
NUnit.Framework.Assert.Fail(errorMessage);
}
}
[NUnit.Framework.Test]
public virtual void CheckBoxFontSizeTest04() {
String outPdf = destinationFolder + "checkBoxFontSizeTest04.pdf";
String cmpPdf = sourceFolder + "cmp_checkBoxFontSizeTest04.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outPdf));
pdfDoc.AddNewPage();
AddCheckBox(pdfDoc, 0, 730, 10, new CheckBoxFormFieldBuilder(pdfDoc, "cb_1").SetWidgetRectangle(new Rectangle
(50, 730, 10, 10)).CreateCheckBox().SetCheckType(PdfFormField.TYPE_CIRCLE).SetValue("YES"));
AddCheckBox(pdfDoc, 0, 700, 10, new CheckBoxFormFieldBuilder(pdfDoc, "cb_2").SetWidgetRectangle(new Rectangle
(50, 700, 10, 10)).CreateCheckBox().SetCheckType(PdfFormField.TYPE_CROSS).SetValue("YES"));
AddCheckBox(pdfDoc, 0, 670, 10, new CheckBoxFormFieldBuilder(pdfDoc, "cb_3").SetWidgetRectangle(new Rectangle
(50, 670, 10, 10)).CreateCheckBox().SetCheckType(PdfFormField.TYPE_DIAMOND).SetValue("YES"));
AddCheckBox(pdfDoc, 0, 640, 10, new CheckBoxFormFieldBuilder(pdfDoc, "cb_4").SetWidgetRectangle(new Rectangle
(50, 640, 10, 10)).CreateCheckBox().SetCheckType(PdfFormField.TYPE_SQUARE).SetValue("YES"));
AddCheckBox(pdfDoc, 0, 610, 10, new CheckBoxFormFieldBuilder(pdfDoc, "cb_5").SetWidgetRectangle(new Rectangle
(50, 610, 10, 10)).CreateCheckBox().SetCheckType(PdfFormField.TYPE_STAR).SetValue("YES"));
pdfDoc.Close();
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_");
if (errorMessage != null) {
NUnit.Framework.Assert.Fail(errorMessage);
}
}
[NUnit.Framework.Test]
public virtual void CheckBoxFontSizeTest05() {
String outPdf = destinationFolder + "checkBoxFontSizeTest05.pdf";
String cmpPdf = sourceFolder + "cmp_checkBoxFontSizeTest05.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outPdf));
pdfDoc.AddNewPage();
AddCheckBox(pdfDoc, 0, 730, 40, 40);
AddCheckBox(pdfDoc, 0, 600, 100, 100);
pdfDoc.Close();
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_");
if (errorMessage != null) {
NUnit.Framework.Assert.Fail(errorMessage);
}
}
[NUnit.Framework.Test]
public virtual void CheckBoxToggleTest01() {
String srcPdf = sourceFolder + "checkBoxToggledOn.pdf";
String outPdf = destinationFolder + "checkBoxToggleTest01.pdf";
String cmpPdf = sourceFolder + "cmp_checkBoxToggleTest01.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfReader(srcPdf), new PdfWriter(outPdf));
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
PdfFormField checkBox = form.GetField("cb_fs_6_7_7");
checkBox.SetValue("Off");
pdfDoc.Close();
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_");
if (errorMessage != null) {
NUnit.Framework.Assert.Fail(errorMessage);
}
}
[NUnit.Framework.Test]
public virtual void CheckBoxToggleTest02() {
String srcPdf = sourceFolder + "checkBoxToggledOn.pdf";
String outPdf = destinationFolder + "checkBoxToggleTest02.pdf";
String cmpPdf = sourceFolder + "cmp_checkBoxToggleTest02.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfReader(srcPdf), new PdfWriter(outPdf));
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
PdfFormField checkBox = form.GetField("cb_fs_6_7_7");
checkBox.SetValue("Off", false);
pdfDoc.Close();
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_");
if (errorMessage != null) {
NUnit.Framework.Assert.Fail(errorMessage);
}
}
private void AddCheckBox(PdfDocument pdfDoc, float fontSize, float yPos, float checkBoxW, float checkBoxH) {
Rectangle rect = new Rectangle(50, yPos, checkBoxW, checkBoxH);
AddCheckBox(pdfDoc, fontSize, yPos, checkBoxW, new CheckBoxFormFieldBuilder(pdfDoc, MessageFormatUtil.Format
("cb_fs_{0}_{1}_{2}", fontSize, checkBoxW, checkBoxH)).SetWidgetRectangle(rect).CreateCheckBox().SetCheckType
(PdfFormField.TYPE_CHECK).SetValue("YES"));
}
private void AddCheckBox(PdfDocument pdfDoc, float fontSize, float yPos, float checkBoxW, PdfFormField checkBox
) {
PdfPage page = pdfDoc.GetFirstPage();
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
if (fontSize >= 0) {
checkBox.SetFontSize(fontSize);
}
checkBox.GetFirstFormAnnotation().SetBorderWidth(1);
checkBox.GetFirstFormAnnotation().SetBorderColor(ColorConstants.BLACK);
form.AddField(checkBox, page);
PdfCanvas canvas = new PdfCanvas(page);
canvas.SaveState().BeginText().MoveText(50 + checkBoxW + 10, yPos).SetFontAndSize(PdfFontFactory.CreateFont
(), 12).ShowText("okay?").EndText().RestoreState();
}
}
}

View File

@@ -0,0 +1,274 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using TSpdf.Forms.Fields;
using TSpdf.IO.Font;
using TSpdf.Kernel.Colors;
using TSpdf.Kernel.Font;
using TSpdf.Kernel.Geom;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Utils;
using TSpdf.Test;
using TSpdf.Test.Attributes;
namespace TSpdf.Forms {
[NUnit.Framework.Category("IntegrationTest")]
public class PdfChoiceFieldTest : ExtendedTSpdfTest {
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/forms/PdfChoiceFieldTest/";
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/forms/PdfChoiceFieldTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
CreateOrClearDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void ChoiceFieldsWithUnicodeTest() {
String outPdf = destinationFolder + "choiceFieldsWithUnicodeTest.pdf";
String cmpPdf = sourceFolder + "cmp_choiceFieldsWithUnicodeTest.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outPdf));
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "NotoSansCJKjp-Bold.otf", "Identity-H");
font.SetSubset(false);
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
pdfDoc.AddNewPage();
// 规
PdfFormField field = new ChoiceFormFieldBuilder(pdfDoc, "combo1").SetWidgetRectangle(new Rectangle(36, 666
, 40, 80)).SetOptions(new String[] { "\u89c4", "\u89c9" }).SetConformanceLevel(null).CreateComboBox().
SetValue("\u89c4");
field.SetFont(font);
field.GetFirstFormAnnotation().SetBorderColor(ColorConstants.BLACK);
form.AddField(field);
// 觉
field = new ChoiceFormFieldBuilder(pdfDoc, "combo2").SetWidgetRectangle(new Rectangle(136, 666, 40, 80)).SetOptions
(new String[] { "\u89c4", "\u89c9" }).SetConformanceLevel(null).CreateComboBox();
field.SetValue("\u89c4").SetFont(font);
field.SetValue("\u89c9");
field.GetFirstFormAnnotation().SetBorderColor(ColorConstants.BLACK);
form.AddField(field);
// 规
field = new ChoiceFormFieldBuilder(pdfDoc, "list1").SetWidgetRectangle(new Rectangle(236, 666, 50, 80)).SetOptions
(new String[] { "\u89c4", "\u89c9" }).SetConformanceLevel(null).CreateList().SetValue("\u89c4");
field.SetFont(font);
field.GetFirstFormAnnotation().SetBorderColor(ColorConstants.BLACK);
form.AddField(field);
// 觉
field = new ChoiceFormFieldBuilder(pdfDoc, "list2").SetWidgetRectangle(new Rectangle(336, 666, 50, 80)).SetOptions
(new String[] { "\u89c4", "\u89c9" }).SetConformanceLevel(null).CreateList();
field.SetValue("\u89c4").SetFont(font);
field.SetValue("\u89c9");
field.GetFirstFormAnnotation().SetBorderColor(ColorConstants.BLACK);
form.AddField(field);
pdfDoc.Close();
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(outPdf, cmpPdf, destinationFolder);
if (errorMessage != null) {
NUnit.Framework.Assert.Fail(errorMessage);
}
}
[NUnit.Framework.Test]
public virtual void ChoiceFieldsSetValueTest() {
String srcPdf = sourceFolder + "choiceFieldsWithUnnecessaryIEntries.pdf";
String outPdf = destinationFolder + "choiceFieldsSetValueTest.pdf";
String cmpPdf = sourceFolder + "cmp_choiceFieldsSetValueTest.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfReader(srcPdf), new PdfWriter(outPdf));
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDocument, false);
PdfFormField firstField = form.GetField("First");
PdfFormField secondField = form.GetField("Second");
firstField.SetValue("First");
secondField.SetValue("Second");
PdfArray indicesFirst = ((PdfChoiceFormField)firstField).GetIndices();
PdfArray indicesSecond = ((PdfChoiceFormField)secondField).GetIndices();
PdfArray expectedIndicesFirst = new PdfArray(new int[] { 1 });
PdfArray expectedIndicesSecond = new PdfArray(new int[] { 2 });
CompareTool compareTool = new CompareTool();
NUnit.Framework.Assert.IsTrue(compareTool.CompareArrays(indicesFirst, expectedIndicesFirst));
NUnit.Framework.Assert.IsTrue(compareTool.CompareArrays(indicesSecond, expectedIndicesSecond));
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(compareTool.CompareByContent(outPdf, cmpPdf, destinationFolder));
}
[NUnit.Framework.Test]
public virtual void ComboNoHighlightCenteredTextOfChosenFirstItemTest() {
String srcPdf = sourceFolder + "comboNoHighlightCenteredTextOfChosenFirstItemTest.pdf";
String outPdf = destinationFolder + "comboNoHighlightCenteredTextOfChosenFirstItemTest.pdf";
String cmpPdf = sourceFolder + "cmp_comboNoHighlightCenteredTextOfChosenFirstItemTest.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfReader(srcPdf), new PdfWriter(outPdf));
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDocument, false);
form.GetField("First").SetValue("Default");
// flattening is only used for the sake of ease to see what appearance is generated by TSpdf
form.FlattenFields();
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder));
}
[NUnit.Framework.Test]
public virtual void NoWarningOnValueNotOfOptComboEditTest() {
String srcPdf = sourceFolder + "noWarningOnValueNotOfOptComboEditTest.pdf";
String outPdf = destinationFolder + "noWarningOnValueNotOfOptComboEditTest.pdf";
String cmpPdf = sourceFolder + "cmp_noWarningOnValueNotOfOptComboEditTest.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfReader(srcPdf), new PdfWriter(outPdf));
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDocument, false);
form.GetField("First").SetValue("Value not of /Opt array");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.FIELD_VALUE_IS_NOT_CONTAINED_IN_OPT_ARRAY, Count = 2)]
public virtual void MultiSelectByValueTest() {
String outPdf = destinationFolder + "multiSelectByValueTest.pdf";
String cmpPdf = sourceFolder + "cmp_multiSelectByValueTest.pdf";
PdfDocument document = new PdfDocument(new PdfWriter(outPdf));
document.AddNewPage();
PdfAcroForm form = PdfAcroForm.GetAcroForm(document, true);
PdfChoiceFormField choice = (PdfChoiceFormField)new ChoiceFormFieldBuilder(document, "choice").SetWidgetRectangle
(new Rectangle(336, 666, 50, 80)).SetOptions(new String[] { "one", "two", "three", "four" }).SetConformanceLevel
(null).CreateList().SetValue("two").SetFont(null);
choice.GetFirstFormAnnotation().SetBorderColor(ColorConstants.BLACK);
choice.SetMultiSelect(true);
choice.SetListSelected(new String[] { "one", "three", "eins", "drei" });
NUnit.Framework.Assert.AreEqual(new int[] { 0, 2 }, choice.GetIndices().ToIntArray());
PdfArray values = (PdfArray)choice.GetValue();
String[] valuesAsStrings = new String[values.Size()];
for (int i = 0; i < values.Size(); i++) {
valuesAsStrings[i] = values.GetAsString(i).ToUnicodeString();
}
NUnit.Framework.Assert.AreEqual(new String[] { "one", "three", "eins", "drei" }, valuesAsStrings);
form.AddField(choice);
document.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder));
}
[NUnit.Framework.Test]
public virtual void CorruptedOptAndValueSetToNullTest() {
String srcPdf = sourceFolder + "corruptedOptAndValueSetToNullTest.pdf";
String outPdf = destinationFolder + "corruptedOptAndValueSetToNullTest.pdf";
String cmpPdf = sourceFolder + "cmp_corruptedOptAndValueSetToNullTest.pdf";
PdfDocument document = new PdfDocument(new PdfReader(srcPdf), new PdfWriter(outPdf));
PdfAcroForm form = PdfAcroForm.GetAcroForm(document, false);
PdfChoiceFormField choice = (PdfChoiceFormField)form.GetField("choice");
choice.SetListSelected(new String[] { null, "three" });
document.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.FIELD_VALUE_IS_NOT_CONTAINED_IN_OPT_ARRAY)]
public virtual void MultiSelectByValueRemoveIKeyTest() {
String srcPdf = sourceFolder + "listWithPreselectedValue.pdf";
String outPdf = destinationFolder + "selectByValueRemoveIKeyTest.pdf";
String cmpPdf = sourceFolder + "cmp_selectByValueRemoveIKeyTest.pdf";
String value = "zwei";
PdfDocument document = new PdfDocument(new PdfReader(srcPdf), new PdfWriter(outPdf));
document.AddNewPage();
PdfAcroForm form = PdfAcroForm.GetAcroForm(document, true);
PdfFormField field = form.GetField("choice");
field.SetValue(value);
NUnit.Framework.Assert.IsNull(field.GetPdfObject().Get(PdfName.I));
CompareTool compareTool = new CompareTool();
NUnit.Framework.Assert.IsTrue(compareTool.CompareStrings(new PdfString(value), field.GetPdfObject().GetAsString
(PdfName.V)));
document.Close();
NUnit.Framework.Assert.IsNull(compareTool.CompareByContent(outPdf, cmpPdf, destinationFolder));
}
[NUnit.Framework.Test]
public virtual void MultiSelectByIndexOutOfBoundsTest() {
String srcPdf = sourceFolder + "multiSelectTest.pdf";
String outPdf = destinationFolder + "multiSelectByIndexOutOfBoundsTest.pdf";
String cmpPdf = sourceFolder + "cmp_multiSelectByIndexOutOfBoundsTest.pdf";
PdfDocument document = new PdfDocument(new PdfReader(srcPdf), new PdfWriter(outPdf));
PdfAcroForm form = PdfAcroForm.GetAcroForm(document, false);
PdfChoiceFormField field = (PdfChoiceFormField)form.GetField("choice");
field.SetListSelected(new int[] { 5 });
document.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder));
}
[NUnit.Framework.Test]
public virtual void NotInstanceOfPdfChoiceFormFieldTest() {
String outPdf = destinationFolder + "notInstanceOfPdfChoiceFormFieldTest.pdf";
String cmpPdf = sourceFolder + "cmp_notInstanceOfPdfChoiceFormFieldTest.pdf";
PdfDocument document = new PdfDocument(new PdfWriter(outPdf));
PdfPage page = document.AddNewPage();
PdfAcroForm form = PdfAcroForm.GetAcroForm(document, true);
PdfDictionary fieldDictionary = new PdfDictionary();
fieldDictionary.Put(PdfName.FT, PdfName.Ch);
PdfArray opt = new PdfArray();
opt.Add(new PdfString("one", PdfEncodings.UNICODE_BIG));
opt.Add(new PdfString("two", PdfEncodings.UNICODE_BIG));
opt.Add(new PdfString("three", PdfEncodings.UNICODE_BIG));
opt.Add(new PdfString("four", PdfEncodings.UNICODE_BIG));
fieldDictionary.Put(PdfName.Opt, opt);
fieldDictionary.Put(PdfName.P, page.GetPdfObject().GetIndirectReference());
fieldDictionary.Put(PdfName.Rect, new PdfArray(new int[] { 330, 660, 380, 740 }));
fieldDictionary.Put(PdfName.Subtype, PdfName.Widget);
fieldDictionary.Put(PdfName.T, new PdfString("choice", PdfEncodings.UNICODE_BIG));
fieldDictionary.MakeIndirect(document);
PdfFormField field = new PdfFormField(fieldDictionary);
field.SetValue("two");
form.AddField(field);
document.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder));
}
[NUnit.Framework.Test]
public virtual void TopIndexTest() {
String srcPdf = sourceFolder + "choiceFieldNotFittingTest.pdf";
String outPdf = destinationFolder + "topIndexTest.pdf";
String cmpPdf = sourceFolder + "cmp_topIndexTest.pdf";
PdfDocument document = new PdfDocument(new PdfReader(srcPdf), new PdfWriter(outPdf));
PdfAcroForm form = PdfAcroForm.GetAcroForm(document, false);
PdfChoiceFormField field = (PdfChoiceFormField)form.GetField("choice");
field.SetListSelected(new String[] { "seven" });
int topIndex = field.GetIndices().GetAsNumber(0).IntValue();
field.SetTopIndex(topIndex);
document.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder));
}
[NUnit.Framework.Test]
public virtual void LongOptionWrappedIntoTwoLinesTest() {
// TODO DEVSIX-4480 TSpdf wraps the text into more than one line when generating listbox appearance
String outFileName = destinationFolder + "longOptionWrappedIntoTwoLinesTest.pdf";
String cmpFileName = sourceFolder + "cmp_longOptionWrappedIntoTwoLinesTest.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDocument, true);
String shortOption = "Short option";
String longOption = "Long long long long long long long option";
String[] options = new String[] { shortOption, longOption };
Rectangle rect = new Rectangle(50, 650, 100, 100);
PdfChoiceFormField choice = new ChoiceFormFieldBuilder(pdfDocument, "List").SetWidgetRectangle(rect).SetOptions
(options).CreateList();
choice.SetValue("Short option", true);
form.AddField(choice);
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
));
}
}
}

View File

@@ -0,0 +1,159 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Forms.Fields;
using TSpdf.Kernel.Geom;
using TSpdf.Kernel.Logs;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Utils;
using TSpdf.Test;
using TSpdf.Test.Attributes;
namespace TSpdf.Forms {
[NUnit.Framework.Category("BouncyCastleIntegrationTest")]
public class PdfEncryptionTest : ExtendedTSpdfTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/forms/PdfEncryptionTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/forms/PdfEncryptionTest/";
/// <summary>User password.</summary>
public static byte[] USER = "Hello".GetBytes(TSpdf.Commons.Utils.EncodingUtil.ISO_8859_1);
/// <summary>Owner password.</summary>
public static byte[] OWNER = "World".GetBytes(TSpdf.Commons.Utils.EncodingUtil.ISO_8859_1);
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
CreateOrClearDestinationFolder(destinationFolder);
}
// Custom entry in Info dictionary is used because standard entried are gone into metadata in PDF 2.0
internal const String customInfoEntryKey = "Custom";
internal const String customInfoEntryValue = "String";
[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
public virtual void EncryptedDocumentWithFormFields() {
PdfReader reader = new PdfReader(sourceFolder + "encryptedDocumentWithFormFields.pdf", new ReaderProperties
().SetPassword("12345".GetBytes(TSpdf.Commons.Utils.EncodingUtil.ISO_8859_1)));
PdfDocument pdfDocument = new PdfDocument(reader);
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(pdfDocument, false);
acroForm.GetField("personal.name").GetPdfObject();
pdfDocument.Close();
}
[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
public virtual void EncryptAes256Pdf2PermissionsTest01() {
String filename = "encryptAes256Pdf2PermissionsTest01.pdf";
int permissions = EncryptionConstants.ALLOW_FILL_IN | EncryptionConstants.ALLOW_SCREENREADERS | EncryptionConstants
.ALLOW_DEGRADED_PRINTING;
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(destinationFolder + filename, new WriterProperties().SetPdfVersion
(PdfVersion.PDF_2_0).SetStandardEncryption(USER, OWNER, permissions, EncryptionConstants.ENCRYPTION_AES_256
)));
pdfDoc.GetDocumentInfo().SetMoreInfo(customInfoEntryKey, customInfoEntryValue);
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
PdfTextFormField textField1 = new TextFormFieldBuilder(pdfDoc, "Name").SetWidgetRectangle(new Rectangle(100
, 600, 200, 30)).CreateText();
textField1.SetValue("Enter your name");
form.AddField(textField1);
PdfTextFormField textField2 = new TextFormFieldBuilder(pdfDoc, "Surname").SetWidgetRectangle(new Rectangle
(100, 550, 200, 30)).CreateText();
textField2.SetValue("Enter your surname");
form.AddField(textField2);
PdfButtonFormField group = new RadioFormFieldBuilder(pdfDoc, "Sex").CreateRadioGroup();
group.SetValue("Male");
new RadioFormFieldBuilder(pdfDoc).SetWidgetRectangle(new Rectangle(100, 530, 10, 10)).CreateRadioButton(group
, "Male");
new RadioFormFieldBuilder(pdfDoc).SetWidgetRectangle(new Rectangle(120, 530, 10, 10)).CreateRadioButton(group
, "Female");
form.AddField(group);
pdfDoc.Close();
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(destinationFolder + filename, sourceFolder + "cmp_" + filename
, destinationFolder, "diff_", USER, USER);
if (errorMessage != null) {
NUnit.Framework.Assert.Fail(errorMessage);
}
}
[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
public virtual void EncryptAes256Pdf2PermissionsTest02() {
String filename = "encryptAes256Pdf2PermissionsTest02.pdf";
// This test differs from the previous one (encryptAes256Pdf2PermissionsTest01) only in permissions.
// Here we do not allow to fill the form in.
int permissions = EncryptionConstants.ALLOW_SCREENREADERS | EncryptionConstants.ALLOW_DEGRADED_PRINTING;
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(destinationFolder + filename, new WriterProperties().SetPdfVersion
(PdfVersion.PDF_2_0).SetStandardEncryption(USER, OWNER, permissions, EncryptionConstants.ENCRYPTION_AES_256
)));
pdfDoc.GetDocumentInfo().SetMoreInfo(customInfoEntryKey, customInfoEntryValue);
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
PdfTextFormField textField1 = new TextFormFieldBuilder(pdfDoc, "Name").SetWidgetRectangle(new Rectangle(100
, 600, 200, 30)).CreateText();
textField1.SetValue("Enter your name");
form.AddField(textField1);
PdfTextFormField textField2 = new TextFormFieldBuilder(pdfDoc, "Surname").SetWidgetRectangle(new Rectangle
(100, 550, 200, 30)).CreateText();
textField2.SetValue("Enter your surname");
form.AddField(textField2);
PdfButtonFormField group = new RadioFormFieldBuilder(pdfDoc, "Sex").CreateRadioGroup();
group.SetValue("Male");
new RadioFormFieldBuilder(pdfDoc).SetWidgetRectangle(new Rectangle(100, 530, 10, 10)).CreateRadioButton(group
, "Male");
new RadioFormFieldBuilder(pdfDoc).SetWidgetRectangle(new Rectangle(120, 530, 10, 10)).CreateRadioButton(group
, "Female");
form.AddField(group);
pdfDoc.Close();
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(destinationFolder + filename, sourceFolder + "cmp_" + filename
, destinationFolder, "diff_", USER, USER);
if (errorMessage != null) {
NUnit.Framework.Assert.Fail(errorMessage);
}
}
}
}

View File

@@ -0,0 +1,598 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.IO.Source;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Utils;
using TSpdf.Test;
using TSpdf.Test.Attributes;
namespace TSpdf.Forms {
[NUnit.Framework.Category("IntegrationTest")]
public class PdfFormCopyTest : ExtendedTSpdfTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/forms/PdfFormCopyTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/forms/PdfFormCopyTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, Count = 32)]
public virtual void CopyFieldsTest01() {
String srcFilename1 = sourceFolder + "appearances1.pdf";
String srcFilename2 = sourceFolder + "fieldsOn2-sPage.pdf";
String srcFilename3 = sourceFolder + "fieldsOn3-sPage.pdf";
String filename = destinationFolder + "copyFields01.pdf";
PdfDocument doc1 = new PdfDocument(new PdfReader(srcFilename1));
PdfDocument doc2 = new PdfDocument(new PdfReader(srcFilename2));
PdfDocument doc3 = new PdfDocument(new PdfReader(srcFilename3));
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(filename));
pdfDoc.InitializeOutlines();
doc3.CopyPagesTo(1, doc3.GetNumberOfPages(), pdfDoc, new PdfPageFormCopier());
doc2.CopyPagesTo(1, doc2.GetNumberOfPages(), pdfDoc, new PdfPageFormCopier());
doc1.CopyPagesTo(1, doc1.GetNumberOfPages(), pdfDoc, new PdfPageFormCopier());
pdfDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, sourceFolder + "cmp_copyFields01.pdf"
, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void CopyFieldsTest02() {
String srcFilename = sourceFolder + "hello_with_comments.pdf";
String filename = destinationFolder + "copyFields02.pdf";
PdfDocument doc1 = new PdfDocument(new PdfReader(srcFilename));
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(filename));
pdfDoc.InitializeOutlines();
doc1.CopyPagesTo(1, doc1.GetNumberOfPages(), pdfDoc, new PdfPageFormCopier());
pdfDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, sourceFolder + "cmp_copyFields02.pdf"
, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void CopyFieldsTest03() {
String srcFilename = sourceFolder + "hello2_with_comments.pdf";
String filename = destinationFolder + "copyFields03.pdf";
PdfDocument doc1 = new PdfDocument(new PdfReader(srcFilename));
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(filename));
pdfDoc.InitializeOutlines();
doc1.CopyPagesTo(1, doc1.GetNumberOfPages(), pdfDoc, new PdfPageFormCopier());
pdfDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, sourceFolder + "cmp_copyFields03.pdf"
, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void LargeFileTest() {
String srcFilename1 = sourceFolder + "frontpage.pdf";
String srcFilename2 = sourceFolder + "largeFile.pdf";
String filename = destinationFolder + "copyLargeFile.pdf";
PdfDocument doc1 = new PdfDocument(new PdfReader(srcFilename1));
PdfDocument doc2 = new PdfDocument(new PdfReader(srcFilename2));
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(filename));
pdfDoc.InitializeOutlines();
PdfPageFormCopier formCopier = new PdfPageFormCopier();
doc1.CopyPagesTo(1, doc1.GetNumberOfPages(), pdfDoc, formCopier);
doc2.CopyPagesTo(1, 10, pdfDoc, formCopier);
pdfDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, sourceFolder + "cmp_copyLargeFile.pdf"
, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD)]
public virtual void CopyFieldsTest04() {
String srcFilename = sourceFolder + "srcFile1.pdf";
PdfDocument srcDoc = new PdfDocument(new PdfReader(srcFilename));
PdfDocument destDoc = new PdfDocument(new PdfWriter(new ByteArrayOutputStream()));
PdfPageFormCopier formCopier = new PdfPageFormCopier();
srcDoc.CopyPagesTo(1, srcDoc.GetNumberOfPages(), destDoc, formCopier);
srcDoc.CopyPagesTo(1, srcDoc.GetNumberOfPages(), destDoc, formCopier);
PdfAcroForm form = PdfAcroForm.GetAcroForm(destDoc, false);
NUnit.Framework.Assert.AreEqual(1, form.GetFields().Size());
NUnit.Framework.Assert.IsNotNull(form.GetField("Name1"));
destDoc.Close();
}
[NUnit.Framework.Test]
public virtual void CopyFieldsTest05() {
String srcFilename = sourceFolder + "srcFile1.pdf";
String destFilename = destinationFolder + "copyFields05.pdf";
PdfDocument srcDoc = new PdfDocument(new PdfReader(srcFilename));
PdfDocument destDoc = new PdfDocument(new PdfWriter(destFilename));
destDoc.AddPage(srcDoc.GetFirstPage().CopyTo(destDoc, new PdfPageFormCopier()));
destDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFilename, sourceFolder + "cmp_copyFields05.pdf"
, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, Count = 12)]
public virtual void CopyMultipleSubfieldsTest01() {
String srcFilename = sourceFolder + "copyMultipleSubfieldsTest01.pdf";
String destFilename = destinationFolder + "copyMultipleSubfieldsTest01.pdf";
PdfDocument srcDoc = new PdfDocument(new PdfReader(srcFilename));
PdfDocument destDoc = new PdfDocument(new PdfWriter(destFilename));
PdfPageFormCopier pdfPageFormCopier = new PdfPageFormCopier();
// copying the same page from the same document twice
for (int i = 0; i < 4; ++i) {
srcDoc.CopyPagesTo(1, 1, destDoc, pdfPageFormCopier);
}
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(destDoc, false);
acroForm.GetField("text_1").SetValue("Text 1!");
acroForm.GetField("text_2").SetValue("Text 2!");
acroForm.GetField("text.3").SetValue("Text 3!");
acroForm.GetField("text.4").SetValue("Text 4!");
destDoc.Close();
srcDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFilename, sourceFolder + "cmp_copyMultipleSubfieldsTest01.pdf"
, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, Count = 2)]
public virtual void CopyMultipleSubfieldsTest02() {
String srcFilename = sourceFolder + "copyMultipleSubfieldsTest02.pdf";
String destFilename = destinationFolder + "copyMultipleSubfieldsTest02.pdf";
PdfDocument srcDoc = new PdfDocument(new PdfReader(srcFilename));
PdfDocument destDoc = new PdfDocument(new PdfWriter(destFilename));
PdfPageFormCopier pdfPageFormCopier = new PdfPageFormCopier();
// copying the same page from the same document twice
for (int i = 0; i < 3; ++i) {
srcDoc.CopyPagesTo(1, 1, destDoc, pdfPageFormCopier);
}
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(destDoc, false);
acroForm.GetField("text.3").SetValue("Text 3!");
destDoc.Close();
srcDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFilename, sourceFolder + "cmp_copyMultipleSubfieldsTest02.pdf"
, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, Count = 2)]
public virtual void CopyMultipleSubfieldsTest03() {
String srcFilename = sourceFolder + "copyMultipleSubfieldsTest03.pdf";
String destFilename = destinationFolder + "copyMultipleSubfieldsTest03.pdf";
PdfDocument srcDoc = new PdfDocument(new PdfReader(srcFilename));
PdfDocument destDoc = new PdfDocument(new PdfWriter(destFilename));
PdfPageFormCopier pdfPageFormCopier = new PdfPageFormCopier();
// copying the same page from the same document twice
for (int i = 0; i < 3; ++i) {
srcDoc.CopyPagesTo(1, 1, destDoc, pdfPageFormCopier);
}
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(destDoc, false);
acroForm.GetField("text_1").SetValue("Text 1!");
destDoc.Close();
srcDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFilename, sourceFolder + "cmp_copyMultipleSubfieldsTest03.pdf"
, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, Count = 12)]
public virtual void CopyMultipleSubfieldsSmartModeTest01() {
String srcFilename = sourceFolder + "copyMultipleSubfieldsSmartModeTest01.pdf";
String destFilename = destinationFolder + "copyMultipleSubfieldsSmartModeTest01.pdf";
PdfDocument srcDoc = new PdfDocument(new PdfReader(srcFilename));
PdfDocument destDoc = new PdfDocument(new PdfWriter(destFilename).SetSmartMode(true));
PdfPageFormCopier pdfPageFormCopier = new PdfPageFormCopier();
// copying the same page from the same document twice
for (int i = 0; i < 4; ++i) {
srcDoc.CopyPagesTo(1, 1, destDoc, pdfPageFormCopier);
}
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(destDoc, false);
acroForm.GetField("text_1").SetValue("Text 1!");
acroForm.GetField("text_2").SetValue("Text 2!");
acroForm.GetField("text.3").SetValue("Text 3!");
acroForm.GetField("text.4").SetValue("Text 4!");
destDoc.Close();
srcDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFilename, sourceFolder + "cmp_copyMultipleSubfieldsSmartModeTest01.pdf"
, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, Count = 13)]
public virtual void CopyFieldsTest06() {
String srcFilename = sourceFolder + "datasheet.pdf";
String destFilename = destinationFolder + "copyFields06.pdf";
PdfDocument srcDoc = new PdfDocument(new PdfReader(srcFilename));
PdfDocument destDoc = new PdfDocument(new PdfWriter(destFilename));
PdfPageFormCopier pdfPageFormCopier = new PdfPageFormCopier();
// copying the same page from the same document twice
for (int i = 0; i < 2; ++i) {
srcDoc.CopyPagesTo(1, 1, destDoc, pdfPageFormCopier);
}
destDoc.Close();
srcDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFilename, sourceFolder + "cmp_copyFields06.pdf"
, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, Count = 32)]
public virtual void CopyFieldsTest07() {
String srcFilename = sourceFolder + "datasheet.pdf";
String destFilename = destinationFolder + "copyFields07.pdf";
PdfDocument destDoc = new PdfDocument(new PdfWriter(destFilename));
PdfPageFormCopier pdfPageFormCopier = new PdfPageFormCopier();
// copying the same page from reopened document twice
for (int i = 0; i < 2; ++i) {
PdfDocument srcDoc = new PdfDocument(new PdfReader(srcFilename));
srcDoc.CopyPagesTo(1, 1, destDoc, pdfPageFormCopier);
srcDoc.Close();
}
destDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFilename, sourceFolder + "cmp_copyFields07.pdf"
, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, Count = 32)]
public virtual void CopyFieldsTest08() {
String srcFilename1 = sourceFolder + "appearances1.pdf";
String srcFilename2 = sourceFolder + "fieldsOn2-sPage.pdf";
String srcFilename3 = sourceFolder + "fieldsOn3-sPage.pdf";
String filename = destinationFolder + "copyFields08.pdf";
PdfDocument doc1 = new PdfDocument(new PdfReader(srcFilename1));
PdfDocument doc2 = new PdfDocument(new PdfReader(srcFilename2));
PdfDocument doc3 = new PdfDocument(new PdfReader(srcFilename3));
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(filename));
pdfDoc.InitializeOutlines();
PdfPageFormCopier formCopier = new PdfPageFormCopier();
doc3.CopyPagesTo(1, doc3.GetNumberOfPages(), pdfDoc, formCopier);
doc2.CopyPagesTo(1, doc2.GetNumberOfPages(), pdfDoc, formCopier);
doc1.CopyPagesTo(1, doc1.GetNumberOfPages(), pdfDoc, formCopier);
pdfDoc.Close();
// comparing with cmp_copyFields01.pdf on purpose: result should be the same as in the first test
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, sourceFolder + "cmp_copyFields01.pdf"
, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, Count = 64)]
//TODO DEVSIX-6345 Equal form fields full names
[NUnit.Framework.Ignore("DEVSIX-6345")]
public virtual void CopyFieldsTest09() {
String srcFilename = sourceFolder + "datasheet.pdf";
String destFilename = destinationFolder + "copyFields09.pdf";
PdfDocument destDoc = new PdfDocument(new PdfWriter(destFilename, new WriterProperties().UseSmartMode()));
// copying the same page from the same document twice
PdfPageFormCopier copier = new PdfPageFormCopier();
for (int i = 0; i < 3; ++i) {
PdfDocument srcDoc = new PdfDocument(new PdfReader(srcFilename));
srcDoc.CopyPagesTo(1, 1, destDoc, copier);
destDoc.FlushCopiedObjects(srcDoc);
srcDoc.Close();
}
destDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFilename, sourceFolder + "cmp_copyFields09.pdf"
, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void CopyFieldsTest10() {
String srcFilename = sourceFolder + "datasheet.pdf";
String destFilename = destinationFolder + "copyFields10.pdf";
PdfDocument destDoc = new PdfDocument(new PdfWriter(destFilename, new WriterProperties().UseSmartMode()));
// copying the same page from the same document twice
for (int i = 0; i < 3; ++i) {
PdfDocument srcDoc = new PdfDocument(new PdfReader(srcFilename));
srcDoc.CopyPagesTo(1, 1, destDoc, new PdfPageFormCopier());
destDoc.FlushCopiedObjects(srcDoc);
srcDoc.Close();
}
destDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFilename, sourceFolder + "cmp_copyFields10.pdf"
, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void CopyFieldsTest11() {
String srcFilename1 = sourceFolder + "datasheet.pdf";
String srcFilename2 = sourceFolder + "datasheet2.pdf";
String destFilename = destinationFolder + "copyFields11.pdf";
PdfDocument destDoc = new PdfDocument(new PdfWriter(destFilename, new WriterProperties()));
PdfDocument srcDoc1 = new PdfDocument(new PdfReader(srcFilename1));
srcDoc1.CopyPagesTo(1, 1, destDoc, new PdfPageFormCopier());
destDoc.FlushCopiedObjects(srcDoc1);
srcDoc1.Close();
PdfDocument srcDoc2 = new PdfDocument(new PdfReader(srcFilename2));
srcDoc2.CopyPagesTo(1, 1, destDoc, new PdfPageFormCopier());
destDoc.FlushCopiedObjects(srcDoc2);
srcDoc2.Close();
destDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFilename, sourceFolder + "cmp_copyFields11.pdf"
, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void CopyFieldsTest12() {
String srcFilename1 = sourceFolder + "datasheet.pdf";
String srcFilename2 = sourceFolder + "datasheet2.pdf";
String destFilename = destinationFolder + "copyFields12.pdf";
PdfDocument destDoc = new PdfDocument(new PdfWriter(destFilename, new WriterProperties().UseSmartMode()));
PdfDocument srcDoc2 = new PdfDocument(new PdfReader(srcFilename2));
srcDoc2.CopyPagesTo(1, 1, destDoc, new PdfPageFormCopier());
destDoc.FlushCopiedObjects(srcDoc2);
srcDoc2.Close();
PdfDocument srcDoc1 = new PdfDocument(new PdfReader(srcFilename1));
srcDoc1.CopyPagesTo(1, 1, destDoc, new PdfPageFormCopier());
destDoc.FlushCopiedObjects(srcDoc1);
srcDoc1.Close();
destDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFilename, sourceFolder + "cmp_copyFields12.pdf"
, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, Count = 1)]
public virtual void CopyFieldsTest13() {
String srcFilename = sourceFolder + "copyFields13.pdf";
String destFilename = destinationFolder + "copyFields13.pdf";
PdfDocument srcDoc = new PdfDocument(new PdfReader(srcFilename));
PdfDocument destDoc = new PdfDocument(new PdfWriter(destFilename));
PdfPageFormCopier pdfPageFormCopier = new PdfPageFormCopier();
for (int i = 0; i < 1; ++i) {
srcDoc.CopyPagesTo(1, 1, destDoc, pdfPageFormCopier);
}
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(destDoc, false);
acroForm.GetField("text").SetValue("Text!");
destDoc.Close();
srcDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFilename, sourceFolder + "cmp_copyFields13.pdf"
, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void CopyPagesWithInheritedResources() {
String sourceFile = sourceFolder + "AnnotationSampleStandard.pdf";
String destFile = destinationFolder + "AnnotationSampleStandard_copy.pdf";
PdfDocument source = new PdfDocument(new PdfReader(sourceFile));
PdfDocument target = new PdfDocument(new PdfWriter(destFile));
target.InitializeOutlines();
source.CopyPagesTo(1, source.GetNumberOfPages(), target, new PdfPageFormCopier());
target.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFile, sourceFolder + "cmp_AnnotationSampleStandard_copy.pdf"
, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void UnnamedFieldsHierarchyTest() {
String srcFilename = sourceFolder + "unnamedFields.pdf";
String destFilename = destinationFolder + "hierarchyTest.pdf";
PdfDocument src = new PdfDocument(new PdfReader(srcFilename));
PdfDocument merged = new PdfDocument(new PdfWriter(destFilename));
src.CopyPagesTo(1, 1, merged, new PdfPageFormCopier());
merged.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFilename, sourceFolder + "cmp_unnamedFieldsHierarchyTest.pdf"
, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, Count = 51)]
public virtual void CopyAndEditTextFields() {
//TODO: update after DEVSIX-2354
String srcFileName = sourceFolder + "checkPdfFormCopy_Source.pdf";
String destFilename = destinationFolder + "copyAndEditTextFields.pdf";
String cmpFileName = sourceFolder + "cmp_copyAndEditTextFields.pdf";
PdfDocument srcDoc = new PdfDocument(new PdfReader(srcFileName));
PdfDocument destDoc = new PdfDocument(new PdfWriter(destFilename));
PdfPageFormCopier pdfPageFormCopier = new PdfPageFormCopier();
for (int i = 0; i < 4; i++) {
srcDoc.CopyPagesTo(1, 1, destDoc, pdfPageFormCopier);
}
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(destDoc, false);
acroForm.GetField("text_1").SetValue("text_1");
acroForm.GetField("NumberField_text.2").SetValue("-100.00");
acroForm.GetField("NumberField_text.2_1").SetValue("3.00");
acroForm.GetField("text.3_1<!").SetValue("text.3_1<!");
acroForm.GetField("text.4___#1+1").SetValue("CHANGEDtext");
destDoc.Close();
srcDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFilename, cmpFileName, destinationFolder
, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, Count = 51)]
public virtual void CopyAndEditCheckboxes() {
//TODO: update after DEVSIX-2354
String srcFileName = sourceFolder + "checkPdfFormCopy_Source.pdf";
String destFilename = destinationFolder + "copyAndEditCheckboxes.pdf";
String cmpFileName = sourceFolder + "cmp_copyAndEditCheckboxes.pdf";
PdfDocument srcDoc = new PdfDocument(new PdfReader(srcFileName));
PdfDocument destDoc = new PdfDocument(new PdfWriter(destFilename));
PdfPageFormCopier pdfPageFormCopier = new PdfPageFormCopier();
for (int i = 0; i < 4; i++) {
srcDoc.CopyPagesTo(1, 1, destDoc, pdfPageFormCopier);
}
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(destDoc, false);
acroForm.GetField("CheckBox_1").SetValue("On");
acroForm.GetField("Check Box.2").SetValue("Off");
acroForm.GetField("CheckBox4.1#1").SetValue("Off");
destDoc.Close();
srcDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFilename, cmpFileName, destinationFolder
, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, Count = 51)]
public virtual void CopyAndEditRadioButtons() {
//TODO: update after DEVSIX-2354
String srcFileName = sourceFolder + "checkPdfFormCopy_Source.pdf";
String destFilename = destinationFolder + "copyAndEditRadioButtons.pdf";
String cmpFileName = sourceFolder + "cmp_copyAndEditRadioButtons.pdf";
PdfDocument srcDoc = new PdfDocument(new PdfReader(srcFileName));
PdfDocument destDoc = new PdfDocument(new PdfWriter(destFilename));
PdfPageFormCopier pdfPageFormCopier = new PdfPageFormCopier();
for (int i = 0; i < 4; i++) {
srcDoc.CopyPagesTo(1, 1, destDoc, pdfPageFormCopier);
}
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(destDoc, false);
acroForm.GetField("Group.4").SetValue("Choice_3!<>3.3.3");
destDoc.Close();
srcDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFilename, cmpFileName, destinationFolder
, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD)]
public virtual void MergeMergedFieldAndMergedFieldTest() {
String srcFileName1 = sourceFolder + "fieldMergedWithWidget.pdf";
String destFilename = destinationFolder + "mergeMergedFieldAndMergedFieldTest.pdf";
String cmpFileName = sourceFolder + "cmp_mergeMergedFieldAndMergedFieldTest.pdf";
using (PdfWriter writer = new PdfWriter(destFilename)) {
using (PdfDocument resultPdfDocument = new PdfDocument(writer)) {
using (PdfReader reader1 = new PdfReader(srcFileName1)) {
using (PdfDocument sourceDoc1 = new PdfDocument(reader1)) {
PdfAcroForm.GetAcroForm(resultPdfDocument, true);
PdfPageFormCopier formCopier = new PdfPageFormCopier();
sourceDoc1.CopyPagesTo(1, sourceDoc1.GetNumberOfPages(), resultPdfDocument, formCopier);
sourceDoc1.CopyPagesTo(1, sourceDoc1.GetNumberOfPages(), resultPdfDocument, formCopier);
}
}
}
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFilename, cmpFileName, destinationFolder
, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, Count = 2)]
public virtual void MergeMergedFieldAndTwoWidgetsTest() {
String srcFileName1 = sourceFolder + "fieldMergedWithWidget.pdf";
String srcFileName2 = sourceFolder + "fieldTwoWidgets.pdf";
String destFilename = destinationFolder + "mergeMergedFieldAndTwoWidgetsTest.pdf";
String cmpFileName = sourceFolder + "cmp_mergeMergedFieldAndTwoWidgetsTest.pdf";
using (PdfWriter writer = new PdfWriter(destFilename)) {
using (PdfDocument resultPdfDocument = new PdfDocument(writer)) {
using (PdfReader reader1 = new PdfReader(srcFileName1)) {
using (PdfDocument sourceDoc1 = new PdfDocument(reader1)) {
using (PdfReader reader2 = new PdfReader(srcFileName2)) {
using (PdfDocument sourceDoc2 = new PdfDocument(reader2)) {
PdfAcroForm.GetAcroForm(resultPdfDocument, true);
PdfPageFormCopier formCopier = new PdfPageFormCopier();
sourceDoc1.CopyPagesTo(1, sourceDoc1.GetNumberOfPages(), resultPdfDocument, formCopier);
sourceDoc2.CopyPagesTo(1, sourceDoc2.GetNumberOfPages(), resultPdfDocument, formCopier);
}
}
}
}
}
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFilename, cmpFileName, destinationFolder
, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD)]
public virtual void MergeTwoWidgetsAndMergedFieldTest() {
String srcFileName1 = sourceFolder + "fieldMergedWithWidget.pdf";
String srcFileName2 = sourceFolder + "fieldTwoWidgets.pdf";
String destFilename = destinationFolder + "mergeTwoWidgetsAndMergedFieldTest.pdf";
String cmpFileName = sourceFolder + "cmp_mergeTwoWidgetsAndMergedFieldTest.pdf";
using (PdfWriter writer = new PdfWriter(destFilename)) {
using (PdfDocument resultPdfDocument = new PdfDocument(writer)) {
using (PdfReader reader1 = new PdfReader(srcFileName1)) {
using (PdfDocument sourceDoc1 = new PdfDocument(reader1)) {
using (PdfReader reader2 = new PdfReader(srcFileName2)) {
using (PdfDocument sourceDoc2 = new PdfDocument(reader2)) {
PdfAcroForm.GetAcroForm(resultPdfDocument, true);
PdfPageFormCopier formCopier = new PdfPageFormCopier();
sourceDoc2.CopyPagesTo(1, sourceDoc2.GetNumberOfPages(), resultPdfDocument, formCopier);
sourceDoc1.CopyPagesTo(1, sourceDoc1.GetNumberOfPages(), resultPdfDocument, formCopier);
}
}
}
}
}
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFilename, cmpFileName, destinationFolder
, "diff_"));
}
[NUnit.Framework.Test]
public virtual void MergeTwoWidgetsAndTwoWidgetsTest() {
String srcFileName2 = sourceFolder + "fieldTwoWidgets.pdf";
String destFilename = destinationFolder + "mergeTwoWidgetsAndTwoWidgetsTest.pdf";
String cmpFileName = sourceFolder + "cmp_mergeTwoWidgetsAndTwoWidgetsTest.pdf";
using (PdfWriter writer = new PdfWriter(destFilename)) {
using (PdfDocument resultPdfDocument = new PdfDocument(writer)) {
using (PdfReader reader2 = new PdfReader(srcFileName2)) {
using (PdfDocument sourceDoc2 = new PdfDocument(reader2)) {
PdfAcroForm.GetAcroForm(resultPdfDocument, true);
PdfPageFormCopier formCopier = new PdfPageFormCopier();
sourceDoc2.CopyPagesTo(1, sourceDoc2.GetNumberOfPages(), resultPdfDocument, formCopier);
sourceDoc2.CopyPagesTo(1, sourceDoc2.GetNumberOfPages(), resultPdfDocument, formCopier);
}
}
}
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFilename, cmpFileName, destinationFolder
, "diff_"));
}
[NUnit.Framework.Test]
public virtual void WidgetContainsNoTEntryTest() {
String sourceFileName = sourceFolder + "fieldThreeWidgets.pdf";
String destFileName = destinationFolder + "widgetContainsNoTEntryTest.pdf";
String cmpFileName = sourceFolder + "cmp_widgetContainsNoTEntryTest.pdf";
PdfDocument sourcePdfDocument = new PdfDocument(new PdfReader(sourceFileName));
PdfDocument resultPdfDocument = new PdfDocument(new PdfWriter(destFileName));
sourcePdfDocument.CopyPagesTo(1, sourcePdfDocument.GetNumberOfPages(), resultPdfDocument, new PdfPageFormCopier
());
resultPdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFileName, cmpFileName, destinationFolder
, "diff_"));
}
}
}

View File

@@ -0,0 +1,383 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using System.IO;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Pdf.Annot;
using TSpdf.Kernel.Pdf.Navigation;
using TSpdf.Test;
namespace TSpdf.Forms {
[NUnit.Framework.Category("IntegrationTest")]
public class PdfFormCopyWithGotoTest : ExtendedTSpdfTest {
public static readonly String SOURCE_FOLDER = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/forms/PdfFormCopyWithGotoTest/";
public static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/forms/PdfFormCopyWithGotoTest/";
public static readonly String TARGET_DOC = SOURCE_FOLDER + "Target.pdf";
public static readonly String SOURCE_WIDGET_ACTION_WITH_DESTINATION_EXPLICIT = SOURCE_FOLDER + "LinkWidgetExplicitDestination.pdf";
public static readonly String SOURCE_WIDGET_ACTION_WITH_DESTINATION_NAMED = SOURCE_FOLDER + "LinkWidgetNamedDestination.pdf";
public static readonly String SOURCE_WIDGET_ADDITIONAL_ACTION_DOWN_DESTINATION_EXPLICIT = SOURCE_FOLDER +
"LinkWidgetAAMouseDownExplicitDestination.pdf";
public static readonly String SOURCE_WIDGET_ADDITIONAL_ACTION_DOWN_DESTINATION_NAMED = SOURCE_FOLDER + "LinkWidgetAAMouseDownNamedDestination.pdf";
public static readonly String SOURCE_WIDGET_ADDITIONAL_ACTION_UP_DESTINATION_EXPLICIT = SOURCE_FOLDER + "LinkWidgetAAMouseUpExplicitDestination.pdf";
public static readonly String SOURCE_WIDGET_ADDITIONAL_ACTION_UP_DESTINATION_NAMED = SOURCE_FOLDER + "LinkWidgetAAMouseUpNamedDestination.pdf";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
CreateOrClearDestinationFolder(DESTINATION_FOLDER);
}
[NUnit.Framework.Test]
public virtual void TestLinkWidgetNamedDestinationMissing() {
PdfReader sourceReader = new PdfReader(SOURCE_WIDGET_ACTION_WITH_DESTINATION_NAMED);
PdfDocument copySource = new PdfDocument(sourceReader);
PdfReader targetReader = new PdfReader(TARGET_DOC);
String outputPath = System.IO.Path.Combine(DESTINATION_FOLDER, "TestLinkWidgetNamedDestinationMissing.pdf"
).ToString();
PdfDocument targetDoc = new PdfDocument(targetReader, new PdfWriter(outputPath));
copySource.CopyPagesTo(1, 2, targetDoc, 2, new PdfPageFormCopier());
copySource.Close();
targetDoc.Close();
PdfReader resultReader = new PdfReader(outputPath);
PdfDocument resultDoc = new PdfDocument(resultReader);
// get annotation on page 2 and verify the annotation is not copied
PdfAnnotation annot = null;
foreach (PdfAnnotation item in resultDoc.GetPage(2).GetAnnotations()) {
if (item.GetSubtype() == PdfName.Widget) {
annot = item;
break;
}
}
NUnit.Framework.Assert.IsNull(((PdfWidgetAnnotation)annot).GetAction());
// verify wether name is removed
NUnit.Framework.Assert.IsTrue(resultDoc.GetCatalog().GetNameTree(PdfName.Dests).GetNames().IsEmpty());
}
[NUnit.Framework.Test]
public virtual void TestLinkWidgetNamedDestinationTargetBecomesPage5() {
PdfReader sourceReader = new PdfReader(SOURCE_WIDGET_ACTION_WITH_DESTINATION_NAMED);
PdfDocument copySource = new PdfDocument(sourceReader);
PdfReader targetReader = new PdfReader(TARGET_DOC);
String outputPath = System.IO.Path.Combine(DESTINATION_FOLDER, "TestLinkWidgetNamedDestinationTargetBecomesPage5.pdf"
).ToString();
PdfDocument targetDoc = new PdfDocument(targetReader, new PdfWriter(outputPath));
copySource.CopyPagesTo(1, 3, targetDoc, 3, new PdfPageFormCopier());
copySource.Close();
targetDoc.Close();
PdfReader resultReader = new PdfReader(outputPath);
PdfDocument resultDoc = new PdfDocument(resultReader);
// get annotation on page 3 and verify it points to page 5
PdfAnnotation annot = null;
foreach (PdfAnnotation item in resultDoc.GetPage(3).GetAnnotations()) {
if (item.GetSubtype() == PdfName.Widget) {
annot = item;
break;
}
}
NUnit.Framework.Assert.IsNotNull(annot);
PdfDestination dest = PdfDestination.MakeDestination(((PdfWidgetAnnotation)annot).GetAction().Get(PdfName.
D));
NUnit.Framework.Assert.AreEqual(resultDoc.GetPage(5).GetPdfObject(), dest.GetDestinationPage(resultDoc.GetCatalog
().GetNameTree(PdfName.Dests)));
}
[NUnit.Framework.Test]
public virtual void TestLinkWidgetExplicitDestinationMissing() {
PdfReader sourceReader = new PdfReader(SOURCE_WIDGET_ACTION_WITH_DESTINATION_EXPLICIT);
PdfDocument copySource = new PdfDocument(sourceReader);
PdfReader targetReader = new PdfReader(TARGET_DOC);
String outputPath = System.IO.Path.Combine(DESTINATION_FOLDER, "TestLinkWidgetExplicitDestinationMissing.pdf"
).ToString();
PdfDocument targetDoc = new PdfDocument(targetReader, new PdfWriter(outputPath));
copySource.CopyPagesTo(1, 2, targetDoc, 2, new PdfPageFormCopier());
copySource.Close();
targetDoc.Close();
PdfReader resultReader = new PdfReader(outputPath);
PdfDocument resultDoc = new PdfDocument(resultReader);
// get annotation on page 2 and verify the annotation is not copied
PdfAnnotation annot = null;
foreach (PdfAnnotation item in resultDoc.GetPage(2).GetAnnotations()) {
if (item.GetSubtype() == PdfName.Widget) {
annot = item;
break;
}
}
NUnit.Framework.Assert.IsNull(((PdfWidgetAnnotation)annot).GetAction());
// verify wether name is removed
NUnit.Framework.Assert.IsTrue(resultDoc.GetCatalog().GetNameTree(PdfName.Dests).GetNames().IsEmpty());
}
[NUnit.Framework.Test]
public virtual void TestLinkWidgetExplicitDestinationTargetBecomesPage5() {
PdfReader sourceReader = new PdfReader(SOURCE_WIDGET_ACTION_WITH_DESTINATION_EXPLICIT);
PdfDocument copySource = new PdfDocument(sourceReader);
PdfReader targetReader = new PdfReader(TARGET_DOC);
String outputPath = System.IO.Path.Combine(DESTINATION_FOLDER, "TestLinkWidgetExplicitDestinationTargetBecomesPage5.pdf"
).ToString();
PdfDocument targetDoc = new PdfDocument(targetReader, new PdfWriter(outputPath));
copySource.CopyPagesTo(1, 3, targetDoc, 3, new PdfPageFormCopier());
copySource.Close();
targetDoc.Close();
PdfReader resultReader = new PdfReader(outputPath);
PdfDocument resultDoc = new PdfDocument(resultReader);
// get annotation on page 3 and verify it points to page 5
PdfAnnotation annot = null;
foreach (PdfAnnotation item in resultDoc.GetPage(3).GetAnnotations()) {
if (item.GetSubtype() == PdfName.Widget) {
annot = item;
break;
}
}
NUnit.Framework.Assert.IsNotNull(annot);
PdfDestination dest = PdfDestination.MakeDestination(((PdfWidgetAnnotation)annot).GetAction().Get(PdfName.
D));
NUnit.Framework.Assert.AreEqual(resultDoc.GetPage(5).GetPdfObject(), dest.GetDestinationPage(resultDoc.GetCatalog
().GetNameTree(PdfName.Dests)));
}
[NUnit.Framework.Test]
public virtual void TestLinkWidgetAAUpNamedDestinationMissing() {
PdfReader sourceReader = new PdfReader(SOURCE_WIDGET_ADDITIONAL_ACTION_UP_DESTINATION_NAMED);
PdfDocument copySource = new PdfDocument(sourceReader);
PdfReader targetReader = new PdfReader(TARGET_DOC);
String outputPath = System.IO.Path.Combine(DESTINATION_FOLDER, "TestLinkWidgetAAUpNamedDestinationMissing.pdf"
).ToString();
PdfDocument targetDoc = new PdfDocument(targetReader, new PdfWriter(outputPath));
copySource.CopyPagesTo(1, 2, targetDoc, 2, new PdfPageFormCopier());
copySource.Close();
targetDoc.Close();
PdfReader resultReader = new PdfReader(outputPath);
PdfDocument resultDoc = new PdfDocument(resultReader);
// get annotation on page 2 and verify the annotation is not copied
PdfAnnotation annot = null;
foreach (PdfAnnotation item in resultDoc.GetPage(2).GetAnnotations()) {
if (item.GetSubtype() == PdfName.Widget) {
annot = item;
break;
}
}
NUnit.Framework.Assert.IsNull(((PdfWidgetAnnotation)annot).GetAction());
// verify wether name is removed
NUnit.Framework.Assert.IsTrue(resultDoc.GetCatalog().GetNameTree(PdfName.Dests).GetNames().IsEmpty());
}
[NUnit.Framework.Test]
public virtual void TestLinkWidgetAAUpNamedDestinationTargetBecomesPage5() {
PdfReader sourceReader = new PdfReader(SOURCE_WIDGET_ADDITIONAL_ACTION_UP_DESTINATION_NAMED);
PdfDocument copySource = new PdfDocument(sourceReader);
PdfReader targetReader = new PdfReader(TARGET_DOC);
String outputPath = System.IO.Path.Combine(DESTINATION_FOLDER, "TestLinkWidgetAAUpNamedDestinationTargetBecomesPage5.pdf"
).ToString();
PdfDocument targetDoc = new PdfDocument(targetReader, new PdfWriter(outputPath));
copySource.CopyPagesTo(1, 3, targetDoc, 3, new PdfPageFormCopier());
copySource.Close();
targetDoc.Close();
PdfReader resultReader = new PdfReader(outputPath);
PdfDocument resultDoc = new PdfDocument(resultReader);
// get annotation on page 3 and verify it points to page 5
PdfAnnotation annot = null;
foreach (PdfAnnotation item in resultDoc.GetPage(3).GetAnnotations()) {
if (item.GetSubtype() == PdfName.Widget) {
annot = item;
break;
}
}
NUnit.Framework.Assert.IsNotNull(annot);
PdfDestination dest = PdfDestination.MakeDestination(((PdfWidgetAnnotation)annot).GetAdditionalAction().GetAsDictionary
(PdfName.U).Get(PdfName.D));
NUnit.Framework.Assert.AreEqual(resultDoc.GetPage(5).GetPdfObject(), dest.GetDestinationPage(resultDoc.GetCatalog
().GetNameTree(PdfName.Dests)));
}
[NUnit.Framework.Test]
public virtual void TestLinkWidgetAAUpExplicitDestinationMissing() {
PdfReader sourceReader = new PdfReader(SOURCE_WIDGET_ADDITIONAL_ACTION_UP_DESTINATION_EXPLICIT);
PdfDocument copySource = new PdfDocument(sourceReader);
PdfReader targetReader = new PdfReader(TARGET_DOC);
String outputPath = System.IO.Path.Combine(DESTINATION_FOLDER, "TestLinkWidgetAAUpExplicitDestinationMissing.pdf"
).ToString();
PdfDocument targetDoc = new PdfDocument(targetReader, new PdfWriter(outputPath));
copySource.CopyPagesTo(1, 2, targetDoc, 2, new PdfPageFormCopier());
copySource.Close();
targetDoc.Close();
PdfReader resultReader = new PdfReader(outputPath);
PdfDocument resultDoc = new PdfDocument(resultReader);
// get annotation on page 2 and verify the annotation is not copied
PdfAnnotation annot = null;
foreach (PdfAnnotation item in resultDoc.GetPage(2).GetAnnotations()) {
if (item.GetSubtype() == PdfName.Widget) {
annot = item;
break;
}
}
NUnit.Framework.Assert.IsNull(((PdfWidgetAnnotation)annot).GetAction());
// verify wether name is removed
NUnit.Framework.Assert.IsTrue(resultDoc.GetCatalog().GetNameTree(PdfName.Dests).GetNames().IsEmpty());
}
[NUnit.Framework.Test]
public virtual void TestLinkWidgetAAUpExplicitDestinationTargetBecomesPage5() {
PdfReader sourceReader = new PdfReader(SOURCE_WIDGET_ADDITIONAL_ACTION_UP_DESTINATION_EXPLICIT);
PdfDocument copySource = new PdfDocument(sourceReader);
PdfReader targetReader = new PdfReader(TARGET_DOC);
String outputPath = System.IO.Path.Combine(DESTINATION_FOLDER, "TestLinkWidgetAAUpExplicitDestinationTargetBecomesPage5.pdf"
).ToString();
PdfDocument targetDoc = new PdfDocument(targetReader, new PdfWriter(outputPath));
copySource.CopyPagesTo(1, 3, targetDoc, 3, new PdfPageFormCopier());
copySource.Close();
targetDoc.Close();
PdfReader resultReader = new PdfReader(outputPath);
PdfDocument resultDoc = new PdfDocument(resultReader);
// get annotation on page 3 and verify it points to page 5
PdfAnnotation annot = null;
foreach (PdfAnnotation item in resultDoc.GetPage(3).GetAnnotations()) {
if (item.GetSubtype() == PdfName.Widget) {
annot = item;
break;
}
}
NUnit.Framework.Assert.IsNotNull(annot);
PdfDestination dest = PdfDestination.MakeDestination(((PdfWidgetAnnotation)annot).GetAdditionalAction().GetAsDictionary
(PdfName.U).Get(PdfName.D));
NUnit.Framework.Assert.AreEqual(resultDoc.GetPage(5).GetPdfObject(), dest.GetDestinationPage(resultDoc.GetCatalog
().GetNameTree(PdfName.Dests)));
}
[NUnit.Framework.Test]
public virtual void TestLinkWidgetAADownNamedDestinationMissing() {
PdfReader sourceReader = new PdfReader(SOURCE_WIDGET_ADDITIONAL_ACTION_DOWN_DESTINATION_NAMED);
PdfDocument copySource = new PdfDocument(sourceReader);
PdfReader targetReader = new PdfReader(TARGET_DOC);
String outputPath = System.IO.Path.Combine(DESTINATION_FOLDER, "TestLinkWidgetAADownNamedDestinationMissing.pdf"
).ToString();
PdfDocument targetDoc = new PdfDocument(targetReader, new PdfWriter(outputPath));
copySource.CopyPagesTo(1, 2, targetDoc, 2, new PdfPageFormCopier());
copySource.Close();
targetDoc.Close();
PdfReader resultReader = new PdfReader(outputPath);
PdfDocument resultDoc = new PdfDocument(resultReader);
// get annotation on page 2 and verify the annotation is not copied
PdfAnnotation annot = null;
foreach (PdfAnnotation item in resultDoc.GetPage(2).GetAnnotations()) {
if (item.GetSubtype() == PdfName.Widget) {
annot = item;
break;
}
}
NUnit.Framework.Assert.IsNull(((PdfWidgetAnnotation)annot).GetAction());
// verify wether name is removed
NUnit.Framework.Assert.IsTrue(resultDoc.GetCatalog().GetNameTree(PdfName.Dests).GetNames().IsEmpty());
}
[NUnit.Framework.Test]
public virtual void TestLinkWidgetAADownNamedDestinationTargetBecomesPage5() {
PdfReader sourceReader = new PdfReader(SOURCE_WIDGET_ADDITIONAL_ACTION_DOWN_DESTINATION_NAMED);
PdfDocument copySource = new PdfDocument(sourceReader);
PdfReader targetReader = new PdfReader(TARGET_DOC);
String outputPath = System.IO.Path.Combine(DESTINATION_FOLDER, "TestLinkWidgetAADownNamedDestinationTargetBecomesPage5.pdf"
).ToString();
PdfDocument targetDoc = new PdfDocument(targetReader, new PdfWriter(outputPath));
copySource.CopyPagesTo(1, 3, targetDoc, 3, new PdfPageFormCopier());
copySource.Close();
targetDoc.Close();
PdfReader resultReader = new PdfReader(outputPath);
PdfDocument resultDoc = new PdfDocument(resultReader);
// get annotation on page 3 and verify it points to page 5
PdfAnnotation annot = null;
foreach (PdfAnnotation item in resultDoc.GetPage(3).GetAnnotations()) {
if (item.GetSubtype() == PdfName.Widget) {
annot = item;
break;
}
}
NUnit.Framework.Assert.IsNotNull(annot);
PdfDestination dest = PdfDestination.MakeDestination(((PdfWidgetAnnotation)annot).GetAdditionalAction().GetAsDictionary
(PdfName.D).Get(PdfName.D));
NUnit.Framework.Assert.AreEqual(resultDoc.GetPage(5).GetPdfObject(), dest.GetDestinationPage(resultDoc.GetCatalog
().GetNameTree(PdfName.Dests)));
}
[NUnit.Framework.Test]
public virtual void TestLinkWidgetAADownExplicitDestinationMissing() {
PdfReader sourceReader = new PdfReader(SOURCE_WIDGET_ADDITIONAL_ACTION_DOWN_DESTINATION_EXPLICIT);
PdfDocument copySource = new PdfDocument(sourceReader);
PdfReader targetReader = new PdfReader(TARGET_DOC);
String outputPath = System.IO.Path.Combine(DESTINATION_FOLDER, "TestLinkWidgetAADownExplicitDestinationMissing.pdf"
).ToString();
PdfDocument targetDoc = new PdfDocument(targetReader, new PdfWriter(outputPath));
copySource.CopyPagesTo(1, 2, targetDoc, 2, new PdfPageFormCopier());
copySource.Close();
targetDoc.Close();
PdfReader resultReader = new PdfReader(outputPath);
PdfDocument resultDoc = new PdfDocument(resultReader);
// get annotation on page 2 and verify the annotation is not copied
PdfAnnotation annot = null;
foreach (PdfAnnotation item in resultDoc.GetPage(2).GetAnnotations()) {
if (item.GetSubtype() == PdfName.Widget) {
annot = item;
break;
}
}
NUnit.Framework.Assert.IsNull(((PdfWidgetAnnotation)annot).GetAction());
// verify wether name is removed
NUnit.Framework.Assert.IsTrue(resultDoc.GetCatalog().GetNameTree(PdfName.Dests).GetNames().IsEmpty());
}
[NUnit.Framework.Test]
public virtual void TestLinkWidgetAADownExplicitDestinationTargetBecomesPage5() {
PdfReader sourceReader = new PdfReader(SOURCE_WIDGET_ADDITIONAL_ACTION_DOWN_DESTINATION_EXPLICIT);
PdfDocument copySource = new PdfDocument(sourceReader);
PdfReader targetReader = new PdfReader(TARGET_DOC);
String outputPath = System.IO.Path.Combine(DESTINATION_FOLDER, "TestLinkWidgetAADownExplicitDestinationTargetBecomesPage5.pdf"
).ToString();
PdfDocument targetDoc = new PdfDocument(targetReader, new PdfWriter(outputPath));
copySource.CopyPagesTo(1, 3, targetDoc, 3, new PdfPageFormCopier());
copySource.Close();
targetDoc.Close();
PdfReader resultReader = new PdfReader(outputPath);
PdfDocument resultDoc = new PdfDocument(resultReader);
// get annotation on page 3 and verify it points to page 5
PdfAnnotation annot = null;
foreach (PdfAnnotation item in resultDoc.GetPage(3).GetAnnotations()) {
if (item.GetSubtype() == PdfName.Widget) {
annot = item;
break;
}
}
NUnit.Framework.Assert.IsNotNull(annot);
PdfDestination dest = PdfDestination.MakeDestination(((PdfWidgetAnnotation)annot).GetAdditionalAction().GetAsDictionary
(PdfName.D).Get(PdfName.D));
NUnit.Framework.Assert.AreEqual(resultDoc.GetPage(5).GetPdfObject(), dest.GetDestinationPage(resultDoc.GetCatalog
().GetNameTree(PdfName.Dests)));
}
}
}

View File

@@ -0,0 +1,245 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using TSpdf.Forms.Fields;
using TSpdf.IO.Font;
using TSpdf.Kernel.Colors;
using TSpdf.Kernel.Font;
using TSpdf.Kernel.Geom;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Utils;
using TSpdf.Test;
namespace TSpdf.Forms {
[NUnit.Framework.Category("IntegrationTest")]
public class PdfFormFieldMultilineTextTest : ExtendedTSpdfTest {
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/forms/PdfFormFieldMultilineTextTest/";
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/forms/PdfFormFieldMultilineTextTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void MultilineFormFieldTest() {
String filename = destinationFolder + "multilineFormFieldTest.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(filename));
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
PdfTextFormField name = new TextFormFieldBuilder(pdfDoc, "fieldName").SetWidgetRectangle(new Rectangle(150
, 600, 277, 44)).CreateMultilineText();
name.SetValue("").SetFont(null).SetFontSize(0);
name.SetScroll(false);
name.GetFirstFormAnnotation().SetBorderColor(ColorConstants.GRAY);
String TSpdfLicence = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, " + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "
+ "Lorem ipsum dolor sit amet, consectetur adipiscing elit, " + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
name.SetValue(TSpdfLicence);
form.AddField(name);
pdfDoc.Close();
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(filename, sourceFolder + "cmp_multilineFormFieldTest.pdf"
, destinationFolder, "diff_");
if (errorMessage != null) {
NUnit.Framework.Assert.Fail(errorMessage);
}
}
[NUnit.Framework.Test]
public virtual void MultilineTextFieldWithAlignmentTest() {
String outPdf = destinationFolder + "multilineTextFieldWithAlignment.pdf";
String cmpPdf = sourceFolder + "cmp_multilineTextFieldWithAlignment.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outPdf));
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
Rectangle rect = new Rectangle(210, 600, 150, 100);
PdfTextFormField field = new TextFormFieldBuilder(pdfDoc, "fieldName").SetWidgetRectangle(rect).CreateMultilineText
();
field.SetValue("some value\nsecond line\nthird");
field.SetJustification(PdfTextFormField.ALIGN_RIGHT);
form.AddField(field);
pdfDoc.Close();
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_");
if (errorMessage != null) {
NUnit.Framework.Assert.Fail(errorMessage);
}
}
[NUnit.Framework.Test]
public virtual void MultilineFormFieldNewLineTest() {
String testName = "multilineFormFieldNewLineTest";
String outPdf = destinationFolder + testName + ".pdf";
String cmpPdf = sourceFolder + "cmp_" + testName + ".pdf";
String srcPdf = sourceFolder + testName + ".pdf";
PdfWriter writer = new PdfWriter(outPdf);
PdfReader reader = new PdfReader(srcPdf);
PdfDocument pdfDoc = new PdfDocument(reader, writer);
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
IDictionary<String, PdfFormField> fields = form.GetAllFormFields();
fields.Get("BEMERKUNGEN").SetValue("First line\n\n\nFourth line");
pdfDoc.Close();
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_");
if (errorMessage != null) {
NUnit.Framework.Assert.Fail(errorMessage);
}
}
[NUnit.Framework.Test]
public virtual void MultilineFormFieldNewLineFontType3Test() {
String testName = "multilineFormFieldNewLineFontType3Test";
String outPdf = destinationFolder + testName + ".pdf";
String cmpPdf = sourceFolder + "cmp_" + testName + ".pdf";
String srcPdf = sourceFolder + testName + ".pdf";
PdfWriter writer = new PdfWriter(outPdf);
PdfReader reader = new PdfReader(srcPdf);
PdfDocument pdfDoc = new PdfDocument(reader, writer);
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
PdfTextFormField info = (PdfTextFormField)form.GetField("info");
info.SetValue("A\n\nE");
pdfDoc.Close();
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_");
if (errorMessage != null) {
NUnit.Framework.Assert.Fail(errorMessage);
}
}
[NUnit.Framework.Test]
public virtual void NotFittingByHeightTest() {
String filename = "notFittingByHeightTest.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(destinationFolder + filename));
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
for (int i = 15; i <= 50; i += 15) {
PdfFormField[] fields = new PdfFormField[] { new TextFormFieldBuilder(pdfDoc, "multi " + i).SetWidgetRectangle
(new Rectangle(100, 800 - i * 4, 150, i)).CreateMultilineText().SetValue("MULTI"), new TextFormFieldBuilder
(pdfDoc, "single " + i).SetWidgetRectangle(new Rectangle(300, 800 - i * 4, 150, i)).CreateText().SetValue
("SINGLE") };
foreach (PdfFormField field in fields) {
field.SetFontSize(40);
field.GetFirstFormAnnotation().SetBorderColor(ColorConstants.BLACK);
form.AddField(field);
}
}
pdfDoc.Close();
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(destinationFolder + filename, sourceFolder + "cmp_" + filename
, destinationFolder, "diff_");
if (errorMessage != null) {
NUnit.Framework.Assert.Fail(errorMessage);
}
}
[NUnit.Framework.Test]
public virtual void BorderWidthIndentMultilineTest() {
String filename = destinationFolder + "borderWidthIndentMultilineTest.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(filename));
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
PdfTextFormField field = new TextFormFieldBuilder(pdfDoc, "multi").SetWidgetRectangle(new Rectangle(100, 500
, 400, 300)).CreateMultilineText();
field.SetValue("Does this text overlap the border? Well it shouldn't!");
field.SetFontSize(30);
field.GetFirstFormAnnotation().SetBorderColor(ColorConstants.RED);
field.GetFirstFormAnnotation().SetBorderWidth(50);
form.AddField(field);
PdfTextFormField field2 = new TextFormFieldBuilder(pdfDoc, "multiAuto").SetWidgetRectangle(new Rectangle(100
, 400, 400, 50)).CreateMultilineText();
field2.SetValue("Does this autosize text overlap the border? Well it shouldn't! Does it fit accurately though?"
);
field2.SetFontSize(0);
field2.GetFirstFormAnnotation().SetBorderColor(ColorConstants.RED);
field2.GetFirstFormAnnotation().SetBorderWidth(20);
form.AddField(field2);
pdfDoc.Close();
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(filename, sourceFolder + "cmp_borderWidthIndentMultilineTest.pdf"
, destinationFolder, "diff_");
if (errorMessage != null) {
NUnit.Framework.Assert.Fail(errorMessage);
}
}
[NUnit.Framework.Test]
public virtual void FormFieldFilledWithStringTest() {
String value = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(destinationFolder + "formFieldWithStringTest.pdf"));
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "NotoSansCJKtc-Light.otf", PdfEncodings.IDENTITY_H
);
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(pdfDoc, true);
PdfFormField form = new TextFormFieldBuilder(pdfDoc, "field").SetWidgetRectangle(new Rectangle(59, 715, 127
, 69)).CreateMultilineText().SetValue("");
form.SetFont(font).SetFontSize(10f);
form.GetFirstFormAnnotation().SetBorderWidth(2).SetBorderColor(ColorConstants.BLACK);
form.SetValue(value);
acroForm.AddField(form);
pdfDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "formFieldWithStringTest.pdf"
, sourceFolder + "cmp_formFieldWithStringTest.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void MultilineTextFieldLeadingSpacesAreNotTrimmedTest() {
String filename = destinationFolder + "multilineTextFieldLeadingSpacesAreNotTrimmed.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(filename));
pdfDoc.AddNewPage();
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
PdfPage page = pdfDoc.GetFirstPage();
Rectangle rect = new Rectangle(210, 490, 300, 200);
PdfTextFormField field = new TextFormFieldBuilder(pdfDoc, "TestField").SetWidgetRectangle(rect).CreateMultilineText
();
field.SetValue(" value\n with\n leading\n space");
form.AddField(field, page);
pdfDoc.Close();
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(filename, sourceFolder + "cmp_multilineTextFieldLeadingSpacesAreNotTrimmed.pdf"
, destinationFolder, "diff_");
if (errorMessage != null) {
NUnit.Framework.Assert.Fail(errorMessage);
}
}
[NUnit.Framework.Test]
public virtual void MultilineTextFieldRedundantSpacesAreTrimmedTest() {
String filename = destinationFolder + "multilineTextFieldRedundantSpacesAreTrimmedTest.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(filename));
pdfDoc.AddNewPage();
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
PdfPage page = pdfDoc.GetFirstPage();
Rectangle rect = new Rectangle(210, 490, 90, 200);
PdfTextFormField field = new TextFormFieldBuilder(pdfDoc, "TestField").SetWidgetRectangle(rect).CreateMultilineText
();
field.SetValue("before spaces after spaces");
form.AddField(field, page);
pdfDoc.Close();
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(filename, sourceFolder + "cmp_multilineTextFieldRedundantSpacesAreTrimmedTest.pdf"
, destinationFolder, "diff_");
if (errorMessage != null) {
NUnit.Framework.Assert.Fail(errorMessage);
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,141 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using TSpdf.Forms.Fields;
using TSpdf.IO.Font;
using TSpdf.Kernel.Font;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Utils;
using TSpdf.Test;
namespace TSpdf.Forms {
[NUnit.Framework.Category("IntegrationTest")]
public class PdfFormFieldTextTest : ExtendedTSpdfTest {
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/forms/PdfFormFieldTextTest/";
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/forms/PdfFormFieldTextTest/";
private const String TEXT = "Some text in Russian \u0442\u0435\u043A\u0441\u0442 (text)";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void FillFormWithAutosizeTest() {
String outPdf = destinationFolder + "fillFormWithAutosizeTest.pdf";
String inPdf = sourceFolder + "fillFormWithAutosizeSource.pdf";
String cmpPdf = sourceFolder + "cmp_fillFormWithAutosizeTest.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfReader(inPdf), new PdfWriter(outPdf));
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, false);
IDictionary<String, PdfFormField> fields = form.GetAllFormFields();
fields.Get("First field").SetValue("name name name ");
fields.Get("Second field").SetValue("surname surname surname surname surname surname");
pdfDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_"
));
}
[NUnit.Framework.Test]
public virtual void DefaultAppearanceExtractionForNotMergedFieldsTest() {
PdfDocument doc = new PdfDocument(new PdfReader(sourceFolder + "sourceDAExtractionTest.pdf"), new PdfWriter
(destinationFolder + "defaultAppearanceExtractionTest.pdf"));
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, false);
form.GetField("First field").SetValue("Your name");
form.GetField("Text1").SetValue("Your surname");
doc.Close();
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(destinationFolder + "defaultAppearanceExtractionTest.pdf"
, sourceFolder + "cmp_defaultAppearanceExtractionTest.pdf", destinationFolder, "diff_");
if (errorMessage != null) {
NUnit.Framework.Assert.Fail(errorMessage);
}
}
[NUnit.Framework.Test]
public virtual void FontsResourcesHelvFontTest() {
String filename = "fontsResourcesHelvFontTest.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfReader(sourceFolder + "drWithHelv.pdf"), new PdfWriter(destinationFolder
+ filename));
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "NotoSans-Regular.ttf", PdfEncodings.IDENTITY_H);
font.SetSubset(false);
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, false);
form.GetField("description").SetValue(TEXT, font, 12f);
pdfDoc.Close();
PdfDocument document = new PdfDocument(new PdfReader(destinationFolder + filename));
PdfDictionary actualDocumentFonts = PdfAcroForm.GetAcroForm(document, false).GetPdfObject().GetAsDictionary
(PdfName.DR).GetAsDictionary(PdfName.Font);
// Note that we know the structure of the expected pdf file
PdfString expectedFieldsDAFont = new PdfString("/F2 12 Tf");
PdfObject actualFieldDAFont = document.GetCatalog().GetPdfObject().GetAsDictionary(PdfName.AcroForm).GetAsArray
(PdfName.Fields).GetAsDictionary(0).Get(PdfName.DA);
NUnit.Framework.Assert.AreEqual(new PdfName("Helvetica"), actualDocumentFonts.GetAsDictionary(new PdfName(
"F1")).Get(PdfName.BaseFont), "There is no Helvetica font within DR key");
NUnit.Framework.Assert.AreEqual(new PdfName("NotoSans"), actualDocumentFonts.GetAsDictionary(new PdfName("F2"
)).Get(PdfName.BaseFont), "There is no NotoSans font within DR key.");
NUnit.Framework.Assert.AreEqual(expectedFieldsDAFont, actualFieldDAFont, "There is no NotoSans(/F2) font within Fields DA key"
);
document.Close();
ExtendedTSpdfTest.PrintOutputPdfNameAndDir(destinationFolder + filename);
}
[NUnit.Framework.Test]
public virtual void FontsResourcesHelvCourierNotoFontTest() {
String filename = "fontsResourcesHelvCourierNotoFontTest.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfReader(sourceFolder + "drWithHelvAndCourier.pdf"), new PdfWriter
(destinationFolder + filename));
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "NotoSans-Regular.ttf", PdfEncodings.IDENTITY_H);
font.SetSubset(false);
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, false);
form.GetField("description").SetFont(font);
form.GetField("description").SetValue(TEXT);
pdfDoc.Close();
PdfDocument document = new PdfDocument(new PdfReader(destinationFolder + filename));
// Note that we know the structure of the expected pdf file
PdfString expectedAcroformDAFont = new PdfString("/F1 0 Tf 0 g ");
PdfString expectedFieldsDAFont = new PdfString("/F3 12 Tf");
PdfObject actualAcroFormDAFont = document.GetCatalog().GetPdfObject().GetAsDictionary(PdfName.AcroForm).Get
(PdfName.DA);
PdfDictionary actualDocumentFonts = PdfAcroForm.GetAcroForm(document, false).GetPdfObject().GetAsDictionary
(PdfName.DR).GetAsDictionary(PdfName.Font);
PdfObject actualFieldDAFont = document.GetCatalog().GetPdfObject().GetAsDictionary(PdfName.AcroForm).GetAsArray
(PdfName.Fields).GetAsDictionary(0).Get(PdfName.DA);
NUnit.Framework.Assert.AreEqual(new PdfName("Helvetica"), actualDocumentFonts.GetAsDictionary(new PdfName(
"F1")).Get(PdfName.BaseFont), "There is no Helvetica font within DR key");
NUnit.Framework.Assert.AreEqual(new PdfName("Courier"), actualDocumentFonts.GetAsDictionary(new PdfName("F2"
)).Get(PdfName.BaseFont), "There is no Courier font within DR key.");
NUnit.Framework.Assert.AreEqual(new PdfName("NotoSans"), actualDocumentFonts.GetAsDictionary(new PdfName("F3"
)).Get(PdfName.BaseFont), "There is no NotoSans font within DR key.");
NUnit.Framework.Assert.AreEqual(expectedAcroformDAFont, actualAcroFormDAFont, "There is no Helvetica(/F1) font within AcroForm DA key"
);
NUnit.Framework.Assert.AreEqual(expectedFieldsDAFont, actualFieldDAFont, "There is no NotoSans(/F3) font within Fields DA key"
);
document.Close();
ExtendedTSpdfTest.PrintOutputPdfNameAndDir(destinationFolder + filename);
}
}
}

View File

@@ -0,0 +1,109 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using TSpdf.Forms.Fields;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Utils;
using TSpdf.Test;
namespace TSpdf.Forms {
[NUnit.Framework.Category("IntegrationTest")]
public class PdfFormFieldsHierarchyTest : ExtendedTSpdfTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/forms/PdfFormFieldsHierarchyTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/forms/PdfFormFieldsHierarchyTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
[NUnit.Framework.Ignore("DEVSIX-7264: Investigate 3 failed forms tests from 7.3/develop on .NET")]
public virtual void FillingFormWithKidsTest() {
//TODO DEVSIX-6467 The parent's formField value is set to children
String srcPdf = sourceFolder + "formWithKids.pdf";
String cmpPdf = sourceFolder + "cmp_fillingFormWithKidsTest.pdf";
String outPdf = destinationFolder + "fillingFormWithKidsTest.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfReader(srcPdf), new PdfWriter(outPdf));
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(pdfDocument, false);
IDictionary<String, PdfFormField> formFields = acroForm.GetAllFormFields();
foreach (String key in formFields.Keys) {
PdfFormField field = acroForm.GetField(key);
field.SetValue(key);
}
pdfDocument.Close();
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(outPdf, cmpPdf, destinationFolder);
if (errorMessage != null) {
NUnit.Framework.Assert.Fail(errorMessage);
}
}
[NUnit.Framework.Test]
public virtual void AutosizeInheritedDAFormFieldsTest() {
String inPdf = destinationFolder + "autosizeInheritedDAFormFields.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfReader(sourceFolder + "autosizeInheritedDAFormFields.pdf"), new
PdfWriter(inPdf));
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
IDictionary<String, PdfFormField> fields = form.GetAllFormFields();
fields.Get("field_1").SetValue("1111 2222 3333 4444");
fields.Get("field_2").SetValue("1111 2222 3333 4444");
fields.Get("field_3").SetValue("surname surname surname surname surname surname");
pdfDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(inPdf, sourceFolder + "cmp_autosizeInheritedDAFormFields.pdf"
, inPdf, "diff_"));
}
[NUnit.Framework.Test]
public virtual void AutosizeInheritedDAFormFieldsWithKidsTest() {
String inPdf = destinationFolder + "autosizeInheritedDAFormFieldsWithKids.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfReader(sourceFolder + "autosizeInheritedDAFormFieldsWithKids.pdf"
), new PdfWriter(inPdf));
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
form.GetField("root.child.text1").SetValue("surname surname surname surname surname");
form.GetField("root.child.text2").SetValue("surname surname surname surname surname");
pdfDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(inPdf, sourceFolder + "cmp_autosizeInheritedDAFormFieldsWithKids.pdf"
, inPdf));
}
[NUnit.Framework.Test]
public virtual void AlignmentInheritanceInFieldsTest() {
String name = "alignmentInheritanceInFields";
String fileName = destinationFolder + name + ".pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfReader(sourceFolder + name + ".pdf"), new PdfWriter(fileName));
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
form.SetGenerateAppearance(false);
IDictionary<String, PdfFormField> fields = form.GetAllFormFields();
fields.Get("root").SetValue("Deutschland");
form.FlattenFields();
pdfDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(fileName, sourceFolder + "cmp_" + name +
".pdf", destinationFolder + name, "diff_"));
}
}
}

View File

@@ -0,0 +1,117 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.Collections.Generic;
using TSpdf.Forms.Fields;
using TSpdf.IO.Font;
using TSpdf.Kernel.Font;
using TSpdf.Kernel.Geom;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Utils;
using TSpdf.Test;
namespace TSpdf.Forms {
[NUnit.Framework.Category("UnitTest")]
public class Utf8FormsTest : ExtendedTSpdfTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/forms/Utf8FormsTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/forms/Utf8FormsTest/";
public static readonly String FONT = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/forms/Utf8FormsTest/NotoSansCJKsc-Regular.otf";
[NUnit.Framework.SetUp]
public virtual void Before() {
CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void ReadUtf8FieldName() {
String filename = sourceFolder + "utf-8-field-name.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfReader(filename));
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
IDictionary<String, PdfFormField> fields = form.GetAllFormFields();
pdfDoc.Close();
foreach (String fldName in fields.Keys) {
// لا
NUnit.Framework.Assert.AreEqual("\u0644\u0627", fldName);
}
pdfDoc.Close();
}
[NUnit.Framework.Test]
public virtual void ReadUtf8TextAnnot() {
String filename = sourceFolder + "utf-8-text-annot.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfReader(filename));
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
IDictionary<String, PdfFormField> fields = form.GetAllFormFields();
pdfDoc.Close();
foreach (String fldName in fields.Keys) {
// 福昕 福昕UTF8
NUnit.Framework.Assert.AreEqual("\u798F\u6615 \u798F\u6615UTF8", fields.Get(fldName).GetValueAsString());
}
}
[NUnit.Framework.Test]
public virtual void WriteUtf8FieldNameAndValue() {
//TODO DEVSIX-2798
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(destinationFolder + "writeUtf8FieldNameAndValue.pdf"));
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
PdfTextFormField field = new TextFormFieldBuilder(pdfDoc, "").SetWidgetRectangle(new Rectangle(99, 753, 425
, 15)).CreateText();
field.SetValue("");
field.SetFont(PdfFontFactory.CreateFont(FONT, PdfEncodings.IDENTITY_H));
// لا
field.Put(PdfName.T, new PdfString("\u0644\u0627", PdfEncodings.UTF8));
// 福昕 福昕UTF8
field.Put(PdfName.V, new PdfString("\u798F\u6615 \u798F\u6615UTF8", PdfEncodings.UTF8));
field.RegenerateField();
form.AddField(field);
pdfDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "writeUtf8FieldNameAndValue.pdf"
, sourceFolder + "cmp_writeUtf8FieldNameAndValue.pdf", destinationFolder, "diffFieldNameAndValue_"));
}
}
}

View File

@@ -0,0 +1,883 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.IO;
using TSpdf.Forms.Xfdf;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Utils;
using TSpdf.Test;
using TSpdf.Test.Attributes;
namespace TSpdf.Forms {
[NUnit.Framework.Category("IntegrationTest")]
public class XfdfReaderTest : ExtendedTSpdfTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/forms/XfdfReaderTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/forms/XfdfReaderTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfNoFields() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfNoFields.pdf",
FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfNoFields.pdf",
FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfNoFields.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfNoFields.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfNoFields.pdf", sourceFolder
+ "cmp_xfdfNoFields.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_NO_F_OBJECT_TO_COMPARE)]
public virtual void XfdfNoFieldsNoFAttributes() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfNoFieldsNoFAttributes.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfNoFieldsNoFAttributes.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfNoFieldsNoFAttributes.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfNoFieldsNoFAttributes.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfNoFieldsNoFAttributes.pdf"
, sourceFolder + "cmp_xfdfNoFieldsNoFAttributes.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfNoFieldsNoIdsAttributes() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfNoFieldsNoIdsAttributes.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfNoFieldsNoIdsAttributes.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfNoFieldsNoIdsAttributes.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfNoFieldsNoIdsAttributes.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfNoFieldsNoIdsAttributes.pdf"
, sourceFolder + "cmp_xfdfNoFieldsNoIdsAttributes.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfWithFieldsWithValue() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfWithFieldsWithValue.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfWithFieldsWithValue.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfWithFieldsWithValue.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfWithFieldsWithValue.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfWithFieldsWithValue.pdf"
, sourceFolder + "cmp_xfdfWithFieldsWithValue.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_NO_SUCH_FIELD_IN_PDF_DOCUMENT)]
public virtual void XfdfValueRichText() {
//TODO DEVSIX-3215 Support annots
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfValueRichText.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfValueRichText.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfValueRichText.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfValueRichText.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfValueRichText.pdf"
, sourceFolder + "cmp_xfdfValueRichText.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_NO_SUCH_FIELD_IN_PDF_DOCUMENT, Count = 3)]
public virtual void XfdfHierarchyFieldsTest() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "hierarchy_fields.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "hierarchy_fields.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "hierarchy_fields.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "hierarchy_fields.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "hierarchy_fields.pdf"
, sourceFolder + "cmp_hierarchy_fields.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_NO_SUCH_FIELD_IN_PDF_DOCUMENT, Count = 3)]
public virtual void XfdfWithFieldsWithValueParentAndChild() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfWithFieldsWithValueParentAndChild.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfWithFieldsWithValueParentAndChild.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfWithFieldsWithValueParentAndChild.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfWithFieldsWithValueParentAndChild.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfWithFieldsWithValueParentAndChild.pdf"
, sourceFolder + "cmp_xfdfWithFieldsWithValueParentAndChild.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_UNSUPPORTED_ANNOTATION_ATTRIBUTE)]
public virtual void XfdfAnnotationHighlightedText() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationHighlightedText.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationHighlightedText.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationHighlightedText.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, "xfdfAnnotationHighlightedText.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationHighlightedText.pdf"
, sourceFolder + "cmp_xfdfAnnotationHighlightedText.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfAnnotationUnderlineText() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationUnderlineText.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationUnderlineText.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationUnderlineText.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationUnderlineText.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationUnderlineText.pdf"
, sourceFolder + "cmp_xfdfAnnotationUnderlineText.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfAnnotationUnderlineTextRectWithTwoCoords() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationUnderlineTextRectWithTwoCoords.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationUnderlineTextRectWithTwoCoords.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationUnderlineTextRectWithTwoCoords.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationUnderlineTextRectWithTwoCoords.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationUnderlineTextRectWithTwoCoords.pdf"
, sourceFolder + "cmp_xfdfAnnotationUnderlineTextRectWithTwoCoords.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfAnnotationUnderlinePopupAllFlags() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationUnderlinePopupAllFlags.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationUnderlinePopupAllFlags.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationUnderlinePopupAllFlags.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationUnderlinePopupAllFlags.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationUnderlinePopupAllFlags.pdf"
, sourceFolder + "cmp_xfdfAnnotationUnderlinePopupAllFlags.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfAnnotationText() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationText.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationText.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationText.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationText.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationText.pdf"
, sourceFolder + "cmp_xfdfAnnotationText.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfAnnotationStrikeout() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationStrikeout.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationStrikeout.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationStrikeout.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationStrikeout.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationStrikeout.pdf"
, sourceFolder + "cmp_xfdfAnnotationStrikeout.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfAnnotationSquigglyText() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationSquigglyText.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationSquigglyText.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationSquigglyText.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationSquigglyText.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationSquigglyText.pdf"
, sourceFolder + "cmp_xfdfAnnotationSquigglyText.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_UNSUPPORTED_ANNOTATION_ATTRIBUTE, Count = 2)]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_ANNOTATION_IS_NOT_SUPPORTED)]
public virtual void XfdfAnnotationLine() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationLine.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationLine.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationLine.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationLine.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationLine.pdf"
, sourceFolder + "cmp_xfdfAnnotationLine.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfAnnotationCircle() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationCircle.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationCircle.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationCircle.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationCircle.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationCircle.pdf"
, sourceFolder + "cmp_xfdfAnnotationCircle.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfAnnotationSquare() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationSquare.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationSquare.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationSquare.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationSquare.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationSquare.pdf"
, sourceFolder + "cmp_xfdfAnnotationSquare.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfAnnotationCaret() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationCaret.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationCaret.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationCaret.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationCaret.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationCaret.pdf"
, sourceFolder + "cmp_xfdfAnnotationCaret.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfAnnotationPolygon() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationPolygon.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationPolygon.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationPolygon.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationPolygon.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationPolygon.pdf"
, sourceFolder + "cmp_xfdfAnnotationPolygon.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfAnnotationPolyline() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationPolyline.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationPolyline.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationPolyline.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationPolyline.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationPolyline.pdf"
, sourceFolder + "cmp_xfdfAnnotationPolyline.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfAnnotationStamp() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationStamp.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationStamp.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationStamp.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationStamp.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationStamp.pdf"
, sourceFolder + "cmp_xfdfAnnotationStamp.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfAnnotationInk() {
//TODO DEVSIX-3215 Support annots
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationInk.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationInk.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationInk.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationInk.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationInk.pdf"
, sourceFolder + "cmp_xfdfAnnotationInk.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfAnnotationFreeText() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationFreeText.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationFreeText.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationFreeText.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationFreeText.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationFreeText.pdf"
, sourceFolder + "cmp_xfdfAnnotationFreeText.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfAnnotationFileAttachment() {
//TODO DEVSIX-3215 Support annots
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationFileAttachment.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationFileAttachment.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationFileAttachment.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationFileAttachment.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationFileAttachment.pdf"
, sourceFolder + "cmp_xfdfAnnotationFileAttachment.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfAnnotationSound() {
//TODO DEVSIX-3215 Support annots
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationSound.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationSound.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationSound.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationSound.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationSound.pdf"
, sourceFolder + "cmp_xfdfAnnotationSound.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfAnnotationLink() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationLink.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationLink.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationLink.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationLink.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationLink.pdf"
, sourceFolder + "cmp_xfdfAnnotationLink.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfAnnotationRedact() {
//TODO DEVSIX-3215 Support annots
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationRedact.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationRedact.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationRedact.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationRedact.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationRedact.pdf"
, sourceFolder + "cmp_xfdfAnnotationRedact.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfAnnotationProjection() {
//TODO DEVSIX-3215 Support annots
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationProjection.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationProjection.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationProjection.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationProjection.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationProjection.pdf"
, sourceFolder + "cmp_xfdfAnnotationProjection.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfAnnotationLinkAllParams() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationLinkAllParams.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationLinkAllParams.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationLinkAllParams.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationLinkAllParams.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationLinkAllParams.pdf"
, sourceFolder + "cmp_xfdfAnnotationLinkAllParams.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_UNSUPPORTED_ANNOTATION_ATTRIBUTE)]
public virtual void XfdfAnnotationReplaceText() {
//TODO DEVSIX-3215 Support annots
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationReplaceText.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationReplaceText.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationReplaceText.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationReplaceText.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationReplaceText.pdf"
, sourceFolder + "cmp_xfdfAnnotationReplaceText.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_UNSUPPORTED_ANNOTATION_ATTRIBUTE, Count = 5)]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_ANNOTATION_IS_NOT_SUPPORTED)]
public virtual void XfdfAnnotationArrow() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationArrow.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationArrow.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationArrow.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationArrow.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationArrow.pdf"
, sourceFolder + "cmp_xfdfAnnotationArrow.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfAnnotationCallout() {
//TODO DEVSIX-3215 Support annots
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationCallout.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationCallout.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationCallout.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationCallout.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationCallout.pdf"
, sourceFolder + "cmp_xfdfAnnotationCallout.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_UNSUPPORTED_ANNOTATION_ATTRIBUTE, Count = 3)]
public virtual void XfdfAnnotationCloud() {
//TODO DEVSIX-3215 Support annots
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationCloud.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationCloud.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationCloud.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationCloud.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationCloud.pdf"
, sourceFolder + "cmp_xfdfAnnotationCloud.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_UNSUPPORTED_ANNOTATION_ATTRIBUTE, Count = 3)]
public virtual void XfdfAnnotationCloudNested() {
//TODO DEVSIX-3215 Support annots
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationCloudNested.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationCloudNested.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationCloudNested.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationCloudNested.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationCloudNested.pdf"
, sourceFolder + "cmp_xfdfAnnotationCloudNested.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfAnnotationTextBoxAllParams() {
//TODO DEVSIX-3215 Support annots
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationTextBoxAllParams.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationTextBoxAllParams.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationTextBoxAllParams.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationTextBoxAllParams.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationTextBoxAllParams.pdf"
, sourceFolder + "cmp_xfdfAnnotationTextBoxAllParams.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfJavaScriptForms() {
//TODO DEVSIX-3215 Support annots
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfJavaScriptForms.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfJavaScriptForms.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfJavaScriptForms.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfJavaScriptForms.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfJavaScriptForms.pdf"
, sourceFolder + "cmp_xfdfJavaScriptForms.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfFormsFieldParams() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfFormsFieldParams.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfFormsFieldParams.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfFormsFieldParams.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfFormsFieldParams.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfFormsFieldParams.pdf"
, sourceFolder + "cmp_xfdfFormsFieldParams.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfAnnotationAttrColor() {
//TODO DEVSIX-3215 Support annots
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationAttrColor.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationAttrColor.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationAttrColor.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationAttrColor.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationAttrColor.pdf"
, sourceFolder + "cmp_xfdfAnnotationAttrColor.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfAnnotationAttrFlagsOpacity() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationAttrFlagsOpacity.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationAttrFlagsOpacity.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationAttrFlagsOpacity.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationAttrFlagsOpacity.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationAttrFlagsOpacity.pdf"
, sourceFolder + "cmp_xfdfAnnotationAttrFlagsOpacity.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_UNSUPPORTED_ANNOTATION_ATTRIBUTE, Count = 4)]
public virtual void XfdfAnnotationAttrTitle() {
//TODO DEVSIX-3215 Support annots
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAnnotationAttrTitle.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfAnnotationAttrTitle.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfAnnotationAttrTitle.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfAnnotationAttrTitle.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfAnnotationAttrTitle.pdf"
, sourceFolder + "cmp_xfdfAnnotationAttrTitle.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfReferenceFor3DMeasurement() {
//TODO DEVSIX-3215 Support annots
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfReferenceFor3DMeasurement.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfReferenceFor3DMeasurement.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfReferenceFor3DMeasurement.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfReferenceFor3DMeasurement.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfReferenceFor3DMeasurement.pdf"
, sourceFolder + "cmp_xfdfReferenceFor3DMeasurement.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfReferenceFor3DAngular() {
//TODO DEVSIX-3215 Support annots
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfReferenceFor3DAngular.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfReferenceFor3DAngular.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfReferenceFor3DAngular.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfReferenceFor3DAngular.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfReferenceFor3DAngular.pdf"
, sourceFolder + "cmp_xfdfReferenceFor3DAngular.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfReferenceFor3DRadial() {
//TODO DEVSIX-3215 Support annots
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfReferenceFor3DRadial.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfReferenceFor3DRadial.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfReferenceFor3DRadial.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfReferenceFor3DRadial.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfReferenceFor3DRadial.pdf"
, sourceFolder + "cmp_xfdfReferenceFor3DRadial.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfSubelementContents() {
//TODO DEVSIX-3215
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfSubelementContents.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfSubelementContents.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfSubelementContents.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfSubelementContents.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfSubelementContents.pdf"
, sourceFolder + "cmp_xfdfSubelementContents.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfSubelementOverlayAppearance() {
//TODO DEVSIX-3215 Support annots
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfSubelementOverlayAppearance.pdf"
, FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfSubelementOverlayAppearance.pdf"
, FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfSubelementOverlayAppearance.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfSubelementOverlayAppearance.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfSubelementOverlayAppearance.pdf"
, sourceFolder + "cmp_xfdfSubelementOverlayAppearance.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfButton() {
//TODO DEVSIX-3215
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfButton.pdf", FileMode.Open
, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfButton.pdf", FileMode.Create
)));
String xfdfFilename = sourceFolder + "xfdfButton.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfButton.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfButton.pdf", sourceFolder
+ "cmp_xfdfButton.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfCheckBox() {
//TODO DEVSIX-3215
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfCheckBox.pdf",
FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfCheckBox.pdf",
FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfCheckBox.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfCheckBox.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfCheckBox.pdf", sourceFolder
+ "cmp_xfdfCheckBox.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfList() {
//TODO DEVSIX-3215
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfList.pdf", FileMode.Open
, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfList.pdf", FileMode.Create)
));
String xfdfFilename = sourceFolder + "xfdfList.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfList.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfList.pdf", sourceFolder
+ "cmp_xfdfList.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT)]
public virtual void XfdfDropDown() {
//TODO DEVSIX-3215 Support richtext
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfDropDown.pdf",
FileMode.Open, FileAccess.Read)), new PdfWriter(new FileStream(destinationFolder + "xfdfDropDown.pdf",
FileMode.Create)));
String xfdfFilename = sourceFolder + "xfdfDropDown.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(new FileStream(xfdfFilename, FileMode.Open, FileAccess.Read
));
xfdfObject.MergeToPdf(pdfDocument, sourceFolder + "xfdfDropDown.pdf");
pdfDocument.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "xfdfDropDown.pdf", sourceFolder
+ "cmp_xfdfDropDown.pdf", destinationFolder, "diff_"));
}
}
}

View File

@@ -0,0 +1,37 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using TSpdf.Forms.Exceptions;
using TSpdf.Forms.Xfdf;
using TSpdf.Test;
namespace TSpdf.Forms {
[NUnit.Framework.Category("UnitTest")]
public class XfdfUnitTest : ExtendedTSpdfTest {
[NUnit.Framework.Test]
public virtual void FitObjectWithEmptyPageTest() {
Exception e = NUnit.Framework.Assert.Catch(typeof(XfdfException), () => new FitObject(null));
NUnit.Framework.Assert.AreEqual(XfdfException.PAGE_IS_MISSING, e.Message);
}
}
}

View File

@@ -0,0 +1,978 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.IO;
using TSpdf.Forms.Exceptions;
using TSpdf.Forms.Xfdf;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Utils;
using TSpdf.Test;
namespace TSpdf.Forms {
[NUnit.Framework.Category("IntegrationTest")]
public class XfdfWriterTest : ExtendedTSpdfTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/forms/XfdfWriterTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/forms/XfdfWriterTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void SimpleFormWithOneFieldTest() {
String pdfDocumentName = "simpleFormWithOneField.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + pdfDocumentName, FileMode.Open
, FileAccess.Read)));
String xfdfFilename = destinationFolder + "simpleFormWithOneField.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "simpleFormWithOneField.xfdf", sourceFolder + "cmp_simpleFormWithOneField.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
[NUnit.Framework.Ignore("DEVSIX-7264: Investigate 3 failed forms tests from 7.3/develop on .NET")]
public virtual void SimpleFormWithMultipleFieldsTest() {
String pdfDocumentName = "simpleFormWithMultipleFields.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfReader(new FileStream(sourceFolder + pdfDocumentName, FileMode.Open
, FileAccess.Read)));
String xfdfFilename = destinationFolder + "simpleFormWithMultipleFields.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDoc, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDoc.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "simpleFormWithMultipleFields.xfdf", sourceFolder +
"cmp_simpleFormWithMultipleFields.xfdf")) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfValueRichText() {
//TODO DEVSIX-3215
String pdfDocumentName = "xfdfValueRichText.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfReader(new FileStream(sourceFolder + pdfDocumentName, FileMode.Open
, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfValueRichText.xfdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDoc, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDoc.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfValueRichText.xfdf", sourceFolder + "cmp_xfdfValueRichText.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfHierarchyFields() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfHierarchyFields.pdf"
, FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfHierarchyFields.xfdf";
String pdfDocumentName = "xfdfHierarchyFields.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfHierarchyFields.xfdf", sourceFolder + "cmp_xfdfHierarchyFields.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfFreeText() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfFreeText.pdf",
FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfFreeText.xfdf";
String pdfDocumentName = "xfdfFreeText.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfFreeText.xfdf", sourceFolder + "cmp_xfdfFreeText.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfHighlightedText() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfHighlightedText.pdf"
, FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfHighlightedText.xfdf";
String pdfDocumentName = "xfdfHighlightedText.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfHighlightedText.xfdf", sourceFolder + "cmp_xfdfHighlightedText.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfUnderlineText() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfUnderlineText.pdf"
, FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfUnderlineText.xfdf";
String pdfDocumentName = "xfdfUnderlineText.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfUnderlineText.xfdf", sourceFolder + "cmp_xfdfUnderlineText.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfPopupNewFlags() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfPopupNewFlags.pdf"
, FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfPopupNewFlags.xfdf";
String pdfDocumentName = "xfdfPopupNewFlags.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfPopupNewFlags.xfdf", sourceFolder + "cmp_xfdfPopupNewFlags.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfStrikeout() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfStrikeout.pdf",
FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfStrikeout.xfdf";
String pdfDocumentName = "xfdfStrikeout.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfStrikeout.xfdf", sourceFolder + "cmp_xfdfStrikeout.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfSquigglyText() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfSquigglyText.pdf"
, FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfSquigglyText.xfdf";
String pdfDocumentName = "xfdfSquigglyText.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfSquigglyText.xfdf", sourceFolder + "cmp_xfdfSquigglyText.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfLine() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfLine.pdf", FileMode.Open
, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfLine.xfdf";
String pdfDocumentName = "xfdfLine.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfLine.xfdf", sourceFolder + "cmp_xfdfLine.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfCircle() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfCircle.pdf", FileMode.Open
, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfCircle.xfdf";
String pdfDocumentName = "xfdfCircle.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfCircle.xfdf", sourceFolder + "cmp_xfdfCircle.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfSquare() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfSquare.pdf", FileMode.Open
, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfSquare.xfdf";
String pdfDocumentName = "xfdfSquare.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfSquare.xfdf", sourceFolder + "cmp_xfdfSquare.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfSquareAndCircleInteriorColor() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfSquareAndCircleInteriorColor.pdf"
, FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfSquareAndCircleInteriorColor.xfdf";
String pdfDocumentName = "xfdfSquareAndCircleInteriorColor.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfSquareAndCircleInteriorColor.xfdf", sourceFolder
+ "cmp_xfdfSquareAndCircleInteriorColor.xfdf")) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfCaret() {
//TODO DEVSIX-3215
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfCaret.pdf", FileMode.Open
, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfCaret.xfdf";
String pdfDocumentName = "xfdfCaret.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfCaret.xfdf", sourceFolder + "cmp_xfdfCaret.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfPolygon() {
//TODO DEVSIX-3215 Support annots
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfPolygon.pdf", FileMode.Open
, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfPolygon.xfdf";
String pdfDocumentName = "xfdfPolygon.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfPolygon.xfdf", sourceFolder + "cmp_xfdfPolygon.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfPolyline() {
//TODO DEVSIX-3215 Support annots
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfPolyline.pdf",
FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfPolyline.xfdf";
String pdfDocumentName = "xfdfPolyline.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfPolyline.xfdf", sourceFolder + "cmp_xfdfPolyline.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfStamp() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfStamp.pdf", FileMode.Open
, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfStamp.xfdf";
String pdfDocumentName = "xfdfStamp.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfStamp.xfdf", sourceFolder + "cmp_xfdfStamp.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfStampWithAppearance() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfStampWithAppearance.pdf"
, FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfStampWithAppearance.xfdf";
String pdfDocumentName = "xfdfStampWithAppearance.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfStampWithAppearance.xfdf", sourceFolder + "cmp_xfdfStampWithAppearance.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfInk() {
//TODO DEVSIX-3215 Support annots
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfInk.pdf", FileMode.Open
, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfInk.xfdf";
String pdfDocumentName = "xfdfInk.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfInk.xfdf", sourceFolder + "cmp_xfdfInk.xfdf")) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfFileAttachment() {
//TODO DEVSIX-3215
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfFileAttachment.pdf"
, FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfFileAttachment.xfdf";
String pdfDocumentName = "xfdfFileAttachment.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfFileAttachment.xfdf", sourceFolder + "cmp_xfdfFileAttachment.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfSound() {
//TODO DEVSIX-3215
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfSound.pdf", FileMode.Open
, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfSound.xfdf";
String pdfDocumentName = "xfdfSound.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfSound.xfdf", sourceFolder + "cmp_xfdfSound.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfLink() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfLink.pdf", FileMode.Open
, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfLink.xfdf";
String pdfDocumentName = "xfdfLink.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfLink.xfdf", sourceFolder + "cmp_xfdfLink.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfLinkBorderStyle() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfLinkBorderStyle.pdf"
, FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfLinkBorderStyle.xfdf";
String pdfDocumentName = "xfdfLinkBorderStyle.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfLinkBorderStyle.xfdf", sourceFolder + "cmp_xfdfLinkBorderStyle.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfLinkDest() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfLinkDest.pdf",
FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfLinkDest.xfdf";
String pdfDocumentName = "xfdfLinkDest.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfLinkDest.xfdf", sourceFolder + "cmp_xfdfLinkDest.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfLinkDestFit() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfLinkDestFit.pdf"
, FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfLinkDestFit.xfdf";
String pdfDocumentName = "xfdfLinkDestFit.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfLinkDestFit.xfdf", sourceFolder + "cmp_xfdfLinkDestFit.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfLinkDestFitB() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfLinkDestFitB.pdf"
, FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfLinkDestFitB.xfdf";
String pdfDocumentName = "xfdfLinkDestFitB.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfLinkDestFitB.xfdf", sourceFolder + "cmp_xfdfLinkDestFitB.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfLinkDestFitR() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfLinkDestFitR.pdf"
, FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfLinkDestFitR.xfdf";
String pdfDocumentName = "xfdfLinkDestFitR.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfLinkDestFitR.xfdf", sourceFolder + "cmp_xfdfLinkDestFitR.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfLinkDestFitH() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfLinkDestFitH.pdf"
, FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfLinkDestFitH.xfdf";
String pdfDocumentName = "xfdfLinkDestFitH.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfLinkDestFitH.xfdf", sourceFolder + "cmp_xfdfLinkDestFitH.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfLinkDestFitBH() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfLinkDestFitBH.pdf"
, FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfLinkDestFitBH.xfdf";
String pdfDocumentName = "xfdfLinkDestFitBH.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfLinkDestFitBH.xfdf", sourceFolder + "cmp_xfdfLinkDestFitBH.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfLinkDestFitBV() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfLinkDestFitBV.pdf"
, FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfLinkDestFitBV.xfdf";
String pdfDocumentName = "xfdfLinkDestFitBV.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfLinkDestFitBV.xfdf", sourceFolder + "cmp_xfdfLinkDestFitBV.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfLinkDestFitV() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfLinkDestFitV.pdf"
, FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfLinkDestFitV.xfdf";
String pdfDocumentName = "xfdfLinkDestFitV.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfLinkDestFitV.xfdf", sourceFolder + "cmp_xfdfLinkDestFitV.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfRedact() {
//TODO DEVSIX-3215
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfRedact.pdf", FileMode.Open
, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfRedact.xfdf";
String pdfDocumentName = "xfdfRedact.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfRedact.xfdf", sourceFolder + "cmp_xfdfRedact.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfProjection() {
//TODO DEVSIX-3215
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfProjection.pdf"
, FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfProjection.xfdf";
String pdfDocumentName = "xfdfProjection.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfProjection.xfdf", sourceFolder + "cmp_xfdfProjection.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfLinkAllParams() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfLinkAllParams.pdf"
, FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfLinkAllParams.xfdf";
String pdfDocumentName = "xfdfLinkAllParams.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfLinkAllParams.xfdf", sourceFolder + "cmp_xfdfLinkAllParams.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfReplaceText() {
//TODO DEVSIX-3215 Support caret annontation
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfReplaceText.pdf"
, FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfReplaceText.xfdf";
String pdfDocumentName = "xfdfReplaceText.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfReplaceText.xfdf", sourceFolder + "cmp_xfdfReplaceText.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfArrow() {
//TODO DEVSIX-3215
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfArrow.pdf", FileMode.Open
, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfArrow.xfdf";
String pdfDocumentName = "xfdfArrow.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfArrow.xfdf", sourceFolder + "cmp_xfdfArrow.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfCallout() {
//TODO DEVSIX-3215
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfCallout.pdf", FileMode.Open
, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfCallout.xfdf";
String pdfDocumentName = "xfdfCallout.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfCallout.xfdf", sourceFolder + "cmp_xfdfCallout.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfCloud() {
//TODO DEVSIX-3215 Support annots
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfCloud.pdf", FileMode.Open
, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfCloud.xfdf";
String pdfDocumentName = "xfdfCloud.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfCloud.xfdf", sourceFolder + "cmp_xfdfCloud.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfCloudNested() {
//TODO DEVSIX-3215 Support annots
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfCloudNested.pdf"
, FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfCloudNested.xfdf";
String pdfDocumentName = "xfdfCloudNested.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfCloudNested.xfdf", sourceFolder + "cmp_xfdfCloudNested.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfTextBoxAllParams() {
//TODO DEVSIX-3215 Support richtext
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfTextBoxAllParams.pdf"
, FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfTextBoxAllParams.xfdf";
String pdfDocumentName = "xfdfTextBoxAllParams.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfTextBoxAllParams.xfdf", sourceFolder + "cmp_xfdfTextBoxAllParams.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfJavaScriptForms() {
//TODO DEVSIX-3215
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfJavaScriptForms.pdf"
, FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfJavaScriptForms.xfdf";
String pdfDocumentName = "xfdfJavaScriptForms.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfJavaScriptForms.xfdf", sourceFolder + "cmp_xfdfJavaScriptForms.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfAttrColor() {
//TODO DEVSIX-3215
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAttrColor.pdf",
FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfAttrColor.xfdf";
String pdfDocumentName = "xfdfAttrColor.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfAttrColor.xfdf", sourceFolder + "cmp_xfdfAttrColor.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfAttrFlagsOpacity() {
//TODO DEVSIX-3215
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAttrFlagsOpacity.pdf"
, FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfAttrFlagsOpacity.xfdf";
String pdfDocumentName = "xfdfAttrFlagsOpacity.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfAttrFlagsOpacity.xfdf", sourceFolder + "cmp_xfdfAttrFlagsOpacity.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfAttrTitle() {
//TODO DEVSIX-3215
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfAttrTitle.pdf",
FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfAttrTitle.xfdf";
String pdfDocumentName = "xfdfAttrTitle.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfAttrTitle.xfdf", sourceFolder + "cmp_xfdfAttrTitle.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfReferenceFor3DMeasurement() {
//TODO DEVSIX-3215
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfReferenceFor3DMeasurement.pdf"
, FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfReferenceFor3DMeasurement.xfdf";
String pdfDocumentName = "xfdfReferenceFor3DMeasurement.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfReferenceFor3DMeasurement.xfdf", sourceFolder
+ "cmp_xfdfReferenceFor3DMeasurement.xfdf")) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfReferenceFor3DAngular() {
//TODO DEVSIX-3215
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfReferenceFor3DAngular.pdf"
, FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfReferenceFor3DAngular.xfdf";
String pdfDocumentName = "xfdfReferenceFor3DAngular.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfReferenceFor3DAngular.xfdf", sourceFolder + "cmp_xfdfReferenceFor3DAngular.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfReferenceFor3DRadial() {
//TODO DEVSIX-3215
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfReferenceFor3DRadial.pdf"
, FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfReferenceFor3DRadial.xfdf";
String pdfDocumentName = "xfdfReferenceFor3DRadial.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfReferenceFor3DRadial.xfdf", sourceFolder + "cmp_xfdfReferenceFor3DRadial.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfSubelementContents() {
//TODO DEVSIX-3215
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfSubelementContents.pdf"
, FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfSubelementContents.xfdf";
String pdfDocumentName = "xfdfSubelementContents.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfSubelementContents.xfdf", sourceFolder + "cmp_xfdfSubelementContents.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfSubelementOverlayAppearance() {
//check when Redact annotation is implemented
//TODO DEVSIX-3215
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfSubelementOverlayAppearance.pdf"
, FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfSubelementOverlayAppearance.xfdf";
String pdfDocumentName = "xfdfSubelementOverlayAppearance.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfSubelementOverlayAppearance.xfdf", sourceFolder
+ "cmp_xfdfSubelementOverlayAppearance.xfdf")) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfButton() {
//Widget annotation is not supported in xfdf 2014 spec version
//TODO DEVSIX-3215
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfButton.pdf", FileMode.Open
, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfButton.xfdf";
String pdfDocumentName = "xfdfButton.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfButton.xfdf", sourceFolder + "cmp_xfdfButton.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfCheckBox() {
//Widget annotation is not supported in xfdf 2014 spec version
//TODO DEVSIX-3215
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfCheckBox.pdf",
FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfCheckBox.xfdf";
String pdfDocumentName = "xfdfCheckBox.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfCheckBox.xfdf", sourceFolder + "cmp_xfdfCheckBox.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfList() {
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfList.pdf", FileMode.Open
, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfList.xfdf";
String pdfDocumentName = "xfdfList.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfList.xfdf", sourceFolder + "cmp_xfdfList.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfDropDown() {
//Widget annotation is not supported in 2014 spec version
//TODO DEVSIX-3215
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new FileStream(sourceFolder + "xfdfDropDown.pdf",
FileMode.Open, FileAccess.Read)));
String xfdfFilename = destinationFolder + "xfdfDropDown.xfdf";
String pdfDocumentName = "xfdfDropDown.pdf";
XfdfObjectFactory factory = new XfdfObjectFactory();
XfdfObject xfdfObject = factory.CreateXfdfObject(pdfDocument, pdfDocumentName);
xfdfObject.WriteToFile(xfdfFilename);
pdfDocument.Close();
if (!new CompareTool().CompareXmls(destinationFolder + "xfdfDropDown.xfdf", sourceFolder + "cmp_xfdfDropDown.xfdf"
)) {
NUnit.Framework.Assert.Fail("Xfdf files are not equal");
}
}
[NUnit.Framework.Test]
public virtual void XfdfEmptyAttributeTest() {
XfdfObject xfdfObject = new XfdfObject();
AnnotsObject annots = new AnnotsObject();
xfdfObject.SetAnnots(annots);
AnnotObject annot = new AnnotObject();
annots.AddAnnot(annot);
String namePresent = "name1";
String nameAbsent = null;
String valuePresent = "value";
String valueAbsent = null;
Exception e = NUnit.Framework.Assert.Catch(typeof(XfdfException), () => annot.AddAttribute(new AttributeObject
(nameAbsent, valuePresent)));
NUnit.Framework.Assert.AreEqual(XfdfException.ATTRIBUTE_NAME_OR_VALUE_MISSING, e.Message);
Exception e2 = NUnit.Framework.Assert.Catch(typeof(XfdfException), () => annot.AddAttribute(new AttributeObject
(namePresent, valueAbsent)));
NUnit.Framework.Assert.AreEqual(XfdfException.ATTRIBUTE_NAME_OR_VALUE_MISSING, e2.Message);
}
}
}

View File

@@ -0,0 +1,105 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.IO;
using TSpdf.Kernel.Geom;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Pdf.Annot;
using TSpdf.Kernel.Utils;
using TSpdf.Test;
namespace TSpdf.Forms.Fields {
[NUnit.Framework.Category("UnitTest")]
public class CheckBoxFormFieldBuilderTest : ExtendedTSpdfTest {
private static readonly PdfDocument DUMMY_DOCUMENT = new PdfDocument(new PdfWriter(new MemoryStream()));
private const String DUMMY_NAME = "dummy name";
private static readonly Rectangle DUMMY_RECTANGLE = new Rectangle(7, 11, 13, 17);
[NUnit.Framework.Test]
public virtual void ConstructorTest() {
CheckBoxFormFieldBuilder builder = new CheckBoxFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME);
NUnit.Framework.Assert.AreSame(DUMMY_DOCUMENT, builder.GetDocument());
NUnit.Framework.Assert.AreSame(DUMMY_NAME, builder.GetFormFieldName());
}
[NUnit.Framework.Test]
public virtual void SetGetCheckType() {
CheckBoxFormFieldBuilder builder = new CheckBoxFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME);
builder.SetCheckType(55);
NUnit.Framework.Assert.AreEqual(55, builder.GetCheckType());
}
[NUnit.Framework.Test]
public virtual void CreateCheckBoxWithWidgetTest() {
PdfButtonFormField checkBoxFormField = new CheckBoxFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).SetWidgetRectangle
(DUMMY_RECTANGLE).CreateCheckBox();
CompareCheckBoxes(checkBoxFormField, true);
}
[NUnit.Framework.Test]
public virtual void CreateCheckBoxWithoutWidgetTest() {
PdfButtonFormField checkBoxFormField = new CheckBoxFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).CreateCheckBox
();
CompareCheckBoxes(checkBoxFormField, false);
}
[NUnit.Framework.Test]
public virtual void CreateCheckBoxWithConformanceLevelTest() {
PdfButtonFormField checkBoxFormField = new CheckBoxFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).SetWidgetRectangle
(DUMMY_RECTANGLE).SetConformanceLevel(PdfAConformanceLevel.PDF_A_1A).CreateCheckBox();
CompareCheckBoxes(checkBoxFormField, true);
}
private static void CompareCheckBoxes(PdfButtonFormField checkBoxFormField, bool widgetExpected) {
PdfDictionary expectedDictionary = new PdfDictionary();
IList<PdfWidgetAnnotation> widgets = checkBoxFormField.GetWidgets();
if (widgetExpected) {
NUnit.Framework.Assert.AreEqual(1, widgets.Count);
PdfWidgetAnnotation annotation = widgets[0];
NUnit.Framework.Assert.IsTrue(DUMMY_RECTANGLE.EqualsWithEpsilon(annotation.GetRectangle().ToRectangle()));
PdfArray kids = new PdfArray();
kids.Add(annotation.GetPdfObject());
PutIfAbsent(expectedDictionary, PdfName.Kids, kids);
}
else {
NUnit.Framework.Assert.AreEqual(0, widgets.Count);
}
PutIfAbsent(expectedDictionary, PdfName.FT, PdfName.Btn);
PutIfAbsent(expectedDictionary, PdfName.T, new PdfString(DUMMY_NAME));
PutIfAbsent(expectedDictionary, PdfName.V, new PdfName(PdfFormAnnotation.OFF_STATE_VALUE));
expectedDictionary.MakeIndirect(DUMMY_DOCUMENT);
checkBoxFormField.MakeIndirect(DUMMY_DOCUMENT);
NUnit.Framework.Assert.IsNull(new CompareTool().CompareDictionariesStructure(expectedDictionary, checkBoxFormField
.GetPdfObject()));
}
private static void PutIfAbsent(PdfDictionary dictionary, PdfName name, PdfObject value) {
if (!dictionary.ContainsKey(name)) {
dictionary.Put(name, value);
}
}
}
}

View File

@@ -0,0 +1,209 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.IO;
using TSpdf.Commons.Utils;
using TSpdf.Forms.Exceptions;
using TSpdf.IO.Font;
using TSpdf.Kernel.Geom;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Pdf.Annot;
using TSpdf.Kernel.Utils;
using TSpdf.Test;
namespace TSpdf.Forms.Fields {
[NUnit.Framework.Category("UnitTest")]
public class ChoiceFormFieldBuilderTest : ExtendedTSpdfTest {
private static readonly PdfDocument DUMMY_DOCUMENT = new PdfDocument(new PdfWriter(new MemoryStream()));
private const String DUMMY_NAME = "dummy name";
private static readonly Rectangle DUMMY_RECTANGLE = new Rectangle(7, 11, 13, 17);
private static readonly PdfArray DUMMY_OPTIONS = new PdfArray(JavaUtil.ArraysAsList("option1", "option2",
"option3"), false);
[NUnit.Framework.Test]
public virtual void ConstructorTest() {
ChoiceFormFieldBuilder builder = new ChoiceFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME);
NUnit.Framework.Assert.AreSame(DUMMY_DOCUMENT, builder.GetDocument());
NUnit.Framework.Assert.AreSame(DUMMY_NAME, builder.GetFormFieldName());
}
[NUnit.Framework.Test]
public virtual void SetGetOptionsAsPdfArrayTest() {
ChoiceFormFieldBuilder builder = new ChoiceFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME);
builder.SetOptions(DUMMY_OPTIONS);
NUnit.Framework.Assert.AreSame(DUMMY_OPTIONS, builder.GetOptions());
}
[NUnit.Framework.Test]
public virtual void SetGetOptionsAsStringArrayTest() {
ChoiceFormFieldBuilder builder = new ChoiceFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME);
String[] options = new String[] { "option1", "option2", "option3" };
builder.SetOptions(options);
for (int i = 0; i < options.Length; ++i) {
NUnit.Framework.Assert.AreEqual(new PdfString(options[i], PdfEncodings.UNICODE_BIG), builder.GetOptions().
GetAsString(i));
}
}
[NUnit.Framework.Test]
public virtual void SetGetOptionsAsTwoDimensionalStringArrayTest() {
ChoiceFormFieldBuilder builder = new ChoiceFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME);
String[][] options = new String[][] { new String[] { "option1", "option2" }, new String[] { "option3", "option4"
} };
builder.SetOptions(options);
for (int i = 0; i < options.Length; ++i) {
for (int j = 0; j < options[i].Length; ++j) {
NUnit.Framework.Assert.AreEqual(new PdfString(options[i][j], PdfEncodings.UNICODE_BIG), builder.GetOptions
().GetAsArray(i).GetAsString(j));
}
}
}
[NUnit.Framework.Test]
public virtual void SetGetOptionsAsIllegalTwoDimensionalStringArrayTest() {
ChoiceFormFieldBuilder builder = new ChoiceFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME);
String[][] options = new String[][] { new String[] { "option1", "option2", "option3" } };
Exception exception = NUnit.Framework.Assert.Catch(typeof(ArgumentException), () => builder.SetOptions(options
));
NUnit.Framework.Assert.AreEqual(FormsExceptionMessageConstant.INNER_ARRAY_SHALL_HAVE_TWO_ELEMENTS, exception
.Message);
}
[NUnit.Framework.Test]
public virtual void CreateComboBoxWithWidgetTest() {
PdfChoiceFormField choiceFormField = new ChoiceFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).SetWidgetRectangle
(DUMMY_RECTANGLE).CreateComboBox();
CompareChoices(new PdfDictionary(), choiceFormField, true);
}
[NUnit.Framework.Test]
public virtual void CreateComboBoxWithoutWidgetTest() {
PdfChoiceFormField choiceFormField = new ChoiceFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).CreateComboBox
();
CompareChoices(new PdfDictionary(), choiceFormField, false);
}
[NUnit.Framework.Test]
public virtual void CreateComboBoxWithConformanceLevelTest() {
PdfChoiceFormField choiceFormField = new ChoiceFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).SetWidgetRectangle
(DUMMY_RECTANGLE).SetConformanceLevel(PdfAConformanceLevel.PDF_A_1A).CreateComboBox();
CompareChoices(new PdfDictionary(), choiceFormField, true);
}
[NUnit.Framework.Test]
public virtual void CreateComboBoxWithOptionsTest() {
PdfChoiceFormField choiceFormField = new ChoiceFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).SetWidgetRectangle
(DUMMY_RECTANGLE).SetOptions(DUMMY_OPTIONS).CreateComboBox();
PdfDictionary expectedDictionary = new PdfDictionary();
expectedDictionary.Put(PdfName.Opt, DUMMY_OPTIONS);
CompareChoices(expectedDictionary, choiceFormField, true);
}
[NUnit.Framework.Test]
public virtual void CreateComboBoxWithoutOptionsTest() {
PdfChoiceFormField choiceFormField = new ChoiceFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).SetWidgetRectangle
(DUMMY_RECTANGLE).CreateComboBox();
CompareChoices(new PdfDictionary(), choiceFormField, true);
}
[NUnit.Framework.Test]
public virtual void CreateListWithWidgetTest() {
PdfChoiceFormField choiceFormField = new ChoiceFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).SetWidgetRectangle
(DUMMY_RECTANGLE).CreateList();
PdfDictionary expectedDictionary = new PdfDictionary();
expectedDictionary.Put(PdfName.Ff, new PdfNumber(0));
CompareChoices(expectedDictionary, choiceFormField, true);
}
[NUnit.Framework.Test]
public virtual void CreateListWithoutWidgetTest() {
PdfChoiceFormField choiceFormField = new ChoiceFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).CreateList();
PdfDictionary expectedDictionary = new PdfDictionary();
expectedDictionary.Put(PdfName.Ff, new PdfNumber(0));
CompareChoices(expectedDictionary, choiceFormField, false);
}
[NUnit.Framework.Test]
public virtual void CreateListWithConformanceLevelTest() {
PdfChoiceFormField choiceFormField = new ChoiceFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).SetWidgetRectangle
(DUMMY_RECTANGLE).SetConformanceLevel(PdfAConformanceLevel.PDF_A_1A).CreateList();
PdfDictionary expectedDictionary = new PdfDictionary();
expectedDictionary.Put(PdfName.Ff, new PdfNumber(0));
CompareChoices(expectedDictionary, choiceFormField, true);
}
[NUnit.Framework.Test]
public virtual void CreateListWithOptionsTest() {
PdfChoiceFormField choiceFormField = new ChoiceFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).SetWidgetRectangle
(DUMMY_RECTANGLE).SetOptions(DUMMY_OPTIONS).CreateList();
PdfDictionary expectedDictionary = new PdfDictionary();
expectedDictionary.Put(PdfName.Ff, new PdfNumber(0));
expectedDictionary.Put(PdfName.Opt, DUMMY_OPTIONS);
CompareChoices(expectedDictionary, choiceFormField, true);
}
[NUnit.Framework.Test]
public virtual void CreateListWithoutOptionsTest() {
PdfChoiceFormField choiceFormField = new ChoiceFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).SetWidgetRectangle
(DUMMY_RECTANGLE).CreateList();
PdfDictionary expectedDictionary = new PdfDictionary();
expectedDictionary.Put(PdfName.Ff, new PdfNumber(0));
CompareChoices(expectedDictionary, choiceFormField, true);
}
private static void CompareChoices(PdfDictionary expectedDictionary, PdfChoiceFormField choiceFormField, bool
widgetExpected) {
IList<PdfWidgetAnnotation> widgets = choiceFormField.GetWidgets();
if (widgetExpected) {
NUnit.Framework.Assert.AreEqual(1, widgets.Count);
PdfWidgetAnnotation annotation = widgets[0];
NUnit.Framework.Assert.IsTrue(DUMMY_RECTANGLE.EqualsWithEpsilon(annotation.GetRectangle().ToRectangle()));
PdfArray kids = new PdfArray();
kids.Add(annotation.GetPdfObject());
PutIfAbsent(expectedDictionary, PdfName.Kids, kids);
}
else {
NUnit.Framework.Assert.AreEqual(0, widgets.Count);
}
PutIfAbsent(expectedDictionary, PdfName.FT, PdfName.Ch);
PutIfAbsent(expectedDictionary, PdfName.Ff, new PdfNumber(PdfChoiceFormField.FF_COMBO));
PutIfAbsent(expectedDictionary, PdfName.Opt, new PdfArray());
PutIfAbsent(expectedDictionary, PdfName.T, new PdfString(DUMMY_NAME));
PutIfAbsent(expectedDictionary, PdfName.V, new PdfArray());
expectedDictionary.MakeIndirect(DUMMY_DOCUMENT);
choiceFormField.MakeIndirect(DUMMY_DOCUMENT);
NUnit.Framework.Assert.IsNull(new CompareTool().CompareDictionariesStructure(expectedDictionary, choiceFormField
.GetPdfObject()));
}
private static void PutIfAbsent(PdfDictionary dictionary, PdfName name, PdfObject value) {
if (!dictionary.ContainsKey(name)) {
dictionary.Put(name, value);
}
}
}
}

View File

@@ -0,0 +1,61 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using System.IO;
using TSpdf.Kernel.Pdf;
using TSpdf.Test;
namespace TSpdf.Forms.Fields {
[NUnit.Framework.Category("UnitTest")]
public class FormFieldBuilderTest : ExtendedTSpdfTest {
private static readonly PdfDocument DUMMY_DOCUMENT = new PdfDocument(new PdfWriter(new MemoryStream()));
private const String DUMMY_NAME = "dummy name";
[NUnit.Framework.Test]
public virtual void ConstructorTest() {
FormFieldBuilderTest.TestBuilder builder = new FormFieldBuilderTest.TestBuilder(DUMMY_DOCUMENT, DUMMY_NAME
);
NUnit.Framework.Assert.AreSame(DUMMY_DOCUMENT, builder.GetDocument());
NUnit.Framework.Assert.AreSame(DUMMY_NAME, builder.GetFormFieldName());
}
[NUnit.Framework.Test]
public virtual void GetSetConformanceLevelTest() {
FormFieldBuilderTest.TestBuilder builder = new FormFieldBuilderTest.TestBuilder(DUMMY_DOCUMENT, DUMMY_NAME
);
builder.SetConformanceLevel(PdfAConformanceLevel.PDF_A_1A);
NUnit.Framework.Assert.AreSame(PdfAConformanceLevel.PDF_A_1A, builder.GetConformanceLevel());
}
private class TestBuilder : FormFieldBuilder<FormFieldBuilderTest.TestBuilder> {
protected internal TestBuilder(PdfDocument document, String formFieldName)
: base(document, formFieldName) {
}
protected internal override FormFieldBuilderTest.TestBuilder GetThis() {
return this;
}
}
}
}

View File

@@ -0,0 +1,110 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using System.Threading;
using TSpdf.Commons.Actions.Contexts;
using TSpdf.Layout.Renderer;
using TSpdf.Test;
namespace TSpdf.Forms.Fields {
[NUnit.Framework.Category("UnitTest")]
public class FormsMetaInfoStaticContainerTest : ExtendedTSpdfTest {
[NUnit.Framework.Test]
public virtual void UseMetaInfoDuringTheActionOneThreadTest() {
MetaInfoContainer metaInfo1 = new MetaInfoContainer(new _IMetaInfo_38());
MetaInfoContainer metaInfo2 = new MetaInfoContainer(new _IMetaInfo_39());
FormsMetaInfoStaticContainer.UseMetaInfoDuringTheAction(metaInfo1, () => {
NUnit.Framework.Assert.AreSame(metaInfo1, FormsMetaInfoStaticContainer.GetMetaInfoForLayout());
FormsMetaInfoStaticContainer.UseMetaInfoDuringTheAction(metaInfo2, () => NUnit.Framework.Assert.AreSame(metaInfo2
, FormsMetaInfoStaticContainer.GetMetaInfoForLayout()));
NUnit.Framework.Assert.IsNull(FormsMetaInfoStaticContainer.GetMetaInfoForLayout());
}
);
NUnit.Framework.Assert.IsNull(FormsMetaInfoStaticContainer.GetMetaInfoForLayout());
}
private sealed class _IMetaInfo_38 : IMetaInfo {
public _IMetaInfo_38() {
}
}
private sealed class _IMetaInfo_39 : IMetaInfo {
public _IMetaInfo_39() {
}
}
[NUnit.Framework.Test]
public virtual void UseMetaInfoDuringTheActionSeveralThreadsTest() {
FormsMetaInfoStaticContainerTest.MetaInfoCheckClass metaInfoCheckClass1 = new FormsMetaInfoStaticContainerTest.MetaInfoCheckClass
(null);
FormsMetaInfoStaticContainerTest.MetaInfoCheckClass metaInfoCheckClass2 = new FormsMetaInfoStaticContainerTest.MetaInfoCheckClass
(metaInfoCheckClass1);
FormsMetaInfoStaticContainerTest.MetaInfoCheckClass metaInfoCheckClass3 = new FormsMetaInfoStaticContainerTest.MetaInfoCheckClass
(metaInfoCheckClass2);
Thread thread = new Thread(() => metaInfoCheckClass3.CheckMetaInfo());
thread.Start();
thread.Join();
NUnit.Framework.Assert.IsFalse(metaInfoCheckClass1.IsCheckFailed());
NUnit.Framework.Assert.IsFalse(metaInfoCheckClass2.IsCheckFailed());
NUnit.Framework.Assert.IsFalse(metaInfoCheckClass3.IsCheckFailed());
}
private class MetaInfoCheckClass {
private FormsMetaInfoStaticContainerTest.MetaInfoCheckClass metaInfoCheckClass = null;
private bool checkFailed = false;
public MetaInfoCheckClass(FormsMetaInfoStaticContainerTest.MetaInfoCheckClass metaInfoCheckClass) {
this.metaInfoCheckClass = metaInfoCheckClass;
}
public virtual void CheckMetaInfo() {
MetaInfoContainer metaInfo = new MetaInfoContainer(new _IMetaInfo_78());
FormsMetaInfoStaticContainer.UseMetaInfoDuringTheAction(metaInfo, () => {
if (metaInfoCheckClass != null) {
Thread thread = new Thread(() => metaInfoCheckClass.CheckMetaInfo());
thread.Start();
try {
thread.Join();
}
catch (Exception) {
checkFailed = true;
}
}
checkFailed |= metaInfo != FormsMetaInfoStaticContainer.GetMetaInfoForLayout();
}
);
checkFailed |= FormsMetaInfoStaticContainer.GetMetaInfoForLayout() != null;
}
private sealed class _IMetaInfo_78 : IMetaInfo {
public _IMetaInfo_78() {
}
}
public virtual bool IsCheckFailed() {
return checkFailed;
}
}
}
}

View File

@@ -0,0 +1,69 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.IO;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Pdf.Annot;
using TSpdf.Kernel.Utils;
using TSpdf.Test;
namespace TSpdf.Forms.Fields {
[NUnit.Framework.Category("UnitTest")]
public class NonTerminalFormFieldBuilderTest : ExtendedTSpdfTest {
private static readonly PdfDocument DUMMY_DOCUMENT = new PdfDocument(new PdfWriter(new MemoryStream()));
private const String DUMMY_NAME = "dummy name";
[NUnit.Framework.Test]
public virtual void ConstructorTest() {
NonTerminalFormFieldBuilder builder = new NonTerminalFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME);
NUnit.Framework.Assert.AreSame(DUMMY_DOCUMENT, builder.GetDocument());
NUnit.Framework.Assert.AreSame(DUMMY_NAME, builder.GetFormFieldName());
}
[NUnit.Framework.Test]
public virtual void CreateNonTerminalFormField() {
PdfFormField nonTerminalFormField = new NonTerminalFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).CreateNonTerminalFormField
();
CompareNonTerminalFormFields(nonTerminalFormField);
}
private static void CompareNonTerminalFormFields(PdfFormField nonTerminalFormField) {
PdfDictionary expectedDictionary = new PdfDictionary();
IList<PdfWidgetAnnotation> widgets = nonTerminalFormField.GetWidgets();
NUnit.Framework.Assert.AreEqual(0, widgets.Count);
PutIfAbsent(expectedDictionary, PdfName.T, new PdfString(DUMMY_NAME));
expectedDictionary.MakeIndirect(DUMMY_DOCUMENT);
nonTerminalFormField.MakeIndirect(DUMMY_DOCUMENT);
NUnit.Framework.Assert.IsNull(new CompareTool().CompareDictionariesStructure(expectedDictionary, nonTerminalFormField
.GetPdfObject()));
}
private static void PutIfAbsent(PdfDictionary dictionary, PdfName name, PdfObject value) {
if (!dictionary.ContainsKey(name)) {
dictionary.Put(name, value);
}
}
}
}

View File

@@ -0,0 +1,59 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using TSpdf.Forms;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Pdf.Xobject;
using TSpdf.Kernel.Utils;
using TSpdf.Test;
namespace TSpdf.Forms.Fields {
[NUnit.Framework.Category("IntegrationTest")]
public class PdfFormFieldIntegrationTest : ExtendedTSpdfTest {
private static readonly String SOURCE_FOLDER = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/forms/fields/PdfFormFieldIntegrationTest/";
private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/forms/fields/PdfFormFieldIntegrationTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
CreateOrClearDestinationFolder(DESTINATION_FOLDER);
}
[NUnit.Framework.Test]
public virtual void AddFormXObjectToPushButtonTest() {
String outPdf = DESTINATION_FOLDER + "addFormXObjectToPushButton.pdf";
String cmpPdf = SOURCE_FOLDER + "cmp_addFormXObjectToPushButton.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfReader(SOURCE_FOLDER + "addFormXObjectToPushButton.pdf"), new
PdfWriter(outPdf));
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
PdfPage page = pdfDoc.GetPage(2);
PdfFormXObject xObject = page.CopyAsFormXObject(pdfDoc);
((PdfButtonFormField)form.GetField("pushButton")).SetImageAsForm(xObject);
pdfDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, DESTINATION_FOLDER, "diff_"
));
}
}
}

View File

@@ -0,0 +1,74 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using TSpdf.Commons.Actions.Contexts;
using TSpdf.IO.Source;
using TSpdf.Kernel.Geom;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Pdf.Canvas;
using TSpdf.Layout;
using TSpdf.Layout.Properties;
using TSpdf.Layout.Renderer;
using TSpdf.Test;
namespace TSpdf.Forms.Fields {
[NUnit.Framework.Category("UnitTest")]
public class PdfFormFieldUnitTest : ExtendedTSpdfTest {
[NUnit.Framework.Test]
public virtual void CannotGetRectangleIfKidsIsNullTest() {
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(new ByteArrayOutputStream()));
PdfFormField pdfFormField = new PdfFormField(pdfDocument);
NUnit.Framework.Assert.IsNull(pdfFormField.GetFirstFormAnnotation());
}
[NUnit.Framework.Test]
public virtual void SetMetaInfoToCanvasMetaInfoUsedTest() {
Canvas canvas = CreateCanvas();
MetaInfoContainer metaInfoContainer = new MetaInfoContainer(new _IMetaInfo_56());
FormsMetaInfoStaticContainer.UseMetaInfoDuringTheAction(metaInfoContainer, () => PdfFormAnnotation.SetMetaInfoToCanvas
(canvas));
NUnit.Framework.Assert.AreSame(metaInfoContainer, canvas.GetProperty<MetaInfoContainer>(Property.META_INFO
));
}
private sealed class _IMetaInfo_56 : IMetaInfo {
public _IMetaInfo_56() {
}
}
[NUnit.Framework.Test]
public virtual void SetMetaInfoToCanvasMetaInfoNotUsedTest() {
Canvas canvas = CreateCanvas();
PdfFormAnnotation.SetMetaInfoToCanvas(canvas);
NUnit.Framework.Assert.IsNull(canvas.GetProperty<MetaInfoContainer>(Property.META_INFO));
}
private static Canvas CreateCanvas() {
using (PdfDocument document = new PdfDocument(new PdfWriter(new ByteArrayOutputStream()))) {
PdfStream stream = (PdfStream)new PdfStream().MakeIndirect(document);
PdfResources resources = new PdfResources();
PdfCanvas pdfCanvas = new PdfCanvas(stream, resources, document);
return new TSpdf.Layout.Canvas(pdfCanvas, new Rectangle(100, 100));
}
}
}
}

View File

@@ -0,0 +1,105 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.IO;
using TSpdf.Kernel.Geom;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Pdf.Annot;
using TSpdf.Kernel.Utils;
using TSpdf.Test;
namespace TSpdf.Forms.Fields {
[NUnit.Framework.Category("UnitTest")]
public class PushButtonFormFieldBuilderTest : ExtendedTSpdfTest {
private static readonly PdfDocument DUMMY_DOCUMENT = new PdfDocument(new PdfWriter(new MemoryStream()));
private const String DUMMY_NAME = "dummy name";
private static readonly Rectangle DUMMY_RECTANGLE = new Rectangle(7, 11, 13, 17);
[NUnit.Framework.Test]
public virtual void ConstructorTest() {
PushButtonFormFieldBuilder builder = new PushButtonFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME);
NUnit.Framework.Assert.AreSame(DUMMY_DOCUMENT, builder.GetDocument());
NUnit.Framework.Assert.AreSame(DUMMY_NAME, builder.GetFormFieldName());
}
[NUnit.Framework.Test]
public virtual void SetGetCaptionType() {
PushButtonFormFieldBuilder builder = new PushButtonFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME);
builder.SetCaption("Caption");
NUnit.Framework.Assert.AreEqual("Caption", builder.GetCaption());
}
[NUnit.Framework.Test]
public virtual void CreatePushButtonWithWidgetTest() {
PdfButtonFormField pushButtonFormField = new PushButtonFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).SetWidgetRectangle
(DUMMY_RECTANGLE).CreatePushButton();
ComparePushButtons(pushButtonFormField, true);
}
[NUnit.Framework.Test]
public virtual void CreatePushButtonWithoutWidgetTest() {
PdfButtonFormField pushButtonFormField = new PushButtonFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).CreatePushButton
();
ComparePushButtons(pushButtonFormField, false);
}
[NUnit.Framework.Test]
public virtual void CreatePushButtonWithConformanceLevelTest() {
PdfButtonFormField pushButtonFormField = new PushButtonFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).SetWidgetRectangle
(DUMMY_RECTANGLE).SetConformanceLevel(PdfAConformanceLevel.PDF_A_1A).CreatePushButton();
ComparePushButtons(pushButtonFormField, true);
}
private static void ComparePushButtons(PdfButtonFormField pushButtonFormField, bool widgetExpected) {
PdfDictionary expectedDictionary = new PdfDictionary();
IList<PdfWidgetAnnotation> widgets = pushButtonFormField.GetWidgets();
if (widgetExpected) {
NUnit.Framework.Assert.AreEqual(1, widgets.Count);
PdfWidgetAnnotation annotation = widgets[0];
NUnit.Framework.Assert.IsTrue(DUMMY_RECTANGLE.EqualsWithEpsilon(annotation.GetRectangle().ToRectangle()));
PdfArray kids = new PdfArray();
kids.Add(annotation.GetPdfObject());
PutIfAbsent(expectedDictionary, PdfName.Kids, kids);
}
else {
NUnit.Framework.Assert.AreEqual(0, widgets.Count);
}
PutIfAbsent(expectedDictionary, PdfName.FT, PdfName.Btn);
PutIfAbsent(expectedDictionary, PdfName.Ff, new PdfNumber(PdfButtonFormField.FF_PUSH_BUTTON));
PutIfAbsent(expectedDictionary, PdfName.T, new PdfString(DUMMY_NAME));
expectedDictionary.MakeIndirect(DUMMY_DOCUMENT);
pushButtonFormField.MakeIndirect(DUMMY_DOCUMENT);
NUnit.Framework.Assert.IsNull(new CompareTool().CompareDictionariesStructure(expectedDictionary, pushButtonFormField
.GetPdfObject()));
}
private static void PutIfAbsent(PdfDictionary dictionary, PdfName name, PdfObject value) {
if (!dictionary.ContainsKey(name)) {
dictionary.Put(name, value);
}
}
}
}

View File

@@ -0,0 +1,128 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.IO;
using TSpdf.Kernel.Geom;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Pdf.Annot;
using TSpdf.Kernel.Utils;
using TSpdf.Test;
namespace TSpdf.Forms.Fields {
[NUnit.Framework.Category("UnitTest")]
public class RadioFormFieldBuilderTest : ExtendedTSpdfTest {
private static readonly PdfDocument DUMMY_DOCUMENT = new PdfDocument(new PdfWriter(new MemoryStream()));
private const String DUMMY_NAME = "dummy name";
private static readonly Rectangle DUMMY_RECTANGLE = new Rectangle(7, 11, 13, 17);
private const String DUMMY_APPEARANCE_NAME = "dummy appearance name";
[NUnit.Framework.Test]
public virtual void OneParameterConstructorTest() {
RadioFormFieldBuilder builder = new RadioFormFieldBuilder(DUMMY_DOCUMENT);
NUnit.Framework.Assert.AreSame(DUMMY_DOCUMENT, builder.GetDocument());
NUnit.Framework.Assert.IsNull(builder.GetFormFieldName());
}
[NUnit.Framework.Test]
public virtual void TwoParametersConstructorTest() {
RadioFormFieldBuilder builder = new RadioFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME);
NUnit.Framework.Assert.AreSame(DUMMY_DOCUMENT, builder.GetDocument());
NUnit.Framework.Assert.AreSame(DUMMY_NAME, builder.GetFormFieldName());
}
[NUnit.Framework.Test]
public virtual void CreateRadioGroupTest() {
PdfButtonFormField radioGroup = new RadioFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).CreateRadioGroup();
CompareRadioGroups(radioGroup);
}
[NUnit.Framework.Test]
public virtual void CreateRadioButtonWithWidgetTest() {
PdfButtonFormField radioGroup = new RadioFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).CreateRadioGroup();
PdfFormField radioFormField = new RadioFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).SetWidgetRectangle(DUMMY_RECTANGLE
).CreateRadioButton(radioGroup, DUMMY_APPEARANCE_NAME);
CompareRadioButtons(radioFormField, radioGroup, true);
}
[NUnit.Framework.Test]
public virtual void CreateRadioButtonWithoutWidgetTest() {
PdfButtonFormField radioGroup = new RadioFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).CreateRadioGroup();
PdfFormField radioFormField = new RadioFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).CreateRadioButton(radioGroup
, DUMMY_APPEARANCE_NAME);
CompareRadioButtons(radioFormField, radioGroup, false);
}
[NUnit.Framework.Test]
public virtual void CreateRadioButtonWithConformanceLevelTest() {
PdfButtonFormField radioGroup = new RadioFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).CreateRadioGroup();
PdfFormField radioFormField = new RadioFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).SetWidgetRectangle(DUMMY_RECTANGLE
).SetConformanceLevel(PdfAConformanceLevel.PDF_A_1A).CreateRadioButton(radioGroup, DUMMY_APPEARANCE_NAME
);
CompareRadioButtons(radioFormField, radioGroup, true);
}
private static void CompareRadioGroups(PdfButtonFormField radioGroupFormField) {
PdfDictionary expectedDictionary = new PdfDictionary();
PutIfAbsent(expectedDictionary, PdfName.FT, PdfName.Btn);
PutIfAbsent(expectedDictionary, PdfName.Ff, new PdfNumber(PdfButtonFormField.FF_RADIO));
PutIfAbsent(expectedDictionary, PdfName.T, new PdfString(DUMMY_NAME));
expectedDictionary.MakeIndirect(DUMMY_DOCUMENT);
radioGroupFormField.MakeIndirect(DUMMY_DOCUMENT);
NUnit.Framework.Assert.IsNull(new CompareTool().CompareDictionariesStructure(expectedDictionary, radioGroupFormField
.GetPdfObject()));
}
private static void CompareRadioButtons(PdfFormField radioButtonFormField, PdfButtonFormField radioGroup,
bool widgetExpected) {
PdfDictionary expectedDictionary = new PdfDictionary();
IList<PdfWidgetAnnotation> widgets = radioButtonFormField.GetWidgets();
if (widgetExpected) {
NUnit.Framework.Assert.AreEqual(1, widgets.Count);
PdfWidgetAnnotation annotation = widgets[0];
NUnit.Framework.Assert.IsTrue(DUMMY_RECTANGLE.EqualsWithEpsilon(annotation.GetRectangle().ToRectangle()));
PdfArray kids = new PdfArray();
kids.Add(annotation.GetPdfObject());
PutIfAbsent(expectedDictionary, PdfName.Kids, kids);
}
else {
NUnit.Framework.Assert.AreEqual(0, widgets.Count);
}
PutIfAbsent(expectedDictionary, PdfName.Parent, radioGroup.GetPdfObject());
PutIfAbsent(expectedDictionary, PdfName.FT, PdfName.Btn);
expectedDictionary.MakeIndirect(DUMMY_DOCUMENT);
radioButtonFormField.MakeIndirect(DUMMY_DOCUMENT);
NUnit.Framework.Assert.IsNull(new CompareTool().CompareDictionariesStructure(expectedDictionary, radioButtonFormField
.GetPdfObject()));
}
private static void PutIfAbsent(PdfDictionary dictionary, PdfName name, PdfObject value) {
if (!dictionary.ContainsKey(name)) {
dictionary.Put(name, value);
}
}
}
}

View File

@@ -0,0 +1,97 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.IO;
using TSpdf.Kernel.Geom;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Pdf.Annot;
using TSpdf.Kernel.Utils;
using TSpdf.Test;
namespace TSpdf.Forms.Fields {
[NUnit.Framework.Category("UnitTest")]
public class SignatureFormFieldBuilderTest : ExtendedTSpdfTest {
private static readonly PdfDocument DUMMY_DOCUMENT = new PdfDocument(new PdfWriter(new MemoryStream()));
private const String DUMMY_NAME = "dummy name";
private static readonly Rectangle DUMMY_RECTANGLE = new Rectangle(7, 11, 13, 17);
[NUnit.Framework.Test]
public virtual void ConstructorTest() {
SignatureFormFieldBuilder builder = new SignatureFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME);
NUnit.Framework.Assert.AreSame(DUMMY_DOCUMENT, builder.GetDocument());
NUnit.Framework.Assert.AreSame(DUMMY_NAME, builder.GetFormFieldName());
}
[NUnit.Framework.Test]
public virtual void CreateSignatureWithWidgetTest() {
PdfSignatureFormField signatureFormField = new SignatureFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).SetWidgetRectangle
(DUMMY_RECTANGLE).CreateSignature();
CompareSignatures(signatureFormField, true);
}
[NUnit.Framework.Test]
public virtual void CreateSignatureWithoutWidgetTest() {
PdfSignatureFormField signatureFormField = new SignatureFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).CreateSignature
();
CompareSignatures(signatureFormField, false);
}
[NUnit.Framework.Test]
public virtual void CreateSignatureWithConformanceLevelTest() {
PdfSignatureFormField signatureFormField = new SignatureFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).SetWidgetRectangle
(DUMMY_RECTANGLE).SetConformanceLevel(PdfAConformanceLevel.PDF_A_1A).CreateSignature();
CompareSignatures(signatureFormField, true);
}
private static void CompareSignatures(PdfSignatureFormField signatureFormField, bool widgetExpected) {
PdfDictionary expectedDictionary = new PdfDictionary();
IList<PdfWidgetAnnotation> widgets = signatureFormField.GetWidgets();
if (widgetExpected) {
NUnit.Framework.Assert.AreEqual(1, widgets.Count);
PdfWidgetAnnotation annotation = widgets[0];
NUnit.Framework.Assert.IsTrue(DUMMY_RECTANGLE.EqualsWithEpsilon(annotation.GetRectangle().ToRectangle()));
PdfArray kids = new PdfArray();
kids.Add(annotation.GetPdfObject());
PutIfAbsent(expectedDictionary, PdfName.Kids, kids);
}
else {
NUnit.Framework.Assert.AreEqual(0, widgets.Count);
}
PutIfAbsent(expectedDictionary, PdfName.FT, PdfName.Sig);
PutIfAbsent(expectedDictionary, PdfName.T, new PdfString(DUMMY_NAME));
expectedDictionary.MakeIndirect(DUMMY_DOCUMENT);
signatureFormField.MakeIndirect(DUMMY_DOCUMENT);
NUnit.Framework.Assert.IsNull(new CompareTool().CompareDictionariesStructure(expectedDictionary, signatureFormField
.GetPdfObject()));
}
private static void PutIfAbsent(PdfDictionary dictionary, PdfName name, PdfObject value) {
if (!dictionary.ContainsKey(name)) {
dictionary.Put(name, value);
}
}
}
}

View File

@@ -0,0 +1,97 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using System.IO;
using TSpdf.Kernel.Geom;
using TSpdf.Kernel.Pdf;
using TSpdf.Test;
namespace TSpdf.Forms.Fields {
[NUnit.Framework.Category("UnitTest")]
public class TerminalFormFieldBuilderTest : ExtendedTSpdfTest {
private static readonly PdfDocument DUMMY_DOCUMENT = new PdfDocument(new PdfWriter(new MemoryStream()));
private const String DUMMY_NAME = "dummy name";
private static readonly Rectangle DUMMY_RECTANGLE = new Rectangle(7, 11, 13, 17);
[NUnit.Framework.Test]
public virtual void ConstructorTest() {
TerminalFormFieldBuilderTest.TestBuilder builder = new TerminalFormFieldBuilderTest.TestBuilder(DUMMY_DOCUMENT
, DUMMY_NAME);
NUnit.Framework.Assert.AreSame(DUMMY_DOCUMENT, builder.GetDocument());
NUnit.Framework.Assert.AreSame(DUMMY_NAME, builder.GetFormFieldName());
}
[NUnit.Framework.Test]
public virtual void GetSetWidgetTest() {
TerminalFormFieldBuilderTest.TestBuilder builder = new TerminalFormFieldBuilderTest.TestBuilder(DUMMY_DOCUMENT
, DUMMY_NAME);
builder.SetWidgetRectangle(DUMMY_RECTANGLE);
NUnit.Framework.Assert.AreSame(DUMMY_RECTANGLE, builder.GetWidgetRectangle());
}
[NUnit.Framework.Test]
public virtual void GetSetPageTest() {
TerminalFormFieldBuilderTest.TestBuilder builder = new TerminalFormFieldBuilderTest.TestBuilder(DUMMY_DOCUMENT
, DUMMY_NAME);
PdfPage page = DUMMY_DOCUMENT.AddNewPage();
builder.SetPage(page);
NUnit.Framework.Assert.AreEqual(1, builder.GetPage());
builder.SetPage(5);
NUnit.Framework.Assert.AreEqual(5, builder.GetPage());
}
[NUnit.Framework.Test]
public virtual void SetPageToFieldTest() {
TerminalFormFieldBuilderTest.TestBuilder builder = new TerminalFormFieldBuilderTest.TestBuilder(DUMMY_DOCUMENT
, DUMMY_NAME);
builder.SetPage(5);
PdfFormAnnotation formFieldAnnot = new _PdfFormAnnotation_79((PdfDictionary)new PdfDictionary().MakeIndirect
(DUMMY_DOCUMENT));
PdfFormField formField = new PdfFormField(DUMMY_DOCUMENT).AddKid(formFieldAnnot);
builder.SetPageToField(formField);
}
private sealed class _PdfFormAnnotation_79 : PdfFormAnnotation {
public _PdfFormAnnotation_79(PdfDictionary baseArg1)
: base(baseArg1) {
}
public override PdfFormAnnotation SetPage(int pageNum) {
NUnit.Framework.Assert.AreEqual(5, pageNum);
return this;
}
}
private class TestBuilder : TerminalFormFieldBuilder<TerminalFormFieldBuilderTest.TestBuilder> {
protected internal TestBuilder(PdfDocument document, String formFieldName)
: base(document, formFieldName) {
}
protected internal override TerminalFormFieldBuilderTest.TestBuilder GetThis() {
return this;
}
}
}
}

View File

@@ -0,0 +1,131 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.IO;
using TSpdf.Kernel.Geom;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Pdf.Annot;
using TSpdf.Kernel.Utils;
using TSpdf.Test;
namespace TSpdf.Forms.Fields {
[NUnit.Framework.Category("UnitTest")]
public class TextFormFieldBuilderTest : ExtendedTSpdfTest {
private static readonly PdfDocument DUMMY_DOCUMENT = new PdfDocument(new PdfWriter(new MemoryStream()));
private const String DUMMY_NAME = "dummy name";
private static readonly Rectangle DUMMY_RECTANGLE = new Rectangle(7, 11, 13, 17);
[NUnit.Framework.Test]
public virtual void ConstructorTest() {
TextFormFieldBuilder builder = new TextFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME);
NUnit.Framework.Assert.AreSame(DUMMY_DOCUMENT, builder.GetDocument());
NUnit.Framework.Assert.AreSame(DUMMY_NAME, builder.GetFormFieldName());
}
[NUnit.Framework.Test]
public virtual void CreateTextWithWidgetTest() {
PdfTextFormField textFormField = new TextFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).SetWidgetRectangle(DUMMY_RECTANGLE
).CreateText();
PdfDictionary expectedDictionary = new PdfDictionary();
expectedDictionary.Put(PdfName.Ff, new PdfNumber(0));
CompareTexts(expectedDictionary, textFormField, true);
}
[NUnit.Framework.Test]
public virtual void CreateTextWithoutWidgetTest() {
PdfTextFormField textFormField = new TextFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).CreateText();
PdfDictionary expectedDictionary = new PdfDictionary();
expectedDictionary.Put(PdfName.Ff, new PdfNumber(0));
CompareTexts(expectedDictionary, textFormField, false);
}
[NUnit.Framework.Test]
public virtual void CreateTextWithConformanceLevelTest() {
PdfTextFormField textFormField = new TextFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).SetWidgetRectangle(DUMMY_RECTANGLE
).SetConformanceLevel(PdfAConformanceLevel.PDF_A_1A).CreateText();
PdfDictionary expectedDictionary = new PdfDictionary();
expectedDictionary.Put(PdfName.Ff, new PdfNumber(0));
CompareTexts(expectedDictionary, textFormField, true);
}
[NUnit.Framework.Test]
public virtual void CreateMultilineTextWithWidgetTest() {
PdfTextFormField textFormField = new TextFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).SetWidgetRectangle(DUMMY_RECTANGLE
).CreateMultilineText();
PdfDictionary expectedDictionary = new PdfDictionary();
expectedDictionary.Put(PdfName.Ff, new PdfNumber(PdfTextFormField.FF_MULTILINE));
CompareTexts(expectedDictionary, textFormField, true);
}
[NUnit.Framework.Test]
public virtual void CreateMultilineTextWithoutWidgetTest() {
PdfTextFormField textFormField = new TextFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).CreateMultilineText(
);
PdfDictionary expectedDictionary = new PdfDictionary();
expectedDictionary.Put(PdfName.Ff, new PdfNumber(PdfTextFormField.FF_MULTILINE));
CompareTexts(expectedDictionary, textFormField, false);
}
[NUnit.Framework.Test]
public virtual void CreateMultilineTextWithConformanceLevelTest() {
PdfTextFormField textFormField = new TextFormFieldBuilder(DUMMY_DOCUMENT, DUMMY_NAME).SetWidgetRectangle(DUMMY_RECTANGLE
).SetConformanceLevel(PdfAConformanceLevel.PDF_A_1A).CreateMultilineText();
PdfDictionary expectedDictionary = new PdfDictionary();
expectedDictionary.Put(PdfName.Ff, new PdfNumber(PdfTextFormField.FF_MULTILINE));
CompareTexts(expectedDictionary, textFormField, true);
}
private static void CompareTexts(PdfDictionary expectedDictionary, PdfTextFormField textFormField, bool widgetExpected
) {
IList<PdfWidgetAnnotation> widgets = textFormField.GetWidgets();
if (widgetExpected) {
NUnit.Framework.Assert.AreEqual(1, widgets.Count);
PdfWidgetAnnotation annotation = widgets[0];
NUnit.Framework.Assert.IsTrue(DUMMY_RECTANGLE.EqualsWithEpsilon(annotation.GetRectangle().ToRectangle()));
PdfArray kids = new PdfArray();
kids.Add(annotation.GetPdfObject());
PutIfAbsent(expectedDictionary, PdfName.Kids, kids);
}
else {
NUnit.Framework.Assert.AreEqual(0, widgets.Count);
}
PutIfAbsent(expectedDictionary, PdfName.FT, PdfName.Tx);
PutIfAbsent(expectedDictionary, PdfName.T, new PdfString(DUMMY_NAME));
PutIfAbsent(expectedDictionary, PdfName.V, new PdfString(""));
PutIfAbsent(expectedDictionary, PdfName.DA, new PdfString("/F1 12 Tf"));
expectedDictionary.MakeIndirect(DUMMY_DOCUMENT);
textFormField.MakeIndirect(DUMMY_DOCUMENT);
NUnit.Framework.Assert.IsNull(new CompareTool().CompareDictionariesStructure(expectedDictionary, textFormField
.GetPdfObject()));
}
private static void PutIfAbsent(PdfDictionary dictionary, PdfName name, PdfObject value) {
if (!dictionary.ContainsKey(name)) {
dictionary.Put(name, value);
}
}
}
}

View File

@@ -0,0 +1,234 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.Collections.Generic;
using TSpdf.Forms;
using TSpdf.Forms.Fields;
using TSpdf.Kernel.Colors;
using TSpdf.Kernel.Geom;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Pdf.Annot;
using TSpdf.Kernel.Utils;
using TSpdf.Test;
namespace TSpdf.Forms.Widget {
[NUnit.Framework.Category("IntegrationTest")]
public class AppearanceCharacteristicsTest : ExtendedTSpdfTest {
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/forms/widget/AppearanceCharacteristicsTest/";
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/forms/widget/AppearanceCharacteristicsTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void FormFieldBordersTest() {
String outPdf = destinationFolder + "formFieldBorders.pdf";
String cmpPdf = sourceFolder + "cmp_formFieldBorders.pdf";
using (PdfDocument doc = new PdfDocument(new PdfWriter(outPdf))) {
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
PdfFormField simpleField = new TextFormFieldBuilder(doc, "simpleField").SetWidgetRectangle(new Rectangle(300
, 300, 200, 100)).CreateText();
simpleField.RegenerateField();
PdfFormField insetField = new TextFormFieldBuilder(doc, "insetField").SetWidgetRectangle(new Rectangle(50,
600, 200, 100)).CreateText();
insetField.GetWidgets()[0].SetBorderStyle(PdfName.I);
insetField.GetFirstFormAnnotation().SetBorderWidth(3f).SetBorderColor(DeviceRgb.RED).RegenerateField();
PdfFormField underlineField = new TextFormFieldBuilder(doc, "underlineField").SetWidgetRectangle(new Rectangle
(300, 600, 200, 100)).CreateText();
underlineField.GetWidgets()[0].SetBorderStyle(PdfName.U);
underlineField.GetFirstFormAnnotation().SetBorderWidth(3f).SetBorderColor(DeviceRgb.RED).RegenerateField();
PdfFormField solidField = new TextFormFieldBuilder(doc, "solidField").SetWidgetRectangle(new Rectangle(50,
450, 200, 100)).CreateText();
solidField.GetWidgets()[0].SetBorderStyle(PdfName.S);
solidField.GetFirstFormAnnotation().SetBorderWidth(3f).SetBorderColor(DeviceRgb.RED).RegenerateField();
PdfFormField dashField = new TextFormFieldBuilder(doc, "dashField").SetWidgetRectangle(new Rectangle(300,
450, 200, 100)).CreateText();
dashField.GetWidgets()[0].SetBorderStyle(PdfName.D);
dashField.GetFirstFormAnnotation().SetBorderWidth(3f).SetBorderColor(DeviceRgb.RED).RegenerateField();
PdfFormField beveledField = new TextFormFieldBuilder(doc, "beveledField").SetWidgetRectangle(new Rectangle
(50, 300, 200, 100)).CreateText();
beveledField.GetWidgets()[0].SetBorderStyle(PdfName.B);
beveledField.GetFirstFormAnnotation().SetBorderWidth(3f).SetBorderColor(DeviceRgb.RED).RegenerateField();
form.AddField(simpleField);
form.AddField(insetField);
form.AddField(underlineField);
form.AddField(solidField);
form.AddField(dashField);
form.AddField(beveledField);
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder));
}
[NUnit.Framework.Test]
public virtual void BeveledBorderWithBackgroundTest() {
String outPdf = destinationFolder + "beveledBorderWithBackground.pdf";
String cmpPdf = sourceFolder + "cmp_beveledBorderWithBackground.pdf";
using (PdfDocument doc = new PdfDocument(new PdfWriter(outPdf))) {
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
PdfFormField formField = new TextFormFieldBuilder(doc, "formField").SetWidgetRectangle(new Rectangle(100,
600, 200, 100)).CreateText();
formField.GetWidgets()[0].SetBorderStyle(PdfName.B);
formField.GetFirstFormAnnotation().SetBorderWidth(3f).SetBackgroundColor(DeviceRgb.GREEN).SetBorderColor(DeviceRgb
.RED);
formField.RegenerateField();
form.AddField(formField);
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder));
}
[NUnit.Framework.Test]
public virtual void DashedBorderWithBackgroundTest() {
String outPdf = destinationFolder + "dashedBorderWithBackground.pdf";
String cmpPdf = sourceFolder + "cmp_dashedBorderWithBackground.pdf";
using (PdfDocument doc = new PdfDocument(new PdfWriter(outPdf))) {
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
PdfFormField formField = new TextFormFieldBuilder(doc, "formField").SetWidgetRectangle(new Rectangle(100,
600, 200, 100)).CreateText();
formField.GetWidgets()[0].SetBorderStyle(PdfName.D);
formField.GetFirstFormAnnotation().SetBorderWidth(3f).SetBorderColor(DeviceRgb.RED).SetBackgroundColor(DeviceRgb
.GREEN);
formField.RegenerateField();
form.AddField(formField);
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder));
}
[NUnit.Framework.Test]
public virtual void TextStartsAfterFieldBorderTest() {
// TODO DEVSIX-4809 text in form filed with borders must start after border
String outPdf = destinationFolder + "textStartsAfterFieldBorderTest.pdf";
String cmpPdf = sourceFolder + "cmp_textStartsAfterFieldBorderTest.pdf";
using (PdfDocument doc = new PdfDocument(new PdfWriter(outPdf))) {
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
PdfFormField insetFormField = new TextFormFieldBuilder(doc, "insetFormField").SetWidgetRectangle(new Rectangle
(90, 600, 200, 100)).CreateText();
insetFormField.GetWidgets()[0].SetBorderStyle(PdfName.I);
insetFormField.GetFirstFormAnnotation().SetBorderWidth(15f).SetBorderColor(DeviceRgb.RED);
insetFormField.SetValue("Text after border").RegenerateField();
PdfFormField solidFormField = new TextFormFieldBuilder(doc, "solidFormField").SetWidgetRectangle(new Rectangle
(300, 600, 200, 100)).CreateText();
solidFormField.GetWidgets()[0].SetBorderStyle(PdfName.S);
solidFormField.GetFirstFormAnnotation().SetBorderWidth(15f).SetBorderColor(DeviceRgb.RED);
solidFormField.SetValue("Text after border").RegenerateField();
PdfFormField underlineFormField = new TextFormFieldBuilder(doc, "underlineFormField").SetWidgetRectangle(new
Rectangle(90, 450, 200, 100)).CreateText();
underlineFormField.GetWidgets()[0].SetBorderStyle(PdfName.U);
underlineFormField.GetFirstFormAnnotation().SetBorderWidth(15f).SetBorderColor(DeviceRgb.RED);
underlineFormField.SetValue("Text after border").RegenerateField();
PdfFormField simpleFormField = new TextFormFieldBuilder(doc, "formField1").SetWidgetRectangle(new Rectangle
(300, 450, 200, 100)).CreateText();
simpleFormField.GetFirstFormAnnotation().SetBorderWidth(15f);
simpleFormField.SetValue("Text after border").RegenerateField();
form.AddField(insetFormField);
form.AddField(solidFormField);
form.AddField(underlineFormField);
form.AddField(simpleFormField);
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_"
));
}
[NUnit.Framework.Test]
public virtual void FillFormWithRotatedFieldAndPageTest() {
String outPdf = destinationFolder + "fillFormWithRotatedFieldAndPageTest.pdf";
String cmpPdf = sourceFolder + "cmp_fillFormWithRotatedFieldAndPageTest.pdf";
using (PdfDocument doc = new PdfDocument(new PdfReader(sourceFolder + "pdfWithRotatedField.pdf"), new PdfWriter
(outPdf))) {
PdfAcroForm form1 = PdfAcroForm.GetAcroForm(doc, false);
form1.GetField("First field").SetValue("We filled this field").GetFirstFormAnnotation().SetBorderColor(ColorConstants
.BLACK);
}
String errorMessage = new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_");
if (errorMessage != null) {
NUnit.Framework.Assert.Fail(errorMessage);
}
}
[NUnit.Framework.Test]
public virtual void BorderStyleInCreatedFormFieldsTest() {
String outPdf = destinationFolder + "borderStyleInCreatedFormFields.pdf";
String cmpPdf = sourceFolder + "cmp_borderStyleInCreatedFormFields.pdf";
using (PdfDocument doc = new PdfDocument(new PdfWriter(outPdf))) {
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
PdfFormField formField1 = new TextFormFieldBuilder(doc, "firstField").SetWidgetRectangle(new Rectangle(100
, 600, 100, 50)).CreateText().SetValue("Hello, TSpdf!");
formField1.GetWidgets()[0].SetBorderStyle(PdfAnnotation.STYLE_BEVELED);
formField1.GetFirstFormAnnotation().SetBorderWidth(2).SetBorderColor(ColorConstants.BLUE);
PdfFormField formField2 = new TextFormFieldBuilder(doc, "secondField").SetWidgetRectangle(new Rectangle(100
, 500, 100, 50)).CreateText().SetValue("Hello, TSpdf!");
formField2.GetWidgets()[0].SetBorderStyle(PdfAnnotation.STYLE_UNDERLINE);
formField2.GetFirstFormAnnotation().SetBorderWidth(2).SetBorderColor(ColorConstants.BLUE);
PdfFormField formField3 = new TextFormFieldBuilder(doc, "thirdField").SetWidgetRectangle(new Rectangle(100
, 400, 100, 50)).CreateText().SetValue("Hello, TSpdf!");
formField3.GetWidgets()[0].SetBorderStyle(PdfAnnotation.STYLE_INSET);
formField3.GetFirstFormAnnotation().SetBorderWidth(2).SetBorderColor(ColorConstants.BLUE);
form.AddField(formField1);
form.AddField(formField2);
form.AddField(formField3);
form.FlattenFields();
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder));
}
[NUnit.Framework.Test]
public virtual void UpdatingBorderStyleInFormFieldsTest() {
String inputPdf = sourceFolder + "borderStyleInCreatedFormFields.pdf";
String outPdf = destinationFolder + "updatingBorderStyleInFormFields.pdf";
String cmpPdf = sourceFolder + "cmp_updatingBorderStyleInFormFields.pdf";
using (PdfDocument doc = new PdfDocument(new PdfReader(inputPdf), new PdfWriter(outPdf))) {
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, false);
IDictionary<String, PdfFormField> fields = form.GetAllFormFields();
fields.Get("firstField").SetValue("New Value 1");
fields.Get("secondField").SetValue("New Value 2");
fields.Get("thirdField").SetValue("New Value 3");
form.FlattenFields();
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder));
}
}
}

View File

@@ -0,0 +1,81 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.IO;
using System.Xml;
using TSpdf.Kernel.Exceptions;
using TSpdf.Kernel.Utils;
namespace TSpdf.Forms.Xfa
{
public class SecurityTestXmlParserFactory : IXmlParserFactory
{
private XmlReaderSettings xmlReaderSettings;
public SecurityTestXmlParserFactory()
{
xmlReaderSettings = new XmlReaderSettings();
xmlReaderSettings.DtdProcessing = DtdProcessing.Parse;
xmlReaderSettings.XmlResolver = new TestXmlResolver();
}
public XmlReader CreateXmlReaderInstance(Stream stream, XmlParserContext inputContext)
{
return XmlReader.Create(stream, xmlReaderSettings);
}
public XmlReader CreateXmlReaderInstance(TextReader textReader)
{
return XmlReader.Create(textReader, xmlReaderSettings);
}
private class TestXmlResolver : XmlResolver
{
public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)
{
throw new PdfException("Test message");
}
}
}
}

View File

@@ -0,0 +1,145 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.IO;
using System.Xml;
using System.Xml.Linq;
using TSpdf.Forms;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Utils;
using TSpdf.Test;
using NUnit.Framework;
namespace TSpdf.Forms.Xfa {
public class XFAFormTest : ExtendedTSpdfTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/forms/xfa/XFAFormTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/forms/xfa/XFAFormTest/";
public static readonly String XML = sourceFolder + "xfa.xml";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void CreateEmptyXFAFormTest01() {
String outFileName = destinationFolder + "createEmptyXFAFormTest01.pdf";
String cmpFileName = sourceFolder + "cmp_createEmptyXFAFormTest01.pdf";
PdfDocument doc = new PdfDocument(new PdfWriter(outFileName));
XfaForm xfa = new XfaForm(doc);
XfaForm.SetXfaForm(xfa, doc);
doc.AddNewPage();
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
, "diff"));
}
[NUnit.Framework.Test]
public virtual void CreateEmptyXFAFormTest02() {
String outFileName = destinationFolder + "createEmptyXFAFormTest02.pdf";
String cmpFileName = sourceFolder + "cmp_createEmptyXFAFormTest02.pdf";
PdfDocument doc = new PdfDocument(new PdfWriter(outFileName));
XfaForm xfa = new XfaForm();
XfaForm.SetXfaForm(xfa, doc);
doc.AddNewPage();
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
, "diff"));
}
[NUnit.Framework.Test]
public virtual void CreateXFAFormTest() {
String outFileName = destinationFolder + "createXFAFormTest.pdf";
String cmpFileName = sourceFolder + "cmp_createXFAFormTest.pdf";
PdfDocument doc = new PdfDocument(new PdfWriter(outFileName));
XfaForm xfa = new XfaForm(new FileStream(XML, FileMode.Open, FileAccess.Read));
xfa.Write(doc);
doc.AddNewPage();
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
, "diff"));
}
[NUnit.Framework.Test]
public virtual void ReadXFAFormTest() {
String inFileName = sourceFolder + "formTemplate.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfReader(inFileName));
Assert.DoesNotThrow(() => PdfAcroForm.GetAcroForm(pdfDocument, true));
}
[NUnit.Framework.Test]
public virtual void FindFieldName() {
String inFileName = sourceFolder + "TextField1.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfReader(inFileName));
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(pdfDocument, true);
XfaForm xfaForm = acroForm.GetXfaForm();
xfaForm.FindFieldName("TextField1");
String secondRun = xfaForm.FindFieldName("TextField1");
NUnit.Framework.Assert.IsNotNull(secondRun);
}
[NUnit.Framework.Test]
public virtual void FindFieldNameWithoutDataSet() {
String inFileName = sourceFolder + "TextField1_empty.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfReader(inFileName));
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(pdfDocument, true);
XfaForm xfaForm = acroForm.GetXfaForm();
String name = xfaForm.FindFieldName("TextField1");
NUnit.Framework.Assert.IsNull(name);
}
[NUnit.Framework.Test]
public virtual void ExtractXFADataTest() {
String src = sourceFolder + "xfaFormWithDataSet.pdf";
PdfDocument pdfDocument = new PdfDocument(new PdfReader(src));
XfaForm xfa = new XfaForm(pdfDocument);
XElement node = (XElement) xfa.FindDatasetsNode("Number1");
NUnit.Framework.Assert.IsNotNull(node);
NUnit.Framework.Assert.AreEqual("Number1", node.Name.LocalName);
}
}
}

View File

@@ -0,0 +1,131 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.IO;
using TSpdf.Forms;
using TSpdf.Kernel.Exceptions;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Utils;
using TSpdf.Test;
namespace TSpdf.Forms.Xfa {
[NUnit.Framework.Category("IntegrationTest")]
public class XfaSecurityTest : ExtendedTSpdfTest {
private static readonly String SOURCE_FOLDER = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/forms/xfa/XfaSecurityTest/";
private static readonly String DTD_EXCEPTION_MESSAGE = ExceptionTestUtil.GetDoctypeIsDisallowedExceptionMessage
();
private const String XFA_WITH_DTD_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<!DOCTYPE foo>\n"
+ "\n" + "<xdp:xdp xmlns:xdp=\"http://ns.adobe.com/xdp/\" timeStamp=\"2018-03-08T12:50:19Z\"\n" + " uuid=\"36ac5111-55c5-4172-b0c1-0cbd783e2fcf\">\n"
+ "</xdp:xdp>\n";
[NUnit.Framework.SetUp]
public virtual void ResetXmlParserFactoryToDefault() {
XmlProcessorCreator.SetXmlParserFactory(null);
}
[NUnit.Framework.Test]
public virtual void XfaExternalFileTest() {
XfaSecurityExceptionTest(SOURCE_FOLDER + "xfaExternalFile.pdf");
}
[NUnit.Framework.Test]
public virtual void XfaExternalConnectionTest() {
XfaSecurityExceptionTest(SOURCE_FOLDER + "xfaExternalConnection.pdf");
}
[NUnit.Framework.Test]
public virtual void XfaInternalEntityTest() {
XfaSecurityExceptionTest(SOURCE_FOLDER + "xfaInternalEntity.pdf");
}
[NUnit.Framework.Test]
public virtual void XfaExternalFileCustomFactoryTest() {
String inFileName = SOURCE_FOLDER + "xfaExternalFile.pdf";
XmlProcessorCreator.SetXmlParserFactory(new SecurityTestXmlParserFactory());
using (PdfDocument pdfDoc = new PdfDocument(new PdfReader(inFileName), new PdfWriter(new MemoryStream()))) {
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => PdfAcroForm.GetAcroForm(pdfDoc, true
));
NUnit.Framework.Assert.AreEqual(ExceptionTestUtil.GetXxeTestMessage(), e.Message);
}
}
[NUnit.Framework.Test]
public virtual void XfaExternalFileXfaFormTest() {
String inFileName = SOURCE_FOLDER + "xfaExternalFile.pdf";
using (PdfDocument pdfDoc = new PdfDocument(new PdfReader(inFileName))) {
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => new XfaForm(pdfDoc));
NUnit.Framework.Assert.AreEqual(DTD_EXCEPTION_MESSAGE, e.Message);
}
}
[NUnit.Framework.Test]
public virtual void XfaWithDtdXfaFormTest() {
using (Stream inputStream = new MemoryStream(XFA_WITH_DTD_XML.GetBytes(System.Text.Encoding.UTF8))) {
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => new XfaForm(inputStream));
NUnit.Framework.Assert.AreEqual(DTD_EXCEPTION_MESSAGE, e.Message);
}
}
[NUnit.Framework.Test]
public virtual void FillXfaFormTest() {
using (Stream inputStream = new MemoryStream(XFA_WITH_DTD_XML.GetBytes(System.Text.Encoding.UTF8))) {
XfaForm form = new XfaForm();
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => form.FillXfaForm(inputStream, true)
);
NUnit.Framework.Assert.AreEqual(DTD_EXCEPTION_MESSAGE, e.Message);
}
}
private void XfaSecurityExceptionTest(String inputFileName) {
using (PdfDocument pdfDoc = new PdfDocument(new PdfReader(inputFileName), new PdfWriter(new MemoryStream()
))) {
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => PdfAcroForm.GetAcroForm(pdfDoc, true
));
NUnit.Framework.Assert.AreEqual(DTD_EXCEPTION_MESSAGE, e.Message);
}
}
}
}

View File

@@ -0,0 +1,63 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System.IO;
using System.Xml;
using TSpdf.Kernel.Exceptions;
using TSpdf.Kernel.Utils;
namespace TSpdf.Forms.Xfdf
{
public class SecurityTestXmlParserFactory : IXmlParserFactory
{
public XmlReader CreateXmlReaderInstance(Stream stream, XmlParserContext inputContext)
{
throw new PdfException("Test message");
}
public XmlReader CreateXmlReaderInstance(TextReader textReader)
{
throw new PdfException("Test message");
}
}
}

View File

@@ -0,0 +1,65 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System.Collections.Generic;
using System.IO;
using TSpdf.Forms;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Pdf.Annot;
using TSpdf.Test;
using TSpdf.Test.Attributes;
namespace TSpdf.Forms.Xfdf {
[NUnit.Framework.Category("UnitTest")]
public class XfdfReaderUnitTest : ExtendedTSpdfTest {
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.XFDF_NO_F_OBJECT_TO_COMPARE)]
public virtual void XfdfSquareAnnotationWithoutFringe() {
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(new MemoryStream()));
pdfDocument.AddNewPage();
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDocument, true);
AnnotObject annotObject = new AnnotObject();
annotObject.SetName(XfdfConstants.SQUARE);
annotObject.AddAttribute(new AttributeObject(XfdfConstants.PAGE, "1"));
annotObject.AddAttribute(new AttributeObject(XfdfConstants.RECT, "493.399638,559.179024,571.790235,600.679928"
));
annotObject.AddAttribute(new AttributeObject(XfdfConstants.COLOR, "#000000"));
annotObject.AddAttribute(new AttributeObject(XfdfConstants.TITLE, "Guest"));
annotObject.AddAttribute(new AttributeObject(XfdfConstants.FLAGS, "print"));
annotObject.AddAttribute(new AttributeObject(XfdfConstants.DATE, "D:20200123110420-05'00'"));
annotObject.AddAttribute(new AttributeObject(XfdfConstants.NAME, "436b0463-41e6-d3fe-b660-c3764226615b"));
annotObject.AddAttribute(new AttributeObject(XfdfConstants.CREATION_DATE, "D:20200123110418-05'00'"));
annotObject.AddAttribute(new AttributeObject(XfdfConstants.SUBJECT, "Rectangle"));
AnnotsObject annotsObject = new AnnotsObject();
annotsObject.AddAnnot(annotObject);
XfdfObject xfdfObject = new XfdfObject();
xfdfObject.SetAnnots(annotsObject);
XfdfReader xfdfReader = new XfdfReader();
xfdfReader.MergeXfdfIntoPdf(xfdfObject, pdfDocument, "smth");
IList<PdfAnnotation> annotations = pdfDocument.GetPage(1).GetAnnotations();
NUnit.Framework.Assert.IsNotNull(annotations);
NUnit.Framework.Assert.AreEqual(1, annotations.Count);
NUnit.Framework.Assert.AreEqual(PdfName.Square, annotations[0].GetSubtype());
pdfDocument.Close();
}
}
}

View File

@@ -0,0 +1,77 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.IO;
using TSpdf.Kernel.Exceptions;
using TSpdf.Kernel.Utils;
using TSpdf.Test;
namespace TSpdf.Forms.Xfdf {
[NUnit.Framework.Category("UnitTest")]
public class XfdfSecurityTest : ExtendedTSpdfTest {
private const String XFDF_WITH_XXE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n" + "<!DOCTYPE foo [ <!ENTITY xxe SYSTEM \"xxe-data.txt\" > ]>\n"
+ "<xfdf xmlns=\"http://ns.adobe.com/xfdf/\" xml:space=\"preserve\">\n" + "<f href=\"something.pdf\"/>\n"
+ "<fields\n" + "><field name=\"Input field\"\n" + "><value\n" + ">ABCDEFGH&xxe;</value\n" + "></field\n"
+ "></fields\n" + ">\n" + "<ids/>\n" + "</xfdf>";
[NUnit.Framework.Test]
public virtual void XxeVulnerabilityXfdfTest() {
XmlProcessorCreator.SetXmlParserFactory(null);
using (Stream inputStream = new MemoryStream(XFDF_WITH_XXE.GetBytes(System.Text.Encoding.UTF8))) {
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => XfdfFileUtils.CreateXfdfDocumentFromStream
(inputStream));
NUnit.Framework.Assert.AreEqual(ExceptionTestUtil.GetDoctypeIsDisallowedExceptionMessage(), e.Message);
}
}
[NUnit.Framework.Test]
public virtual void XxeVulnerabilityXfdfCustomXmlParserTest() {
XmlProcessorCreator.SetXmlParserFactory(new SecurityTestXmlParserFactory());
using (Stream inputStream = new MemoryStream(XFDF_WITH_XXE.GetBytes(System.Text.Encoding.UTF8))) {
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => XfdfFileUtils.CreateXfdfDocumentFromStream
(inputStream));
NUnit.Framework.Assert.AreEqual("Test message", e.Message);
}
}
}
}

View File

@@ -0,0 +1,75 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System.Collections.Generic;
using System.Xml;
using TSpdf.Test;
namespace TSpdf.Forms.Xfdf {
[NUnit.Framework.Category("UnitTest")]
public class XfdfWriterUnitTest : ExtendedTSpdfTest {
[NUnit.Framework.Test]
public virtual void FieldEmptyValueUnitTest() {
XmlDocument document = XfdfFileUtils.CreateNewXfdfDocument();
XmlElement fields = document.CreateElement("fields");
document.AppendChild(fields);
FieldObject fieldObject = new FieldObject();
fieldObject.SetName("testname");
fieldObject.SetValue("");
IList<FieldObject> fieldList = new List<FieldObject>();
XfdfWriter.AddField(fieldObject, fields, document, fieldList);
XmlNode childOfFields = fields.FirstChild;
NUnit.Framework.Assert.IsNotNull(childOfFields);
NUnit.Framework.Assert.IsNull(childOfFields.FirstChild);
}
[NUnit.Framework.Test]
public virtual void FieldNullValueUnitTest() {
XmlDocument document = XfdfFileUtils.CreateNewXfdfDocument();
XmlElement fields = document.CreateElement("fields");
document.AppendChild(fields);
FieldObject fieldObject = new FieldObject();
fieldObject.SetName("testname");
IList<FieldObject> fieldList = new List<FieldObject>();
XfdfWriter.AddField(fieldObject, fields, document, fieldList);
XmlNode childOfFields = fields.FirstChild;
NUnit.Framework.Assert.IsNotNull(childOfFields);
NUnit.Framework.Assert.IsNull(childOfFields.FirstChild);
}
[NUnit.Framework.Test]
public virtual void FieldWithValueUnitTest() {
XmlDocument document = XfdfFileUtils.CreateNewXfdfDocument();
XmlElement fields = document.CreateElement("fields");
document.AppendChild(fields);
FieldObject fieldObject = new FieldObject();
fieldObject.SetName("testname");
fieldObject.SetValue("testValue");
IList<FieldObject> fieldList = new List<FieldObject>();
XfdfWriter.AddField(fieldObject, fields, document, fieldList);
XmlNode childOfFields = fields.FirstChild;
NUnit.Framework.Assert.IsNotNull(childOfFields);
NUnit.Framework.Assert.AreEqual("value", childOfFields.FirstChild.Name);
NUnit.Framework.Assert.AreEqual("testValue", childOfFields.FirstChild.InnerText);
}
}
}

View File

@@ -0,0 +1,52 @@
%PDF-1.7
%<25><><EFBFBD><EFBFBD>
5 0 obj
<</Filter/FlateDecode/Length 144>>stream
x<EFBFBD>M<EFBFBD><EFBFBD>
<EFBFBD>0<10><><EFBFBD>sԃq<D483><71>ϫ`=W<><06>%E<><5F>*<2A>2<EFBFBD>÷<1B>є<EFBFBD>hfW<66>̌<12>ˀ<EFBFBD><CB80>ö<EFBFBD>Ԇ<EFBFBD><D486>-h<>RYK<59>bU<62><03>k<EFBFBD>[<5B><>s\<5C>MT<4D>L<EFBFBD>NG<4E>\<5C>f<EFBFBD><66><15><><EFBFBD><EFBFBD><EFBFBD>z<EFBFBD>pg<><67><EFBFBD><EFBFBD>ά*sΖ<73> e<><65><EFBFBD><EFBFBD>}<7D><><EFBFBD>/~D<>7.Z-J
endstream
endobj
4 0 obj
<</Annots[7 0 R]/Contents 5 0 R/MediaBox[0 0 298 420]/Parent 2 0 R/Resources<</Font<</F1 6 0 R>>>>/Rotate 180/TrimBox[0 0 298 420]/Type/Page>>
endobj
1 0 obj
<</AcroForm 13 0 R/Pages 2 0 R/Type/Catalog>>
endobj
3 0 obj
<</CreationDate(D:20160913114847+02'00')/ModDate(D:20160913114847+02'00')/Producer(TSpdf<64> 7.0.1-SNAPSHOT <20>2000-2016 TSpdf \(1.0\))>>
endobj
10 0 obj
<</BaseFont/Helvetica/Encoding/WinAnsiEncoding/Subtype/Type1/Type/Font>>
endobj
6 0 obj
<</BaseFont/Helvetica/Encoding/WinAnsiEncoding/Subtype/Type1/Type/Font>>
endobj
2 0 obj
<</Count 1/Kids[4 0 R]/Type/Pages>>
endobj
7 0 obj
<</DA(/F1 12 Tf )/FT/Tx/Ff 0/MK<</R 0>>/P 4 0 R/Rect[150 150 200 300]/Subtype/Widget/T(testField)/V()>>
endobj
13 0 obj
<</DA(/Helv 0 Tf 0 g )/Fields[7 0 R]>>
endobj
xref
0 8
0000000000 65535 f
0000000384 00000 n
0000000788 00000 n
0000000445 00000 n
0000000226 00000 n
0000000015 00000 n
0000000700 00000 n
0000000839 00000 n
10 1
0000000611 00000 n
13 1
0000000958 00000 n
trailer
<</ID [<43983b35dae5f6d5949bde1a5324b96d><43983b35dae5f6d5949bde1a5324b96d>]/Info 3 0 R/Root 1 0 R/Size 14>>
%TSpdf-7.0.1-SNAPSHOT
startxref
1013
%%EOF

View File

@@ -0,0 +1,52 @@
%PDF-1.7
%<25><><EFBFBD><EFBFBD>
5 0 obj
<</Filter/FlateDecode/Length 144>>stream
x<EFBFBD>M<EFBFBD><EFBFBD>
<EFBFBD>0<10><><EFBFBD>sԃq<D483><71>ϫ`=W<><06>%E<><5F>*<2A>2<EFBFBD>÷<1B>є<EFBFBD>hfW<66>̌<12>ˀ<EFBFBD><CB80>ö<EFBFBD>Ԇ<EFBFBD><D486>-h<>RYK<59>bU<62><03>k<EFBFBD>[<5B><>s\<5C>MT<4D>L<EFBFBD>NG<4E>\<5C>f<EFBFBD><66><15><><EFBFBD><EFBFBD><EFBFBD>z<EFBFBD>pg<><67><EFBFBD><EFBFBD>ά*sΖ<73> e<><65><EFBFBD><EFBFBD>}<7D><><EFBFBD>/~D<>7.Z-J
endstream
endobj
4 0 obj
<</Annots[7 0 R]/Contents 5 0 R/MediaBox[0 0 298 420]/Parent 2 0 R/Resources<</Font<</F1 6 0 R>>>>/Rotate 180/TrimBox[0 0 298 420]/Type/Page>>
endobj
1 0 obj
<</AcroForm 13 0 R/Pages 2 0 R/Type/Catalog>>
endobj
3 0 obj
<</CreationDate(D:20160913114847+02'00')/ModDate(D:20160913114847+02'00')/Producer(TSpdf<64> 7.0.1-SNAPSHOT <20>2000-2016 TSpdf \(1.0\))>>
endobj
10 0 obj
<</BaseFont/Helvetica/Encoding/WinAnsiEncoding/Subtype/Type1/Type/Font>>
endobj
6 0 obj
<</BaseFont/Helvetica/Encoding/WinAnsiEncoding/Subtype/Type1/Type/Font>>
endobj
2 0 obj
<</Count 1/Kids[4 0 R]/Type/Pages>>
endobj
7 0 obj
<</DA(/F1 12 Tf )/FT/Tx/Ff 0/MK<</R 180>>/P 4 0 R/Rect[150 150 200 300]/Subtype/Widget/T(testField)/V()>>
endobj
13 0 obj
<</DA(/Helv 0 Tf 0 g )/Fields[7 0 R]>>
endobj
xref
0 8
0000000000 65535 f
0000000384 00000 n
0000000788 00000 n
0000000445 00000 n
0000000226 00000 n
0000000015 00000 n
0000000700 00000 n
0000000839 00000 n
10 1
0000000611 00000 n
13 1
0000000960 00000 n
trailer
<</ID [<ecfcc4a41a152f26e15f136cb84ac2fc><ecfcc4a41a152f26e15f136cb84ac2fc>]/Info 3 0 R/Root 1 0 R/Size 14>>
%TSpdf-7.0.1-SNAPSHOT
startxref
1015
%%EOF

View File

@@ -0,0 +1,52 @@
%PDF-1.7
%<25><><EFBFBD><EFBFBD>
5 0 obj
<</Filter/FlateDecode/Length 144>>stream
x<EFBFBD>M<EFBFBD><EFBFBD>
<EFBFBD>0<10><><EFBFBD>sԃq<D483><71>ϫ`=W<><06>%E<><5F>*<2A>2<EFBFBD>÷<1B>є<EFBFBD>hfW<66>̌<12>ˀ<EFBFBD><CB80>ö<EFBFBD>Ԇ<EFBFBD><D486>-h<>RYK<59>bU<62><03>k<EFBFBD>[<5B><>s\<5C>MT<4D>L<EFBFBD>NG<4E>\<5C>f<EFBFBD><66><15><><EFBFBD><EFBFBD><EFBFBD>z<EFBFBD>pg<><67><EFBFBD><EFBFBD>ά*sΖ<73> e<><65><EFBFBD><EFBFBD>}<7D><><EFBFBD>/~D<>7.Z-J
endstream
endobj
4 0 obj
<</Annots[7 0 R]/Contents 5 0 R/MediaBox[0 0 298 420]/Parent 2 0 R/Resources<</Font<</F1 6 0 R>>>>/Rotate 180/TrimBox[0 0 298 420]/Type/Page>>
endobj
1 0 obj
<</AcroForm 13 0 R/Pages 2 0 R/Type/Catalog>>
endobj
3 0 obj
<</CreationDate(D:20160913114847+02'00')/ModDate(D:20160913114847+02'00')/Producer(TSpdf<64> 7.0.1-SNAPSHOT <20>2000-2016 TSpdf \(1.0\))>>
endobj
10 0 obj
<</BaseFont/Helvetica/Encoding/WinAnsiEncoding/Subtype/Type1/Type/Font>>
endobj
6 0 obj
<</BaseFont/Helvetica/Encoding/WinAnsiEncoding/Subtype/Type1/Type/Font>>
endobj
2 0 obj
<</Count 1/Kids[4 0 R]/Type/Pages>>
endobj
7 0 obj
<</DA(/F1 12 Tf )/FT/Tx/Ff 0/MK<</R 270>>/P 4 0 R/Rect[150 150 200 300]/Subtype/Widget/T(testField)/V()>>
endobj
13 0 obj
<</DA(/Helv 0 Tf 0 g )/Fields[7 0 R]>>
endobj
xref
0 8
0000000000 65535 f
0000000384 00000 n
0000000788 00000 n
0000000445 00000 n
0000000226 00000 n
0000000015 00000 n
0000000700 00000 n
0000000839 00000 n
10 1
0000000611 00000 n
13 1
0000000960 00000 n
trailer
<</ID [<8c809aa1c2abd5b4ef96d306a5cc7c29><8c809aa1c2abd5b4ef96d306a5cc7c29>]/Info 3 0 R/Root 1 0 R/Size 14>>
%TSpdf-7.0.1-SNAPSHOT
startxref
1015
%%EOF

View File

@@ -0,0 +1,52 @@
%PDF-1.7
%<25><><EFBFBD><EFBFBD>
5 0 obj
<</Filter/FlateDecode/Length 144>>stream
x<EFBFBD>M<EFBFBD><EFBFBD>
<EFBFBD>0<10><><EFBFBD>sԃq<D483><71>ϫ`=W<><06>%E<><5F>*<2A>2<EFBFBD>÷<1B>є<EFBFBD>hfW<66>̌<12>ˀ<EFBFBD><CB80>ö<EFBFBD>Ԇ<EFBFBD><D486>-h<>RYK<59>bU<62><03>k<EFBFBD>[<5B><>s\<5C>MT<4D>L<EFBFBD>NG<4E>\<5C>f<EFBFBD><66><15><><EFBFBD><EFBFBD><EFBFBD>z<EFBFBD>pg<><67><EFBFBD><EFBFBD>ά*sΖ<73> e<><65><EFBFBD><EFBFBD>}<7D><><EFBFBD>/~D<>7.Z-J
endstream
endobj
4 0 obj
<</Annots[7 0 R]/Contents 5 0 R/MediaBox[0 0 298 420]/Parent 2 0 R/Resources<</Font<</F1 6 0 R>>>>/Rotate 180/TrimBox[0 0 298 420]/Type/Page>>
endobj
1 0 obj
<</AcroForm 13 0 R/Pages 2 0 R/Type/Catalog>>
endobj
3 0 obj
<</CreationDate(D:20160913114847+02'00')/ModDate(D:20160913114847+02'00')/Producer(TSpdf<64> 7.0.1-SNAPSHOT <20>2000-2016 TSpdf \(1.0\))>>
endobj
6 0 obj
<</BaseFont/Helvetica/Encoding/WinAnsiEncoding/Subtype/Type1/Type/Font>>
endobj
10 0 obj
<</BaseFont/Helvetica/Encoding/WinAnsiEncoding/Subtype/Type1/Type/Font>>
endobj
2 0 obj
<</Count 1/Kids[4 0 R]/Type/Pages>>
endobj
7 0 obj
<</DA(/F1 12 Tf )/FT/Tx/Ff 0/MK<</R 90>>/P 4 0 R/Rect[150 150 200 300]/Subtype/Widget/T(testField)/V()>>
endobj
13 0 obj
<</DA(/Helv 0 Tf 0 g )/Fields[7 0 R]>>
endobj
xref
0 8
0000000000 65535 f
0000000384 00000 n
0000000788 00000 n
0000000445 00000 n
0000000226 00000 n
0000000015 00000 n
0000000611 00000 n
0000000839 00000 n
10 1
0000000699 00000 n
13 1
0000000959 00000 n
trailer
<</ID [<2c95f64145d0349af80b3098b465dba7><2c95f64145d0349af80b3098b465dba7>]/Info 3 0 R/Root 1 0 R/Size 14>>
%TSpdf-7.0.1-SNAPSHOT
startxref
1014
%%EOF

View File

@@ -0,0 +1,53 @@
%PDF-1.7
%<25><><EFBFBD><EFBFBD>
5 0 obj
<</Filter/FlateDecode/Length 143>>stream
x<EFBFBD>MLK
<EFBFBD>0<14><>)f<> c^bR<62><15><>jn`[PR<50>Z<EFBFBD><5A>&Z<> <0C><>0<EFBFBD>h
WBM#<23>*<2A>cx<63>1`<17><>$y<><0E>S|<7C><>04XT<58>{<7B><><EFBFBD>Ɔc<C686><18><><EFBFBD>}@<40>0<EFBFBD><19>ĥ<><C4A5><EFBFBD><EFBFBD><EFBFBD>Z3<5A><33><EFBFBD><7F>8<EFBFBD>"N<><4E><EFBFBD> <09>XU8N<38><4E>^<5E><>?<3F>{<7B>dnL<6E>_<EFBFBD><5F> <04>-
endstream
endobj
4 0 obj
<</Annots[7 0 R]/Contents 5 0 R/MediaBox[0 0 298 420]/Parent 2 0 R/Resources<</Font<</F1 6 0 R>>>>/Rotate 90/TrimBox[0 0 298 420]/Type/Page>>
endobj
1 0 obj
<</AcroForm 13 0 R/Pages 2 0 R/Type/Catalog>>
endobj
3 0 obj
<</CreationDate(D:20160913114846+02'00')/ModDate(D:20160913114846+02'00')/Producer(TSpdf<64> 7.0.1-SNAPSHOT <20>2000-2016 TSpdf \(1.0\))>>
endobj
10 0 obj
<</BaseFont/Helvetica/Encoding/WinAnsiEncoding/Subtype/Type1/Type/Font>>
endobj
6 0 obj
<</BaseFont/Helvetica/Encoding/WinAnsiEncoding/Subtype/Type1/Type/Font>>
endobj
2 0 obj
<</Count 1/Kids[4 0 R]/Type/Pages>>
endobj
7 0 obj
<</DA(/F1 12 Tf )/FT/Tx/Ff 0/MK<</R 0>>/P 4 0 R/Rect[150 150 200 300]/Subtype/Widget/T(testField)/V()>>
endobj
13 0 obj
<</DA(/Helv 0 Tf 0 g )/Fields[7 0 R]>>
endobj
xref
0 8
0000000000 65535 f
0000000382 00000 n
0000000786 00000 n
0000000443 00000 n
0000000225 00000 n
0000000015 00000 n
0000000698 00000 n
0000000837 00000 n
10 1
0000000609 00000 n
13 1
0000000956 00000 n
trailer
<</ID [<79bdf0a51871f1bf33b7d3c297cbec23><79bdf0a51871f1bf33b7d3c297cbec23>]/Info 3 0 R/Root 1 0 R/Size 14>>
%TSpdf-7.0.1-SNAPSHOT
startxref
1011
%%EOF

View File

@@ -0,0 +1,53 @@
%PDF-1.7
%<25><><EFBFBD><EFBFBD>
5 0 obj
<</Filter/FlateDecode/Length 143>>stream
x<EFBFBD>MLK
<EFBFBD>0<14><>)f<> c^bR<62><15><>jn`[PR<50>Z<EFBFBD><5A>&Z<> <0C><>0<EFBFBD>h
WBM#<23>*<2A>cx<63>1`<17><>$y<><0E>S|<7C><>04XT<58>{<7B><><EFBFBD>Ɔc<C686><18><><EFBFBD>}@<40>0<EFBFBD><19>ĥ<><C4A5><EFBFBD><EFBFBD><EFBFBD>Z3<5A><33><EFBFBD><7F>8<EFBFBD>"N<><4E><EFBFBD> <09>XU8N<38><4E>^<5E><>?<3F>{<7B>dnL<6E>_<EFBFBD><5F> <04>-
endstream
endobj
4 0 obj
<</Annots[7 0 R]/Contents 5 0 R/MediaBox[0 0 298 420]/Parent 2 0 R/Resources<</Font<</F1 6 0 R>>>>/Rotate 90/TrimBox[0 0 298 420]/Type/Page>>
endobj
1 0 obj
<</AcroForm 13 0 R/Pages 2 0 R/Type/Catalog>>
endobj
3 0 obj
<</CreationDate(D:20160913114846+02'00')/ModDate(D:20160913114846+02'00')/Producer(TSpdf<64> 7.0.1-SNAPSHOT <20>2000-2016 TSpdf \(1.0\))>>
endobj
10 0 obj
<</BaseFont/Helvetica/Encoding/WinAnsiEncoding/Subtype/Type1/Type/Font>>
endobj
6 0 obj
<</BaseFont/Helvetica/Encoding/WinAnsiEncoding/Subtype/Type1/Type/Font>>
endobj
2 0 obj
<</Count 1/Kids[4 0 R]/Type/Pages>>
endobj
7 0 obj
<</DA(/F1 12 Tf )/FT/Tx/Ff 0/MK<</R 180>>/P 4 0 R/Rect[150 150 200 300]/Subtype/Widget/T(testField)/V()>>
endobj
13 0 obj
<</DA(/Helv 0 Tf 0 g )/Fields[7 0 R]>>
endobj
xref
0 8
0000000000 65535 f
0000000382 00000 n
0000000786 00000 n
0000000443 00000 n
0000000225 00000 n
0000000015 00000 n
0000000698 00000 n
0000000837 00000 n
10 1
0000000609 00000 n
13 1
0000000958 00000 n
trailer
<</ID [<ea470f3552491790df9b89b9d14f1ebe><ea470f3552491790df9b89b9d14f1ebe>]/Info 3 0 R/Root 1 0 R/Size 14>>
%TSpdf-7.0.1-SNAPSHOT
startxref
1013
%%EOF

View File

@@ -0,0 +1,53 @@
%PDF-1.7
%<25><><EFBFBD><EFBFBD>
5 0 obj
<</Filter/FlateDecode/Length 143>>stream
x<EFBFBD>MLK
<EFBFBD>0<14><>)f<> c^bR<62><15><>jn`[PR<50>Z<EFBFBD><5A>&Z<> <0C><>0<EFBFBD>h
WBM#<23>*<2A>cx<63>1`<17><>$y<><0E>S|<7C><>04XT<58>{<7B><><EFBFBD>Ɔc<C686><18><><EFBFBD>}@<40>0<EFBFBD><19>ĥ<><C4A5><EFBFBD><EFBFBD><EFBFBD>Z3<5A><33><EFBFBD><7F>8<EFBFBD>"N<><4E><EFBFBD> <09>XU8N<38><4E>^<5E><>?<3F>{<7B>dnL<6E>_<EFBFBD><5F> <04>-
endstream
endobj
4 0 obj
<</Annots[7 0 R]/Contents 5 0 R/MediaBox[0 0 298 420]/Parent 2 0 R/Resources<</Font<</F1 6 0 R>>>>/Rotate 90/TrimBox[0 0 298 420]/Type/Page>>
endobj
1 0 obj
<</AcroForm 13 0 R/Pages 2 0 R/Type/Catalog>>
endobj
3 0 obj
<</CreationDate(D:20160913114846+02'00')/ModDate(D:20160913114846+02'00')/Producer(TSpdf<64> 7.0.1-SNAPSHOT <20>2000-2016 TSpdf \(1.0\))>>
endobj
6 0 obj
<</BaseFont/Helvetica/Encoding/WinAnsiEncoding/Subtype/Type1/Type/Font>>
endobj
10 0 obj
<</BaseFont/Helvetica/Encoding/WinAnsiEncoding/Subtype/Type1/Type/Font>>
endobj
2 0 obj
<</Count 1/Kids[4 0 R]/Type/Pages>>
endobj
7 0 obj
<</DA(/F1 12 Tf )/FT/Tx/Ff 0/MK<</R 270>>/P 4 0 R/Rect[150 150 200 300]/Subtype/Widget/T(testField)/V()>>
endobj
13 0 obj
<</DA(/Helv 0 Tf 0 g )/Fields[7 0 R]>>
endobj
xref
0 8
0000000000 65535 f
0000000382 00000 n
0000000786 00000 n
0000000443 00000 n
0000000225 00000 n
0000000015 00000 n
0000000609 00000 n
0000000837 00000 n
10 1
0000000697 00000 n
13 1
0000000958 00000 n
trailer
<</ID [<d9fdef26b824eaaf66900c2e0db038f3><d9fdef26b824eaaf66900c2e0db038f3>]/Info 3 0 R/Root 1 0 R/Size 14>>
%TSpdf-7.0.1-SNAPSHOT
startxref
1013
%%EOF

View File

@@ -0,0 +1,53 @@
%PDF-1.7
%<25><><EFBFBD><EFBFBD>
5 0 obj
<</Filter/FlateDecode/Length 143>>stream
x<EFBFBD>MLK
<EFBFBD>0<14><>)f<> c^bR<62><15><>jn`[PR<50>Z<EFBFBD><5A>&Z<> <0C><>0<EFBFBD>h
WBM#<23>*<2A>cx<63>1`<17><>$y<><0E>S|<7C><>04XT<58>{<7B><><EFBFBD>Ɔc<C686><18><><EFBFBD>}@<40>0<EFBFBD><19>ĥ<><C4A5><EFBFBD><EFBFBD><EFBFBD>Z3<5A><33><EFBFBD><7F>8<EFBFBD>"N<><4E><EFBFBD> <09>XU8N<38><4E>^<5E><>?<3F>{<7B>dnL<6E>_<EFBFBD><5F> <04>-
endstream
endobj
4 0 obj
<</Annots[7 0 R]/Contents 5 0 R/MediaBox[0 0 298 420]/Parent 2 0 R/Resources<</Font<</F1 6 0 R>>>>/Rotate 90/TrimBox[0 0 298 420]/Type/Page>>
endobj
1 0 obj
<</AcroForm 13 0 R/Pages 2 0 R/Type/Catalog>>
endobj
3 0 obj
<</CreationDate(D:20160913114846+02'00')/ModDate(D:20160913114846+02'00')/Producer(TSpdf<64> 7.0.1-SNAPSHOT <20>2000-2016 TSpdf \(1.0\))>>
endobj
6 0 obj
<</BaseFont/Helvetica/Encoding/WinAnsiEncoding/Subtype/Type1/Type/Font>>
endobj
10 0 obj
<</BaseFont/Helvetica/Encoding/WinAnsiEncoding/Subtype/Type1/Type/Font>>
endobj
2 0 obj
<</Count 1/Kids[4 0 R]/Type/Pages>>
endobj
7 0 obj
<</DA(/F1 12 Tf )/FT/Tx/Ff 0/MK<</R 90>>/P 4 0 R/Rect[150 150 200 300]/Subtype/Widget/T(testField)/V()>>
endobj
13 0 obj
<</DA(/Helv 0 Tf 0 g )/Fields[7 0 R]>>
endobj
xref
0 8
0000000000 65535 f
0000000382 00000 n
0000000786 00000 n
0000000443 00000 n
0000000225 00000 n
0000000015 00000 n
0000000609 00000 n
0000000837 00000 n
10 1
0000000697 00000 n
13 1
0000000957 00000 n
trailer
<</ID [<361c0b1ae02970fe7ee43c9a39d991fc><361c0b1ae02970fe7ee43c9a39d991fc>]/Info 3 0 R/Root 1 0 R/Size 14>>
%TSpdf-7.0.1-SNAPSHOT
startxref
1012
%%EOF

View File

@@ -0,0 +1,74 @@
%PDF-1.7
%<25><><EFBFBD><EFBFBD>
13 0 obj
<</Length 0>>stream
endstream
endobj
12 0 obj
<</Annots[5 0 R]/Contents 13 0 R/MediaBox[0 0 595 842]/Parent 2 0 R/Resources<<>>/TrimBox[0 0 595 842]/Type/Page>>
endobj
1 0 obj
<</AcroForm 4 0 R/Pages 2 0 R/Type/Catalog>>
endobj
3 0 obj
<</CreationDate(D:20191105101604+03'00')/ModDate(D:20191105101659+03'00')/Producer(TSpdf<64> 7.1.9-SNAPSHOT <20>2000-2019 TSpdf \(1.0\); modified using TSpdf<64> 7.1.5-SNAPSHOT <20>2000-2019 TSpdf \(1.0\))>>
endobj
2 0 obj
<</Count 1/Kids[12 0 R]/Type/Pages>>
endobj
4 0 obj
<</DR<</Font<</F1 6 0 R>>>>/Fields[5 0 R]>>
endobj
5 0 obj
<</AP<</N 14 0 R>>/BS<</W 2>>/DA(/F1 12 Tf)/FT/Tx/Ff 0/MK<</BC[0 0 0]>>/P 12 0 R/Rect[100 730 200 750]/Subtype/Widget/T(field_1)/V(TSpdf)>>
endobj
6 0 obj
<</BaseFont/Helvetica/Encoding/WinAnsiEncoding/Subtype/Type1/Type/Font>>
endobj
14 0 obj
<</BBox[0 0 100 20]/Length 91/Matrix[1 0 0 1 0 0]/Resources<</Font<</F1 6 0 R>>>>/Type/XObject>>stream
q
0 0 0 RG
2 w
0 0 100 20 re
S
Q
/Tx BMC
q
n
q
BT
/F1 12 Tf
2 6.32 Td
(TSpdf)Tj
ET
Q
Q
EMC
endstream
endobj
xref
0 15
0000000007 65535 f
0000000193 00000 n
0000000500 00000 n
0000000253 00000 n
0000000552 00000 n
0000000611 00000 n
0000000766 00000 n
0000000008 00001 f
0000000009 00001 f
0000000010 00001 f
0000000011 00001 f
0000000000 00001 f
0000000062 00000 n
0000000015 00000 n
0000000854 00000 n
trailer
<</ID [<b06b6b8e38ab321d960f649508ea23f0><0955e128c1ced4263dc791c426676d33>]/Info 3 0 R/Root 1 0 R/Size 15>>
%TSpdf-7.1.5-SNAPSHOT
startxref
1075
%%EOF

Some files were not shown because too many files have changed in this diff Show More