Agregar archivos de proyecto.
This commit is contained in:
24
TSpdf.tests/TSpdf.pdfa.tests/Properties/AssemblyInfo.cs
Normal file
24
TSpdf.tests/TSpdf.pdfa.tests/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: AssemblyTitle("TSpdf.Pdfa.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("b7c0e021-71ac-4c97-9a51-8356f1bd53c7")]
|
||||
|
||||
[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
|
||||
64
TSpdf.tests/TSpdf.pdfa.tests/TSpdf.pdfa.tests.csproj
Normal file
64
TSpdf.tests/TSpdf.pdfa.tests/TSpdf.pdfa.tests.csproj
Normal file
@@ -0,0 +1,64 @@
|
||||
<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.pdfa.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" />
|
||||
</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.barcodes\TSpdf.barcodes.csproj" />
|
||||
<ProjectReference Include="..\..\TSpdf\TSpdf.io\TSpdf.io.csproj" />
|
||||
<ProjectReference Include="..\..\TSpdf\TSpdf.kernel\TSpdf.kernel.csproj" />
|
||||
<ProjectReference Include="..\..\TSpdf\TSpdf.pdfa\TSpdf.pdfa.csproj" />
|
||||
<ProjectReference Include="..\..\TSpdf\TSpdf.pdftest\TSpdf.pdftest.csproj" />
|
||||
<ProjectReference Include="..\..\TSpdf\TSpdf.forms\TSpdf.forms.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
</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>
|
||||
BIN
TSpdf.tests/TSpdf.pdfa.tests/TSpdf.snk
Normal file
BIN
TSpdf.tests/TSpdf.pdfa.tests/TSpdf.snk
Normal file
Binary file not shown.
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
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.IO.Source;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Utils;
|
||||
using TSpdf.Pdfa.Exceptions;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfA1AcroFormCheckTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
public static readonly String cmpFolder = sourceFolder + "cmp/PdfA1AcroFormCheckTest/";
|
||||
|
||||
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/PdfA1AcroFormCheckTest/";
|
||||
|
||||
[NUnit.Framework.OneTimeSetUp]
|
||||
public static void BeforeClass() {
|
||||
CreateOrClearDestinationFolder(destinationFolder);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AcroFormCheck01() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary acroForm = new PdfDictionary();
|
||||
acroForm.Put(PdfName.NeedAppearances, new PdfBoolean(true));
|
||||
doc.GetCatalog().Put(PdfName.AcroForm, acroForm);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.NEEDAPPEARANCES_FLAG_OF_THE_INTERACTIVE_FORM_DICTIONARY_SHALL_EITHER_NOT_BE_PRESENTED_OR_SHALL_BE_FALSE
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AcroFormCheck02() {
|
||||
String outPdf = destinationFolder + "pdfA1b_acroFormCheck02.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA1b_acroFormCheck02.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary acroForm = new PdfDictionary();
|
||||
acroForm.Put(PdfName.NeedAppearances, new PdfBoolean(false));
|
||||
doc.GetCatalog().Put(PdfName.AcroForm, acroForm);
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AcroFormCheck03() {
|
||||
String outPdf = destinationFolder + "pdfA1b_acroFormCheck03.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA1b_acroFormCheck03.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary acroForm = new PdfDictionary();
|
||||
doc.GetCatalog().Put(PdfName.AcroForm, acroForm);
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
private void CompareResult(String outPdf, String cmpPdf) {
|
||||
String result = new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_");
|
||||
if (result != null) {
|
||||
NUnit.Framework.Assert.Fail(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
220
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfA1ActionCheckTest.cs
Normal file
220
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfA1ActionCheckTest.cs
Normal file
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
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.Commons.Utils;
|
||||
using TSpdf.IO.Source;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Pdf.Action;
|
||||
using TSpdf.Pdfa.Exceptions;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfA1ActionCheckTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ActionCheck01() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary openActions = new PdfDictionary();
|
||||
openActions.Put(PdfName.S, PdfName.Launch);
|
||||
doc.GetCatalog().Put(PdfName.OpenAction, openActions);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException._0_ACTIONS_ARE_NOT_ALLOWED
|
||||
, PdfName.Launch.GetValue()), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ActionCheck02() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary openActions = new PdfDictionary();
|
||||
openActions.Put(PdfName.S, PdfName.Hide);
|
||||
doc.GetCatalog().Put(PdfName.OpenAction, openActions);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException._0_ACTIONS_ARE_NOT_ALLOWED
|
||||
, PdfName.Hide.GetValue()), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ActionCheck03() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary openActions = new PdfDictionary();
|
||||
openActions.Put(PdfName.S, PdfName.Sound);
|
||||
doc.GetCatalog().Put(PdfName.OpenAction, openActions);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException._0_ACTIONS_ARE_NOT_ALLOWED
|
||||
, PdfName.Sound.GetValue()), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ActionCheck04() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary openActions = new PdfDictionary();
|
||||
openActions.Put(PdfName.S, PdfName.Movie);
|
||||
doc.GetCatalog().Put(PdfName.OpenAction, openActions);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException._0_ACTIONS_ARE_NOT_ALLOWED
|
||||
, PdfName.Movie.GetValue()), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ActionCheck05() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary openActions = new PdfDictionary();
|
||||
openActions.Put(PdfName.S, PdfName.ResetForm);
|
||||
doc.GetCatalog().Put(PdfName.OpenAction, openActions);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException._0_ACTIONS_ARE_NOT_ALLOWED
|
||||
, PdfName.ResetForm.GetValue()), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ActionCheck06() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary openActions = new PdfDictionary();
|
||||
openActions.Put(PdfName.S, PdfName.ImportData);
|
||||
doc.GetCatalog().Put(PdfName.OpenAction, openActions);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException._0_ACTIONS_ARE_NOT_ALLOWED
|
||||
, PdfName.ImportData.GetValue()), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ActionCheck07() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary openActions = new PdfDictionary();
|
||||
openActions.Put(PdfName.S, PdfName.JavaScript);
|
||||
doc.GetCatalog().Put(PdfName.OpenAction, openActions);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException._0_ACTIONS_ARE_NOT_ALLOWED
|
||||
, PdfName.JavaScript.GetValue()), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ActionCheck08() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary openActions = new PdfDictionary();
|
||||
openActions.Put(PdfName.S, PdfName.Named);
|
||||
openActions.Put(PdfName.N, new PdfName("CustomName"));
|
||||
doc.GetCatalog().Put(PdfName.OpenAction, openActions);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException.NAMED_ACTION_TYPE_0_IS_NOT_ALLOWED
|
||||
, "CustomName"), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ActionCheck09() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
page.SetAdditionalAction(PdfName.C, PdfAction.CreateJavaScript("js"));
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException._0_ACTIONS_ARE_NOT_ALLOWED
|
||||
, PdfName.JavaScript.GetValue()), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ActionCheck10() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
PdfDictionary action = new PdfDictionary();
|
||||
action.Put(PdfName.S, PdfName.SetState);
|
||||
page.SetAdditionalAction(PdfName.C, new PdfAction(action));
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.DEPRECATED_SETSTATE_AND_NOOP_ACTIONS_ARE_NOT_ALLOWED
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ActionCheck11() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
doc.GetCatalog().SetAdditionalAction(PdfName.C, PdfAction.CreateJavaScript("js"));
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.A_CATALOG_DICTIONARY_SHALL_NOT_CONTAIN_AA_ENTRY,
|
||||
e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,233 @@
|
||||
/*
|
||||
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.Commons.Utils;
|
||||
using TSpdf.IO.Source;
|
||||
using TSpdf.Kernel.Geom;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Pdf.Annot;
|
||||
using TSpdf.Kernel.Utils;
|
||||
using TSpdf.Pdfa.Exceptions;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfA1AnnotationCheckTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
public static readonly String cmpFolder = sourceFolder + "cmp/PdfA1AnnotationCheckTest/";
|
||||
|
||||
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/PdfA1AnnotationCheckTest/";
|
||||
|
||||
[NUnit.Framework.OneTimeSetUp]
|
||||
public static void BeforeClass() {
|
||||
CreateOrClearDestinationFolder(destinationFolder);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AnnotationCheckTest01() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
Rectangle rect = new Rectangle(100, 100, 100, 100);
|
||||
PdfAnnotation annot = new PdfFileAttachmentAnnotation(rect);
|
||||
page.AddAnnotation(annot);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException.ANNOTATION_TYPE_0_IS_NOT_PERMITTED
|
||||
, PdfName.FileAttachment.GetValue()), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AnnotationCheckTest02() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
Rectangle rect = new Rectangle(100, 100, 100, 100);
|
||||
PdfMarkupAnnotation annot = new PdfTextAnnotation(rect);
|
||||
annot.SetFlag(PdfAnnotation.PRINT);
|
||||
annot.SetOpacity(new PdfNumber(0.5));
|
||||
page.AddAnnotation(annot);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.AN_ANNOTATION_DICTIONARY_SHALL_NOT_CONTAIN_THE_CA_KEY_WITH_A_VALUE_OTHER_THAN_1
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AnnotationCheckTest03() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
Rectangle rect = new Rectangle(100, 100, 100, 100);
|
||||
PdfMarkupAnnotation annot = new PdfTextAnnotation(rect);
|
||||
annot.SetFlag(0);
|
||||
page.AddAnnotation(annot);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.THE_F_KEYS_PRINT_FLAG_BIT_SHALL_BE_SET_TO_1_AND_ITS_HIDDEN_INVISIBLE_AND_NOVIEW_FLAG_BITS_SHALL_BE_SET_TO_0
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AnnotationCheckTest04() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
Rectangle rect = new Rectangle(100, 100, 100, 100);
|
||||
PdfMarkupAnnotation annot = new PdfTextAnnotation(rect);
|
||||
annot.SetFlag(PdfAnnotation.PRINT);
|
||||
annot.SetFlag(PdfAnnotation.INVISIBLE);
|
||||
page.AddAnnotation(annot);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.THE_F_KEYS_PRINT_FLAG_BIT_SHALL_BE_SET_TO_1_AND_ITS_HIDDEN_INVISIBLE_AND_NOVIEW_FLAG_BITS_SHALL_BE_SET_TO_0
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AnnotationCheckTest05() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
Rectangle rect = new Rectangle(100, 100, 100, 100);
|
||||
PdfAnnotation annot = new PdfWidgetAnnotation(rect);
|
||||
annot.SetFlag(PdfAnnotation.PRINT);
|
||||
PdfStream s = new PdfStream("Hello World".GetBytes(TSpdf.Commons.Utils.EncodingUtil.ISO_8859_1));
|
||||
annot.SetDownAppearance(new PdfDictionary());
|
||||
annot.SetNormalAppearance(s);
|
||||
page.AddAnnotation(annot);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.APPEARANCE_DICTIONARY_SHALL_CONTAIN_ONLY_THE_N_KEY_WITH_STREAM_VALUE
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AnnotationCheckTest06() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
Rectangle rect = new Rectangle(100, 100, 100, 100);
|
||||
PdfAnnotation annot = new PdfWidgetAnnotation(rect);
|
||||
annot.SetFlag(PdfAnnotation.PRINT);
|
||||
annot.SetNormalAppearance(new PdfDictionary());
|
||||
page.AddAnnotation(annot);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.APPEARANCE_DICTIONARY_SHALL_CONTAIN_ONLY_THE_N_KEY_WITH_STREAM_VALUE
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AnnotationCheckTest07() {
|
||||
String outPdf = destinationFolder + "pdfA1b_annotationCheckTest07.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA1b_annotationCheckTest07.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
Rectangle rect = new Rectangle(100, 100, 100, 100);
|
||||
PdfMarkupAnnotation annot = new PdfTextAnnotation(rect);
|
||||
annot.SetFlags(PdfAnnotation.PRINT | PdfAnnotation.NO_ZOOM | PdfAnnotation.NO_ROTATE);
|
||||
page.AddAnnotation(annot);
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AnnotationCheckTest08() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1A, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.SetTagged();
|
||||
doc.GetCatalog().SetLang(new PdfString("en-US"));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
Rectangle rect = new Rectangle(100, 100, 100, 100);
|
||||
PdfAnnotation annot = new PdfStampAnnotation(rect);
|
||||
annot.SetFlag(PdfAnnotation.PRINT);
|
||||
page.AddAnnotation(annot);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException.ANNOTATION_OF_TYPE_0_SHOULD_HAVE_CONTENTS_KEY
|
||||
, PdfName.Stamp.GetValue()), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AnnotationCheckTest09() {
|
||||
String outPdf = destinationFolder + "pdfA1a_annotationCheckTest09.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA1a_annotationCheckTest09.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1A, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.SetTagged();
|
||||
doc.GetCatalog().SetLang(new PdfString("en-US"));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
Rectangle rect = new Rectangle(100, 100, 100, 100);
|
||||
PdfAnnotation annot = new PdfStampAnnotation(rect);
|
||||
annot.SetFlag(PdfAnnotation.PRINT);
|
||||
annot.SetContents("Hello world");
|
||||
page.AddAnnotation(annot);
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
private void CompareResult(String outPdf, String cmpPdf) {
|
||||
String result = new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_");
|
||||
if (result != null) {
|
||||
NUnit.Framework.Assert.Fail(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
125
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfA1CanvasCheckTest.cs
Normal file
125
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfA1CanvasCheckTest.cs
Normal file
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
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.Pdf;
|
||||
using TSpdf.Kernel.Pdf.Canvas;
|
||||
using TSpdf.Kernel.Utils;
|
||||
using TSpdf.Pdfa.Exceptions;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfA1CanvasCheckTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
public static readonly String cmpFolder = sourceFolder + "cmp/PdfA1CanvasCheckTest/";
|
||||
|
||||
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/PdfA1CanvasCheckTest/";
|
||||
|
||||
[NUnit.Framework.OneTimeSetUp]
|
||||
public static void BeforeClass() {
|
||||
CreateOrClearDestinationFolder(destinationFolder);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CanvasCheckTest1() {
|
||||
PdfWriter writer = new PdfWriter(new MemoryStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
using (PdfADocument pdfDocument = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent)) {
|
||||
pdfDocument.AddNewPage();
|
||||
PdfCanvas canvas = new PdfCanvas(pdfDocument.GetLastPage());
|
||||
for (int i = 0; i < 28; i++) {
|
||||
canvas.SaveState();
|
||||
}
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => canvas.SaveState());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.GRAPHICS_STATE_STACK_DEPTH_IS_GREATER_THAN_28, e.
|
||||
Message);
|
||||
}
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CanvasCheckTest2() {
|
||||
String outPdf = destinationFolder + "pdfA1b_canvasCheckTest2.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA1b_canvasCheckTest2.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument pdfDocument = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent);
|
||||
pdfDocument.AddNewPage();
|
||||
PdfCanvas canvas = new PdfCanvas(pdfDocument.GetLastPage());
|
||||
for (int i = 0; i < 28; i++) {
|
||||
canvas.SaveState();
|
||||
}
|
||||
for (int i = 0; i < 28; i++) {
|
||||
canvas.RestoreState();
|
||||
}
|
||||
pdfDocument.Close();
|
||||
String result = new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_");
|
||||
if (result != null) {
|
||||
NUnit.Framework.Assert.Fail(result);
|
||||
}
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CanvasCheckTest3() {
|
||||
PdfWriter writer = new PdfWriter(new MemoryStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
using (PdfADocument pdfDocument = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent)) {
|
||||
pdfDocument.AddNewPage();
|
||||
PdfCanvas canvas = new PdfCanvas(pdfDocument.GetLastPage());
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => canvas.SetRenderingIntent
|
||||
(new PdfName("Test")));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.IF_SPECIFIED_RENDERING_SHALL_BE_ONE_OF_THE_FOLLOWING_RELATIVECOLORIMETRIC_ABSOLUTECOLORIMETRIC_PERCEPTUAL_OR_SATURATION
|
||||
, e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
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.Pdf;
|
||||
using TSpdf.Kernel.Pdf.Filespec;
|
||||
using TSpdf.Pdfa.Exceptions;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfA1EmbeddedFilesCheckTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void FileSpecCheckTest01() {
|
||||
PdfWriter writer = new PdfWriter(new MemoryStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument pdfDocument = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent);
|
||||
PdfDictionary fileNames = new PdfDictionary();
|
||||
pdfDocument.GetCatalog().Put(PdfName.Names, fileNames);
|
||||
PdfDictionary embeddedFiles = new PdfDictionary();
|
||||
fileNames.Put(PdfName.EmbeddedFiles, embeddedFiles);
|
||||
PdfArray names = new PdfArray();
|
||||
fileNames.Put(PdfName.Names, names);
|
||||
names.Add(new PdfString("some/file/path"));
|
||||
PdfFileSpec spec = PdfFileSpec.CreateEmbeddedFileSpec(pdfDocument, sourceFolder + "sample.wav", "sample.wav"
|
||||
, "sample", null, null);
|
||||
names.Add(spec.GetPdfObject());
|
||||
pdfDocument.AddNewPage();
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfDocument.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.A_NAME_DICTIONARY_SHALL_NOT_CONTAIN_THE_EMBEDDED_FILES_KEY
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void FileSpecCheckTest02() {
|
||||
PdfWriter writer = new PdfWriter(new MemoryStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument pdfDocument = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent);
|
||||
PdfStream stream = new PdfStream();
|
||||
pdfDocument.GetCatalog().Put(new PdfName("testStream"), stream);
|
||||
PdfFileSpec spec = PdfFileSpec.CreateEmbeddedFileSpec(pdfDocument, sourceFolder + "sample.wav", "sample.wav"
|
||||
, "sample", null, null);
|
||||
stream.Put(PdfName.F, spec.GetPdfObject());
|
||||
pdfDocument.AddNewPage();
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfDocument.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.STREAM_OBJECT_DICTIONARY_SHALL_NOT_CONTAIN_THE_F_FFILTER_OR_FDECODEPARAMS_KEYS
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void FileSpecCheckTest03() {
|
||||
PdfWriter writer = new PdfWriter(new MemoryStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument pdfDocument = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent);
|
||||
PdfStream stream = new PdfStream();
|
||||
pdfDocument.GetCatalog().Put(new PdfName("testStream"), stream);
|
||||
PdfFileSpec spec = PdfFileSpec.CreateEmbeddedFileSpec(pdfDocument, sourceFolder + "sample.wav", "sample.wav"
|
||||
, "sample", null, null);
|
||||
stream.Put(new PdfName("fileData"), spec.GetPdfObject());
|
||||
pdfDocument.AddNewPage();
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfDocument.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.FILE_SPECIFICATION_DICTIONARY_SHALL_NOT_CONTAIN_THE_EF_KEY
|
||||
, e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
278
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfA1GraphicsTest.cs
Normal file
278
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfA1GraphicsTest.cs
Normal file
@@ -0,0 +1,278 @@
|
||||
/*
|
||||
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.Colors;
|
||||
using TSpdf.Kernel.Geom;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Pdf.Canvas;
|
||||
using TSpdf.Kernel.Pdf.Extgstate;
|
||||
using TSpdf.Kernel.Pdf.Xobject;
|
||||
using TSpdf.Kernel.Utils;
|
||||
using TSpdf.Pdfa.Exceptions;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfA1GraphicsTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
public static readonly String cmpFolder = sourceFolder + "cmp/PdfA1GraphicsTest/";
|
||||
|
||||
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/PdfA1GraphicsTest/";
|
||||
|
||||
[NUnit.Framework.OneTimeSetUp]
|
||||
public static void BeforeClass() {
|
||||
CreateOrClearDestinationFolder(destinationFolder);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ColorCheckTest1() {
|
||||
PdfWriter writer = new PdfWriter(new MemoryStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent);
|
||||
doc.AddNewPage();
|
||||
PdfCanvas canvas = new PdfCanvas(doc.GetLastPage());
|
||||
canvas.SetFillColor(new DeviceCmyk(0.1f, 0.1f, 0.1f, 0.1f));
|
||||
canvas.MoveTo(doc.GetDefaultPageSize().GetLeft(), doc.GetDefaultPageSize().GetBottom());
|
||||
canvas.LineTo(doc.GetDefaultPageSize().GetRight(), doc.GetDefaultPageSize().GetBottom());
|
||||
canvas.LineTo(doc.GetDefaultPageSize().GetRight(), doc.GetDefaultPageSize().GetTop());
|
||||
canvas.Fill();
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => canvas.SetFillColor(ColorConstants
|
||||
.RED));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.DEVICERGB_AND_DEVICECMYK_COLORSPACES_CANNOT_BE_USED_BOTH_IN_ONE_FILE
|
||||
, e.Message);
|
||||
canvas.MoveTo(doc.GetDefaultPageSize().GetRight(), doc.GetDefaultPageSize().GetTop());
|
||||
canvas.LineTo(doc.GetDefaultPageSize().GetRight(), doc.GetDefaultPageSize().GetBottom());
|
||||
canvas.LineTo(doc.GetDefaultPageSize().GetLeft(), doc.GetDefaultPageSize().GetBottom());
|
||||
canvas.Fill();
|
||||
Exception e2 = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.DEVICERGB_AND_DEVICECMYK_COLORSPACES_CANNOT_BE_USED_BOTH_IN_ONE_FILE
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ColorCheckTest2() {
|
||||
PdfWriter writer = new PdfWriter(new MemoryStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent);
|
||||
doc.AddNewPage();
|
||||
PdfCanvas canvas = new PdfCanvas(doc.GetLastPage());
|
||||
canvas.SetFillColor(new DeviceCmyk(0.1f, 0.1f, 0.1f, 0.1f));
|
||||
canvas.MoveTo(doc.GetDefaultPageSize().GetLeft(), doc.GetDefaultPageSize().GetBottom());
|
||||
canvas.LineTo(doc.GetDefaultPageSize().GetRight(), doc.GetDefaultPageSize().GetBottom());
|
||||
canvas.LineTo(doc.GetDefaultPageSize().GetRight(), doc.GetDefaultPageSize().GetTop());
|
||||
canvas.Fill();
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.DEVICECMYK_MAY_BE_USED_ONLY_IF_THE_FILE_HAS_A_CMYK_PDFA_OUTPUT_INTENT
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ColorCheckTest3() {
|
||||
PdfWriter writer = new PdfWriter(new MemoryStream());
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, null);
|
||||
doc.AddNewPage();
|
||||
PdfCanvas canvas = new PdfCanvas(doc.GetLastPage());
|
||||
canvas.SetFillColor(ColorConstants.GREEN);
|
||||
canvas.MoveTo(doc.GetDefaultPageSize().GetLeft(), doc.GetDefaultPageSize().GetBottom());
|
||||
canvas.LineTo(doc.GetDefaultPageSize().GetRight(), doc.GetDefaultPageSize().GetBottom());
|
||||
canvas.LineTo(doc.GetDefaultPageSize().GetRight(), doc.GetDefaultPageSize().GetTop());
|
||||
canvas.Fill();
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.IF_DEVICE_RGB_CMYK_GRAY_USED_IN_FILE_THAT_FILE_SHALL_CONTAIN_PDFA_OUTPUTINTENT
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ColorCheckTest4() {
|
||||
String outPdf = destinationFolder + "pdfA1b_colorCheckTest4.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA1b_colorCheckTest4.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent);
|
||||
doc.AddNewPage();
|
||||
PdfCanvas canvas = new PdfCanvas(doc.GetLastPage());
|
||||
canvas.SetFillColor(ColorConstants.GREEN);
|
||||
canvas.MoveTo(doc.GetDefaultPageSize().GetLeft(), doc.GetDefaultPageSize().GetBottom());
|
||||
canvas.LineTo(doc.GetDefaultPageSize().GetRight(), doc.GetDefaultPageSize().GetBottom());
|
||||
canvas.LineTo(doc.GetDefaultPageSize().GetRight(), doc.GetDefaultPageSize().GetTop());
|
||||
canvas.Fill();
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void EgsCheckTest1() {
|
||||
PdfWriter writer = new PdfWriter(new MemoryStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
using (PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent)) {
|
||||
doc.AddNewPage();
|
||||
PdfCanvas canvas = new PdfCanvas(doc.GetLastPage());
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => canvas.SetExtGState(new
|
||||
PdfExtGState().SetTransferFunction(new PdfName("Test"))));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.AN_EXTGSTATE_DICTIONARY_SHALL_NOT_CONTAIN_THE_TR_KEY
|
||||
, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void EgsCheckTest2() {
|
||||
String outPdf = destinationFolder + "pdfA1b_egsCheckTest2.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA1b_egsCheckTest2.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent);
|
||||
doc.AddNewPage();
|
||||
PdfCanvas canvas = new PdfCanvas(doc.GetLastPage());
|
||||
canvas.SetExtGState(new PdfExtGState().SetTransferFunction2(PdfName.Default));
|
||||
canvas.Rectangle(30, 30, 100, 100).Fill();
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void EgsCheckTest3() {
|
||||
PdfWriter writer = new PdfWriter(new MemoryStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
using (PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent)) {
|
||||
doc.AddNewPage();
|
||||
PdfCanvas canvas = new PdfCanvas(doc.GetLastPage());
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => canvas.SetExtGState(new
|
||||
PdfExtGState().SetTransferFunction2(new PdfName("Test"))));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.AN_EXTGSTATE_DICTIONARY_SHALL_NOT_CONTAIN_THE_TR_2_KEY_WITH_A_VALUE_OTHER_THAN_DEFAULT
|
||||
, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void EgsCheckTest4() {
|
||||
PdfWriter writer = new PdfWriter(new MemoryStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
using (PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent)) {
|
||||
doc.AddNewPage();
|
||||
PdfCanvas canvas = new PdfCanvas(doc.GetLastPage());
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => canvas.SetExtGState(new
|
||||
PdfExtGState().SetRenderingIntent(new PdfName("Test"))));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.IF_SPECIFIED_RENDERING_SHALL_BE_ONE_OF_THE_FOLLOWING_RELATIVECOLORIMETRIC_ABSOLUTECOLORIMETRIC_PERCEPTUAL_OR_SATURATION
|
||||
, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void TransparencyCheckTest1() {
|
||||
PdfWriter writer = new PdfWriter(new MemoryStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent);
|
||||
doc.AddNewPage();
|
||||
PdfCanvas canvas = new PdfCanvas(doc.GetLastPage());
|
||||
PdfFormXObject xObject = new PdfFormXObject(new Rectangle(100, 100));
|
||||
PdfCanvas xObjCanvas = new PdfCanvas(xObject, doc);
|
||||
xObjCanvas.Rectangle(30, 30, 10, 10).Fill();
|
||||
PdfTransparencyGroup group = new PdfTransparencyGroup();
|
||||
xObject.SetGroup(group);
|
||||
canvas.AddXObjectFittedIntoRectangle(xObject, new Rectangle(300, 300));
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.A_GROUP_OBJECT_WITH_AN_S_KEY_WITH_A_VALUE_OF_TRANSPARENCY_SHALL_NOT_BE_INCLUDED_IN_A_FORM_XOBJECT
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void TransparencyCheckTest2() {
|
||||
PdfWriter writer = new PdfWriter(new MemoryStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
using (PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent)) {
|
||||
doc.AddNewPage();
|
||||
PdfCanvas canvas = new PdfCanvas(doc.GetLastPage());
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => canvas.SetExtGState(new
|
||||
PdfExtGState().SetSoftMask(new PdfName("Test"))));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.THE_SMASK_KEY_IS_NOT_ALLOWED_IN_EXTGSTATE, e.Message
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void TransparencyCheckTest3() {
|
||||
String outPdf = destinationFolder + "pdfA1b_transparencyCheckTest3.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA1b_transparencyCheckTest3.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent);
|
||||
doc.AddNewPage();
|
||||
PdfCanvas canvas = new PdfCanvas(doc.GetLastPage());
|
||||
canvas.SetExtGState(new PdfExtGState().SetSoftMask(PdfName.None));
|
||||
canvas.Rectangle(30, 30, 100, 100).Fill();
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
private void CompareResult(String outPdf, String cmpPdf) {
|
||||
String result = new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_");
|
||||
if (result != null) {
|
||||
NUnit.Framework.Assert.Fail(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
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.IO.Font;
|
||||
using TSpdf.Kernel.Font;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Utils;
|
||||
using TSpdf.Layout;
|
||||
using TSpdf.Layout.Element;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfA1LayoutListTest : ExtendedTSpdfTest {
|
||||
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/PdfA1LayoutListTest/";
|
||||
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
public static readonly String cmpFolder = sourceFolder + "cmp/PdfA1LayoutListTest/";
|
||||
|
||||
[NUnit.Framework.OneTimeSetUp]
|
||||
public static void BeforeClass() {
|
||||
CreateOrClearDestinationFolder(destinationFolder);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ListTest01() {
|
||||
String outPdf = destinationFolder + "pdfA1b_listTest01.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA1b_listTest01.pdf";
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument pdfDocument = new PdfADocument(new PdfWriter(outPdf), PdfAConformanceLevel.PDF_A_1B, outputIntent
|
||||
);
|
||||
Document doc = new Document(pdfDocument);
|
||||
pdfDocument.SetTagged();
|
||||
PdfFont textfont = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", PdfEncodings.WINANSI, PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
textfont.SetSubset(true);
|
||||
List list = new List();
|
||||
ListItem listItem = new ListItem();
|
||||
listItem.Add(new Paragraph().Add("foobar"));
|
||||
list.Add(listItem);
|
||||
listItem.SetFont(textfont);
|
||||
doc.Add(list);
|
||||
doc.Close();
|
||||
String result = new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_");
|
||||
if (result != null) {
|
||||
NUnit.Framework.Assert.Fail(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
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.Forms.Fields;
|
||||
using TSpdf.Kernel.Colors;
|
||||
using TSpdf.Kernel.Geom;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Utils;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfA1bCheckfieldAppearanceTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
public static readonly String cmpFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/cmp/PdfA1bCheckfieldAppearanceTest/";
|
||||
|
||||
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/PdfA1bCheckfieldAppearanceTest/";
|
||||
|
||||
[NUnit.Framework.OneTimeSetUp]
|
||||
public static void BeforeClass() {
|
||||
CreateDestinationFolder(destinationFolder);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA1bCheckFieldOffAppearanceTest() {
|
||||
String name = "pdfA1b_checkFieldOffAppearance";
|
||||
String outPath = destinationFolder + name + ".pdf";
|
||||
String cmpPath = cmpFolder + "cmp_" + name + ".pdf";
|
||||
String diff = "diff_" + name + "_";
|
||||
PdfWriter writer = new PdfWriter(outPath);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
|
||||
PdfFormField chk = new CheckBoxFormFieldBuilder(doc, "name").SetWidgetRectangle(new Rectangle(100, 500, 50
|
||||
, 50)).SetCheckType(PdfFormField.TYPE_CHECK).SetConformanceLevel(PdfAConformanceLevel.PDF_A_1B).CreateCheckBox
|
||||
().SetValue("Off");
|
||||
chk.GetFirstFormAnnotation().SetBorderColor(ColorConstants.BLACK);
|
||||
chk.GetFirstFormAnnotation().SetBorderWidth(1);
|
||||
form.AddField(chk);
|
||||
doc.Close();
|
||||
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff
|
||||
));
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA1bCheckFieldOnAppearanceTest() {
|
||||
String name = "pdfA1b_checkFieldOnAppearance";
|
||||
String outPath = destinationFolder + name + ".pdf";
|
||||
String cmpPath = cmpFolder + "cmp_" + name + ".pdf";
|
||||
String diff = "diff_" + name + "_";
|
||||
PdfWriter writer = new PdfWriter(outPath);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
|
||||
PdfFormField chk = new CheckBoxFormFieldBuilder(doc, "name").SetWidgetRectangle(new Rectangle(100, 500, 50
|
||||
, 50)).SetCheckType(PdfFormField.TYPE_CHECK).SetConformanceLevel(PdfAConformanceLevel.PDF_A_1B).CreateCheckBox
|
||||
().SetValue("On");
|
||||
chk.GetFirstFormAnnotation().SetBorderColor(ColorConstants.BLACK);
|
||||
chk.GetFirstFormAnnotation().SetBorderWidth(1);
|
||||
form.AddField(chk);
|
||||
doc.Close();
|
||||
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
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.IO.Source;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Utils;
|
||||
using TSpdf.Pdfa.Exceptions;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfA2AcroFormCheckTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
public static readonly String cmpFolder = sourceFolder + "cmp/PdfA2AcroFormCheckTest/";
|
||||
|
||||
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/PdfA2AcroFormCheckTest/";
|
||||
|
||||
[NUnit.Framework.OneTimeSetUp]
|
||||
public static void BeforeClass() {
|
||||
CreateOrClearDestinationFolder(destinationFolder);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AcroFormCheck01() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary acroForm = new PdfDictionary();
|
||||
acroForm.Put(PdfName.NeedAppearances, new PdfBoolean(true));
|
||||
doc.GetCatalog().Put(PdfName.AcroForm, acroForm);
|
||||
try {
|
||||
doc.Close();
|
||||
NUnit.Framework.Assert.Fail("PdfAConformanceException expected");
|
||||
}
|
||||
catch (PdfAConformanceException) {
|
||||
}
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AcroFormCheck02() {
|
||||
String outPdf = destinationFolder + "pdfA2b_acroFormCheck02.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA2b_acroFormCheck02.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary acroForm = new PdfDictionary();
|
||||
acroForm.Put(PdfName.NeedAppearances, new PdfBoolean(false));
|
||||
doc.GetCatalog().Put(PdfName.AcroForm, acroForm);
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AcroFormCheck03() {
|
||||
String outPdf = destinationFolder + "pdfA2b_acroFormCheck03.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA2b_acroFormCheck03.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary acroForm = new PdfDictionary();
|
||||
doc.GetCatalog().Put(PdfName.AcroForm, acroForm);
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AcroFormCheck04() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary acroForm = new PdfDictionary();
|
||||
acroForm.Put(PdfName.XFA, new PdfArray());
|
||||
doc.GetCatalog().Put(PdfName.AcroForm, acroForm);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.THE_INTERACTIVE_FORM_DICTIONARY_SHALL_NOT_CONTAIN_THE_XFA_KEY
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
private void CompareResult(String outPdf, String cmpPdf) {
|
||||
String result = new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_");
|
||||
if (result != null) {
|
||||
NUnit.Framework.Assert.Fail(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
293
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfA2ActionCheckTest.cs
Normal file
293
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfA2ActionCheckTest.cs
Normal file
@@ -0,0 +1,293 @@
|
||||
/*
|
||||
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.Commons.Utils;
|
||||
using TSpdf.IO.Source;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Pdf.Action;
|
||||
using TSpdf.Kernel.Utils;
|
||||
using TSpdf.Pdfa.Exceptions;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfA2ActionCheckTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/PdfA2ActionCheckTest/";
|
||||
|
||||
[NUnit.Framework.OneTimeSetUp]
|
||||
public static void BeforeClass() {
|
||||
CreateOrClearDestinationFolder(destinationFolder);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ActionCheck01() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary openActions = new PdfDictionary();
|
||||
openActions.Put(PdfName.S, PdfName.Launch);
|
||||
doc.GetCatalog().Put(PdfName.OpenAction, openActions);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException._0_ACTIONS_ARE_NOT_ALLOWED
|
||||
, PdfName.Launch.GetValue()), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ActionCheck02() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary openActions = new PdfDictionary();
|
||||
openActions.Put(PdfName.S, PdfName.Hide);
|
||||
doc.GetCatalog().Put(PdfName.OpenAction, openActions);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException._0_ACTIONS_ARE_NOT_ALLOWED
|
||||
, PdfName.Hide.GetValue()), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ActionCheck03() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary openActions = new PdfDictionary();
|
||||
openActions.Put(PdfName.S, PdfName.Sound);
|
||||
doc.GetCatalog().Put(PdfName.OpenAction, openActions);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException._0_ACTIONS_ARE_NOT_ALLOWED
|
||||
, PdfName.Sound.GetValue()), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ActionCheck04() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary openActions = new PdfDictionary();
|
||||
openActions.Put(PdfName.S, PdfName.Movie);
|
||||
doc.GetCatalog().Put(PdfName.OpenAction, openActions);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException._0_ACTIONS_ARE_NOT_ALLOWED
|
||||
, PdfName.Movie.GetValue()), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ActionCheck05() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary openActions = new PdfDictionary();
|
||||
openActions.Put(PdfName.S, PdfName.ResetForm);
|
||||
doc.GetCatalog().Put(PdfName.OpenAction, openActions);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException._0_ACTIONS_ARE_NOT_ALLOWED
|
||||
, PdfName.ResetForm.GetValue()), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ActionCheck06() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary openActions = new PdfDictionary();
|
||||
openActions.Put(PdfName.S, PdfName.ImportData);
|
||||
doc.GetCatalog().Put(PdfName.OpenAction, openActions);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException._0_ACTIONS_ARE_NOT_ALLOWED
|
||||
, PdfName.ImportData.GetValue()), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ActionCheck07() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary openActions = new PdfDictionary();
|
||||
openActions.Put(PdfName.S, PdfName.JavaScript);
|
||||
doc.GetCatalog().Put(PdfName.OpenAction, openActions);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException._0_ACTIONS_ARE_NOT_ALLOWED
|
||||
, PdfName.JavaScript.GetValue()), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ActionCheck08() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary openActions = new PdfDictionary();
|
||||
openActions.Put(PdfName.S, PdfName.Named);
|
||||
openActions.Put(PdfName.N, new PdfName("CustomName"));
|
||||
doc.GetCatalog().Put(PdfName.OpenAction, openActions);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException.NAMED_ACTION_TYPE_0_IS_NOT_ALLOWED
|
||||
, "CustomName"), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ActionCheck09() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary openActions = new PdfDictionary();
|
||||
openActions.Put(PdfName.S, PdfName.SetOCGState);
|
||||
doc.GetCatalog().Put(PdfName.OpenAction, openActions);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException._0_ACTIONS_ARE_NOT_ALLOWED
|
||||
, PdfName.SetOCGState.GetValue()), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ActionCheck10() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary openActions = new PdfDictionary();
|
||||
openActions.Put(PdfName.S, PdfName.Rendition);
|
||||
doc.GetCatalog().Put(PdfName.OpenAction, openActions);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException._0_ACTIONS_ARE_NOT_ALLOWED
|
||||
, PdfName.Rendition.GetValue()), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ActionCheck11() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary openActions = new PdfDictionary();
|
||||
openActions.Put(PdfName.S, PdfName.Trans);
|
||||
doc.GetCatalog().Put(PdfName.OpenAction, openActions);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException._0_ACTIONS_ARE_NOT_ALLOWED
|
||||
, PdfName.Trans.GetValue()), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ActionCheck12() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary openActions = new PdfDictionary();
|
||||
openActions.Put(PdfName.S, PdfName.GoTo3DView);
|
||||
doc.GetCatalog().Put(PdfName.OpenAction, openActions);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException._0_ACTIONS_ARE_NOT_ALLOWED
|
||||
, PdfName.GoTo3DView.GetValue()), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ActionCheck13() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
page.SetAdditionalAction(PdfName.C, PdfAction.CreateJavaScript("js"));
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.THE_PAGE_DICTIONARY_SHALL_NOT_CONTAIN_AA_ENTRY, e
|
||||
.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ActionCheck14() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
doc.GetCatalog().SetAdditionalAction(PdfName.C, PdfAction.CreateJavaScript("js"));
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.A_CATALOG_DICTIONARY_SHALL_NOT_CONTAIN_AA_ENTRY,
|
||||
e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ActionCheck15() {
|
||||
String outPdf = destinationFolder + "pdfA2b_actionCheck15.pdf";
|
||||
String cmpPdf = sourceFolder + "cmp/PdfA2ActionCheckTest/cmp_pdfA2b_actionCheck15.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.GetOutlines(true);
|
||||
PdfOutline @out = doc.GetOutlines(false);
|
||||
@out.AddOutline("New").AddAction(PdfAction.CreateGoTo("TestDest"));
|
||||
doc.AddNewPage();
|
||||
doc.Close();
|
||||
String result = new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_");
|
||||
if (result != null) {
|
||||
NUnit.Framework.Assert.Fail(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,345 @@
|
||||
/*
|
||||
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.Commons.Utils;
|
||||
using TSpdf.IO.Source;
|
||||
using TSpdf.Kernel.Font;
|
||||
using TSpdf.Kernel.Geom;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Pdf.Annot;
|
||||
using TSpdf.Kernel.Pdf.Canvas;
|
||||
using TSpdf.Kernel.Pdf.Xobject;
|
||||
using TSpdf.Kernel.Utils;
|
||||
using TSpdf.Pdfa.Exceptions;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfA2AnnotationCheckTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
public static readonly String cmpFolder = sourceFolder + "cmp/PdfA2AnnotationCheckTest/";
|
||||
|
||||
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/PdfA2AnnotationCheckTest/";
|
||||
|
||||
[NUnit.Framework.OneTimeSetUp]
|
||||
public static void BeforeClass() {
|
||||
CreateOrClearDestinationFolder(destinationFolder);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AnnotationCheckTest01() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
Rectangle rect = new Rectangle(100, 650, 400, 100);
|
||||
PdfAnnotation annot = new PdfFileAttachmentAnnotation(rect);
|
||||
page.AddAnnotation(annot);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.AN_ANNOTATION_DICTIONARY_SHALL_CONTAIN_THE_F_KEY,
|
||||
e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AnnotationCheckTest02() {
|
||||
String outPdf = destinationFolder + "pdfA2b_annotationCheckTest02.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA2b_annotationCheckTest02.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
Rectangle rect = new Rectangle(100, 650, 400, 100);
|
||||
PdfAnnotation annot = new PdfPopupAnnotation(rect);
|
||||
page.AddAnnotation(annot);
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AnnotationCheckTest03() {
|
||||
String outPdf = destinationFolder + "pdfA2b_annotationCheckTest03.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA2b_annotationCheckTest03.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
Rectangle rect = new Rectangle(100, 100, 0, 0);
|
||||
PdfAnnotation annot = new PdfWidgetAnnotation(rect);
|
||||
annot.SetContents(new PdfString(""));
|
||||
annot.SetFlag(PdfAnnotation.PRINT);
|
||||
page.AddAnnotation(annot);
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AnnotationCheckTest04() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
Rectangle rect = new Rectangle(100, 650, 400, 100);
|
||||
PdfAnnotation annot = new PdfWidgetAnnotation(rect);
|
||||
annot.SetContents(new PdfString(""));
|
||||
annot.SetFlag(PdfAnnotation.PRINT);
|
||||
page.AddAnnotation(annot);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.EVERY_ANNOTATION_SHALL_HAVE_AT_LEAST_ONE_APPEARANCE_DICTIONARY
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AnnotationCheckTest05() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
Rectangle rect = new Rectangle(100, 650, 400, 100);
|
||||
PdfAnnotation annot = new PdfTextAnnotation(rect);
|
||||
annot.SetFlag(0);
|
||||
page.AddAnnotation(annot);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.THE_F_KEYS_PRINT_FLAG_BIT_SHALL_BE_SET_TO_1_AND_ITS_HIDDEN_INVISIBLE_NOVIEW_AND_TOGGLENOVIEW_FLAG_BITS_SHALL_BE_SET_TO_0
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AnnotationCheckTest06() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
Rectangle rect = new Rectangle(100, 650, 400, 100);
|
||||
PdfAnnotation annot = new PdfTextAnnotation(rect);
|
||||
annot.SetFlags(PdfAnnotation.PRINT | PdfAnnotation.INVISIBLE);
|
||||
page.AddAnnotation(annot);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.THE_F_KEYS_PRINT_FLAG_BIT_SHALL_BE_SET_TO_1_AND_ITS_HIDDEN_INVISIBLE_NOVIEW_AND_TOGGLENOVIEW_FLAG_BITS_SHALL_BE_SET_TO_0
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AnnotationCheckTest07() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
Rectangle rect = new Rectangle(100, 650, 400, 100);
|
||||
Rectangle formRect = new Rectangle(400, 100);
|
||||
PdfAnnotation annot = new PdfWidgetAnnotation(rect);
|
||||
annot.SetContents(new PdfString(""));
|
||||
annot.SetFlags(PdfAnnotation.PRINT);
|
||||
annot.SetDownAppearance(new PdfDictionary());
|
||||
annot.SetNormalAppearance(CreateAppearance(doc, formRect));
|
||||
page.AddAnnotation(annot);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.APPEARANCE_DICTIONARY_SHALL_CONTAIN_ONLY_THE_N_KEY_WITH_STREAM_VALUE
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AnnotationCheckTest08() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
Rectangle rect = new Rectangle(100, 650, 400, 100);
|
||||
Rectangle formRect = new Rectangle(400, 100);
|
||||
PdfAnnotation annot = new PdfWidgetAnnotation(rect);
|
||||
annot.SetContents(new PdfString(""));
|
||||
annot.SetFlags(PdfAnnotation.PRINT);
|
||||
annot.GetPdfObject().Put(PdfName.FT, PdfName.Btn);
|
||||
annot.SetNormalAppearance(CreateAppearance(doc, formRect));
|
||||
page.AddAnnotation(annot);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.APPEARANCE_DICTIONARY_OF_WIDGET_SUBTYPE_AND_BTN_FIELD_TYPE_SHALL_CONTAIN_ONLY_THE_N_KEY_WITH_DICTIONARY_VALUE
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AnnotationCheckTest09() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
Rectangle rect = new Rectangle(100, 650, 400, 100);
|
||||
PdfAnnotation annot = new PdfWidgetAnnotation(rect);
|
||||
annot.SetContents(new PdfString(""));
|
||||
annot.SetFlags(PdfAnnotation.PRINT);
|
||||
annot.SetNormalAppearance(new PdfDictionary());
|
||||
page.AddAnnotation(annot);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.APPEARANCE_DICTIONARY_SHALL_CONTAIN_ONLY_THE_N_KEY_WITH_STREAM_VALUE
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AnnotationCheckTest10() {
|
||||
String outPdf = destinationFolder + "pdfA2b_annotationCheckTest10.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA2b_annotationCheckTest10.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
Rectangle rect = new Rectangle(100, 650, 400, 100);
|
||||
Rectangle formRect = new Rectangle(400, 100);
|
||||
PdfAnnotation annot = new PdfWidgetAnnotation(rect);
|
||||
annot.SetContents(new PdfString(""));
|
||||
annot.SetFlags(PdfAnnotation.PRINT);
|
||||
annot.SetNormalAppearance(CreateAppearance(doc, formRect));
|
||||
page.AddAnnotation(annot);
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AnnotationCheckTest11() {
|
||||
String outPdf = destinationFolder + "pdfA2b_annotationCheckTest11.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA2b_annotationCheckTest11.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
Rectangle rect = new Rectangle(100, 650, 400, 100);
|
||||
Rectangle formRect = new Rectangle(400, 100);
|
||||
PdfAnnotation annot = new PdfTextAnnotation(rect);
|
||||
annot.SetContents(new PdfString(""));
|
||||
annot.SetFlags(PdfAnnotation.PRINT | PdfAnnotation.NO_ZOOM | PdfAnnotation.NO_ROTATE);
|
||||
annot.SetNormalAppearance(CreateAppearance(doc, formRect));
|
||||
page.AddAnnotation(annot);
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AnnotationCheckTest12() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2A, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.SetTagged();
|
||||
doc.GetCatalog().SetLang(new PdfString("en-US"));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
Rectangle rect = new Rectangle(100, 650, 400, 100);
|
||||
PdfAnnotation annot = new PdfStampAnnotation(rect);
|
||||
annot.SetFlags(PdfAnnotation.PRINT);
|
||||
page.AddAnnotation(annot);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException.ANNOTATION_OF_TYPE_0_SHOULD_HAVE_CONTENTS_KEY
|
||||
, PdfName.Stamp.GetValue()), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AnnotationCheckTest13() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2A, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.SetTagged();
|
||||
doc.GetCatalog().SetLang(new PdfString("en-US"));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
Rectangle rect = new Rectangle(100, 650, 400, 100);
|
||||
PdfAnnotation annot = new PdfStampAnnotation(rect);
|
||||
annot.SetFlags(PdfAnnotation.PRINT);
|
||||
annot.SetContents("Hello world");
|
||||
page.AddAnnotation(annot);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.EVERY_ANNOTATION_SHALL_HAVE_AT_LEAST_ONE_APPEARANCE_DICTIONARY
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AnnotationCheckTest14() {
|
||||
String outPdf = destinationFolder + "pdfA2a_annotationCheckTest14.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA2a_annotationCheckTest14.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2A, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.SetTagged();
|
||||
doc.GetCatalog().SetLang(new PdfString("en-US"));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
Rectangle annotRect = new Rectangle(100, 650, 400, 100);
|
||||
Rectangle formRect = new Rectangle(400, 100);
|
||||
PdfAnnotation annot = new PdfStampAnnotation(annotRect);
|
||||
annot.SetFlags(PdfAnnotation.PRINT);
|
||||
annot.SetContents("Hello World");
|
||||
annot.SetNormalAppearance(CreateAppearance(doc, formRect));
|
||||
page.AddAnnotation(annot);
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
private PdfStream CreateAppearance(PdfADocument doc, Rectangle formRect) {
|
||||
PdfFormXObject form = new PdfFormXObject(formRect);
|
||||
PdfCanvas canvas = new PdfCanvas(form, doc);
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
canvas.SetFontAndSize(font, 12);
|
||||
canvas.BeginText().SetTextMatrix(200, 50).ShowText("Hello World").EndText();
|
||||
return form.GetPdfObject();
|
||||
}
|
||||
|
||||
private void CompareResult(String outPdf, String cmpPdf) {
|
||||
String result = new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_");
|
||||
if (result != null) {
|
||||
NUnit.Framework.Assert.Fail(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
126
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfA2CanvasCheckTest.cs
Normal file
126
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfA2CanvasCheckTest.cs
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
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.IO.Source;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Pdf.Canvas;
|
||||
using TSpdf.Kernel.Utils;
|
||||
using TSpdf.Pdfa.Exceptions;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfA2CanvasCheckTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/PdfA2CanvasCheckTest/";
|
||||
|
||||
[NUnit.Framework.OneTimeSetUp]
|
||||
public static void BeforeClass() {
|
||||
CreateOrClearDestinationFolder(destinationFolder);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CanvasCheckTest1() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
using (PdfADocument pdfDocument = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, outputIntent)) {
|
||||
pdfDocument.AddNewPage();
|
||||
PdfCanvas canvas = new PdfCanvas(pdfDocument.GetLastPage());
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => {
|
||||
for (int i = 0; i < 29; i++) {
|
||||
canvas.SaveState();
|
||||
}
|
||||
}
|
||||
);
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.GRAPHICS_STATE_STACK_DEPTH_IS_GREATER_THAN_28, e.
|
||||
Message);
|
||||
}
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CanvasCheckTest2() {
|
||||
String outPdf = destinationFolder + "pdfA2b_canvasCheckTest2.pdf";
|
||||
String cmpPdf = sourceFolder + "cmp/PdfA2CanvasCheckTest/cmp_pdfA2b_canvasCheckTest2.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
using (PdfADocument pdfDocument = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, outputIntent)) {
|
||||
pdfDocument.AddNewPage();
|
||||
PdfCanvas canvas = new PdfCanvas(pdfDocument.GetLastPage());
|
||||
for (int i = 0; i < 28; i++) {
|
||||
canvas.SaveState();
|
||||
}
|
||||
for (int i = 0; i < 28; i++) {
|
||||
canvas.RestoreState();
|
||||
}
|
||||
}
|
||||
String result = new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_");
|
||||
if (result != null) {
|
||||
NUnit.Framework.Assert.Fail(result);
|
||||
}
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CanvasCheckTest3() {
|
||||
PdfWriter writer = new PdfWriter(new MemoryStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
using (PdfADocument pdfDocument = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, outputIntent)) {
|
||||
pdfDocument.AddNewPage();
|
||||
PdfCanvas canvas = new PdfCanvas(pdfDocument.GetLastPage());
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => canvas.SetRenderingIntent
|
||||
(new PdfName("Test")));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.IF_SPECIFIED_RENDERING_SHALL_BE_ONE_OF_THE_FOLLOWING_RELATIVECOLORIMETRIC_ABSOLUTECOLORIMETRIC_PERCEPTUAL_OR_SATURATION
|
||||
, e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
165
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfA2CatalogCheckTest.cs
Normal file
165
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfA2CatalogCheckTest.cs
Normal file
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
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.IO.Source;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Utils;
|
||||
using TSpdf.Pdfa.Exceptions;
|
||||
using TSpdf.Test;
|
||||
using TSpdf.Test.Pdfa;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfA2CatalogCheckTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
public static readonly String cmpFolder = sourceFolder + "cmp/PdfA2CatalogCheckTest/";
|
||||
|
||||
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/PdfA2CatalogCheckTest/";
|
||||
|
||||
[NUnit.Framework.OneTimeSetUp]
|
||||
public static void BeforeClass() {
|
||||
CreateOrClearDestinationFolder(destinationFolder);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CatalogCheck03() {
|
||||
String outPdf = destinationFolder + "pdfA2b_catalogCheck03.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA2b_catalogCheck03.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary ocProperties = new PdfDictionary();
|
||||
PdfDictionary d = new PdfDictionary();
|
||||
d.Put(PdfName.Name, new PdfString("CustomName"));
|
||||
PdfArray configs = new PdfArray();
|
||||
PdfDictionary config = new PdfDictionary();
|
||||
config.Put(PdfName.Name, new PdfString("CustomName1"));
|
||||
configs.Add(config);
|
||||
config = new PdfDictionary();
|
||||
config.Put(PdfName.Name, new PdfString("CustomName2"));
|
||||
configs.Add(config);
|
||||
ocProperties.Put(PdfName.D, d);
|
||||
ocProperties.Put(PdfName.Configs, configs);
|
||||
doc.GetCatalog().Put(PdfName.OCProperties, ocProperties);
|
||||
doc.Close();
|
||||
NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(outPdf));
|
||||
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CatalogCheck04() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary ocProperties = new PdfDictionary();
|
||||
PdfDictionary d = new PdfDictionary();
|
||||
PdfArray configs = new PdfArray();
|
||||
PdfDictionary config = new PdfDictionary();
|
||||
config.Put(PdfName.Name, new PdfString("CustomName1"));
|
||||
configs.Add(config);
|
||||
config = new PdfDictionary();
|
||||
config.Put(PdfName.Name, new PdfString("CustomName2"));
|
||||
configs.Add(config);
|
||||
ocProperties.Put(PdfName.D, d);
|
||||
ocProperties.Put(PdfName.Configs, configs);
|
||||
doc.GetCatalog().Put(PdfName.OCProperties, ocProperties);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.OPTIONAL_CONTENT_CONFIGURATION_DICTIONARY_SHALL_CONTAIN_NAME_ENTRY
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CatalogCheck05() {
|
||||
String outPdf = destinationFolder + "pdfA2b_catalogCheck05.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA2b_catalogCheck05.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary ocProperties = new PdfDictionary();
|
||||
PdfDictionary d = new PdfDictionary();
|
||||
d.Put(PdfName.Name, new PdfString("CustomName"));
|
||||
PdfArray configs = new PdfArray();
|
||||
PdfDictionary config = new PdfDictionary();
|
||||
config.Put(PdfName.Name, new PdfString("CustomName1"));
|
||||
PdfArray order = new PdfArray();
|
||||
PdfDictionary orderItem = new PdfDictionary();
|
||||
orderItem.Put(PdfName.Name, new PdfString("CustomName2"));
|
||||
order.Add(orderItem);
|
||||
PdfDictionary orderItem1 = new PdfDictionary();
|
||||
orderItem1.Put(PdfName.Name, new PdfString("CustomName3"));
|
||||
order.Add(orderItem1);
|
||||
config.Put(PdfName.Order, order);
|
||||
PdfArray ocgs = new PdfArray();
|
||||
ocgs.Add(orderItem);
|
||||
ocgs.Add(orderItem1);
|
||||
ocProperties.Put(PdfName.OCGs, ocgs);
|
||||
configs.Add(config);
|
||||
ocProperties.Put(PdfName.D, d);
|
||||
ocProperties.Put(PdfName.Configs, configs);
|
||||
doc.GetCatalog().Put(PdfName.OCProperties, ocProperties);
|
||||
doc.Close();
|
||||
NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(outPdf));
|
||||
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
private void CompareResult(String outPdf, String cmpPdf) {
|
||||
String result = new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_");
|
||||
if (result != null) {
|
||||
NUnit.Framework.Assert.Fail(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
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.Commons.Utils;
|
||||
using TSpdf.Kernel.Font;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Pdf.Canvas;
|
||||
using TSpdf.Kernel.Pdf.Filespec;
|
||||
using TSpdf.Kernel.Utils;
|
||||
using TSpdf.Pdfa.Logs;
|
||||
using TSpdf.Test;
|
||||
using TSpdf.Test.Attributes;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfA2EmbeddedFilesCheckTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
public static readonly String cmpFolder = sourceFolder + "cmp/PdfA2EmbeddedFilesCheckTest/";
|
||||
|
||||
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/PdfA2EmbeddedFilesCheckTest/";
|
||||
|
||||
[NUnit.Framework.OneTimeSetUp]
|
||||
public static void BeforeClass() {
|
||||
CreateOrClearDestinationFolder(destinationFolder);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
[LogMessage(PdfAConformanceLogMessageConstant.EMBEDDED_FILE_SHALL_BE_COMPLIANT_WITH_SPEC, Count = 1)]
|
||||
public virtual void FileSpecNonConformingTest01() {
|
||||
// According to spec, only pdfa-1 or pdfa-2 compliant pdf document are allowed to be added to the
|
||||
// conforming pdfa-2 document. We only check they mime type, to define embedded file type, but we don't check
|
||||
// the bytes of the file. That's why this test creates invalid pdfa document.
|
||||
String outPdf = destinationFolder + "pdfA2b_fileSpecNonConformingTest01.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA2b_fileSpecNonConformingTest01.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument pdfDocument = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, outputIntent);
|
||||
PdfPage page = pdfDocument.AddNewPage();
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
PdfCanvas canvas = new PdfCanvas(page);
|
||||
canvas.SaveState().BeginText().MoveText(36, 700).SetFontAndSize(font, 36).ShowText("Hello World!").EndText
|
||||
().RestoreState();
|
||||
byte[] somePdf = new byte[25];
|
||||
pdfDocument.AddAssociatedFile("some pdf file", PdfFileSpec.CreateEmbeddedFileSpec(pdfDocument, somePdf, "some pdf file"
|
||||
, "foo.pdf", PdfName.ApplicationPdf, null, new PdfName("Data")));
|
||||
pdfDocument.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
[LogMessage(PdfAConformanceLogMessageConstant.EMBEDDED_FILE_SHALL_BE_COMPLIANT_WITH_SPEC, Count = 1)]
|
||||
public virtual void FileSpecCheckTest02() {
|
||||
String outPdf = destinationFolder + "pdfA2b_fileSpecCheckTest02.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA2b_fileSpecCheckTest02.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument pdfDocument = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, outputIntent);
|
||||
PdfPage page = pdfDocument.AddNewPage();
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
PdfCanvas canvas = new PdfCanvas(page);
|
||||
canvas.SaveState().BeginText().MoveText(36, 700).SetFontAndSize(font, 36).ShowText("Hello World!").EndText
|
||||
().RestoreState();
|
||||
FileStream fis = new FileStream(sourceFolder + "pdfs/pdfa.pdf", FileMode.Open, FileAccess.Read);
|
||||
MemoryStream os = new MemoryStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
while ((length = fis.JRead(buffer, 0, buffer.Length)) > 0) {
|
||||
os.Write(buffer, 0, length);
|
||||
}
|
||||
pdfDocument.AddFileAttachment("some pdf file", PdfFileSpec.CreateEmbeddedFileSpec(pdfDocument, os.ToArray(
|
||||
), "some pdf file", "foo.pdf", PdfName.ApplicationPdf, null, null));
|
||||
pdfDocument.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
[LogMessage(PdfAConformanceLogMessageConstant.EMBEDDED_FILE_SHALL_BE_COMPLIANT_WITH_SPEC, Count = 1)]
|
||||
public virtual void FileSpecCheckTest03() {
|
||||
PdfWriter writer = new PdfWriter(new MemoryStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument pdfDocument = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, outputIntent);
|
||||
PdfPage page = pdfDocument.AddNewPage();
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
PdfCanvas canvas = new PdfCanvas(page);
|
||||
canvas.SaveState().BeginText().MoveText(36, 700).SetFontAndSize(font, 36).ShowText("Hello World!").EndText
|
||||
().RestoreState();
|
||||
MemoryStream txt = new MemoryStream();
|
||||
FormattingStreamWriter @out = new FormattingStreamWriter(txt);
|
||||
@out.Write("<foo><foo2>Hello world</foo2></foo>");
|
||||
@out.Dispose();
|
||||
pdfDocument.AddFileAttachment("foo file", PdfFileSpec.CreateEmbeddedFileSpec(pdfDocument, txt.ToArray(), "foo file"
|
||||
, "foo.xml", PdfName.ApplicationXml, null, PdfName.Source));
|
||||
pdfDocument.Close();
|
||||
}
|
||||
|
||||
private void CompareResult(String outPdf, String cmpPdf) {
|
||||
String result = new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_");
|
||||
if (result != null) {
|
||||
NUnit.Framework.Assert.Fail(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,555 @@
|
||||
/*
|
||||
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.Commons.Utils;
|
||||
using TSpdf.IO.Image;
|
||||
using TSpdf.IO.Source;
|
||||
using TSpdf.Kernel.Colors;
|
||||
using TSpdf.Kernel.Font;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Pdf.Canvas;
|
||||
using TSpdf.Kernel.Pdf.Colorspace;
|
||||
using TSpdf.Kernel.Pdf.Extgstate;
|
||||
using TSpdf.Kernel.Pdf.Function;
|
||||
using TSpdf.Kernel.Utils;
|
||||
using TSpdf.Pdfa.Exceptions;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfA2GraphicsCheckTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
public static readonly String cmpFolder = sourceFolder + "cmp/PdfA2GraphicsCheckTest/";
|
||||
|
||||
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/PdfA2GraphicsCheckTest/";
|
||||
|
||||
[NUnit.Framework.OneTimeSetUp]
|
||||
public static void BeforeClass() {
|
||||
CreateOrClearDestinationFolder(destinationFolder);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ColorCheckTest1() {
|
||||
PdfWriter writer = new PdfWriter(new MemoryStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
using (PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, outputIntent)) {
|
||||
float[] whitePoint = new float[] { 0.9505f, 1f, 1.089f };
|
||||
float[] gamma = new float[] { 2.2f, 2.2f, 2.2f };
|
||||
float[] matrix = new float[] { 0.4124f, 0.2126f, 0.0193f, 0.3576f, 0.7152f, 0.1192f, 0.1805f, 0.0722f, 0.9505f
|
||||
};
|
||||
PdfCieBasedCs.CalRgb calRgb = new PdfCieBasedCs.CalRgb(whitePoint, null, gamma, matrix);
|
||||
PdfCanvas canvas = new PdfCanvas(doc.AddNewPage());
|
||||
canvas.GetResources().SetDefaultCmyk(calRgb);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => canvas.SetFillColor(new
|
||||
DeviceCmyk(0.1f, 0.1f, 0.1f, 0.1f)));
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException.COLOR_SPACE_0_SHALL_HAVE_1_COMPONENTS
|
||||
, PdfName.DefaultCMYK.GetValue(), 4), e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ColorCheckTest2() {
|
||||
String outPdf = destinationFolder + "pdfA2b_colorCheckTest2.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA2b_colorCheckTest2.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
using (PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, null)) {
|
||||
float[] whitePoint = new float[] { 0.9505f, 1f, 1.089f };
|
||||
float[] gamma = new float[] { 2.2f, 2.2f, 2.2f };
|
||||
float[] matrix = new float[] { 0.4124f, 0.2126f, 0.0193f, 0.3576f, 0.7152f, 0.1192f, 0.1805f, 0.0722f, 0.9505f
|
||||
};
|
||||
PdfCieBasedCs.CalRgb calRgb = new PdfCieBasedCs.CalRgb(whitePoint, null, gamma, matrix);
|
||||
PdfCieBasedCs.CalGray calGray = new PdfCieBasedCs.CalGray(whitePoint, null, 2.2f);
|
||||
PdfCanvas canvas = new PdfCanvas(doc.AddNewPage());
|
||||
canvas.GetResources().SetDefaultRgb(calRgb);
|
||||
canvas.GetResources().SetDefaultGray(calGray);
|
||||
String shortText = "text";
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", PdfFontFactory.EmbeddingStrategy.PREFER_EMBEDDED
|
||||
);
|
||||
canvas.SetFontAndSize(font, 12);
|
||||
canvas.SetFillColor(ColorConstants.RED).BeginText().ShowText(shortText).EndText();
|
||||
canvas.SetFillColor(DeviceGray.GRAY).BeginText().ShowText(shortText).EndText();
|
||||
}
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ColorCheckTest3() {
|
||||
PdfWriter writer = new PdfWriter(new MemoryStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, outputIntent);
|
||||
PdfCanvas canvas = new PdfCanvas(doc.AddNewPage());
|
||||
canvas.SetFillColor(new DeviceCmyk(0.1f, 0.1f, 0.1f, 0.1f));
|
||||
canvas.MoveTo(doc.GetDefaultPageSize().GetLeft(), doc.GetDefaultPageSize().GetBottom());
|
||||
canvas.LineTo(doc.GetDefaultPageSize().GetRight(), doc.GetDefaultPageSize().GetBottom());
|
||||
canvas.LineTo(doc.GetDefaultPageSize().GetRight(), doc.GetDefaultPageSize().GetTop());
|
||||
canvas.Fill();
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.DEVICECMYK_MAY_BE_USED_ONLY_IF_THE_FILE_HAS_A_CMYK_PDFA_OUTPUT_INTENT_OR_DEFAULTCMYK_IN_USAGE_CONTEXT
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ColorCheckTest4() {
|
||||
String outPdf = destinationFolder + "pdfA2b_colorCheckTest4.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA2b_colorCheckTest4.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, outputIntent);
|
||||
PdfCanvas canvas = new PdfCanvas(doc.AddNewPage());
|
||||
canvas.SetFillColor(ColorConstants.BLUE);
|
||||
canvas.SetStrokeColor(new DeviceCmyk(0.1f, 0.1f, 0.1f, 0.1f));
|
||||
canvas.MoveTo(doc.GetDefaultPageSize().GetLeft(), doc.GetDefaultPageSize().GetBottom());
|
||||
canvas.LineTo(doc.GetDefaultPageSize().GetRight(), doc.GetDefaultPageSize().GetBottom());
|
||||
canvas.LineTo(doc.GetDefaultPageSize().GetRight(), doc.GetDefaultPageSize().GetTop());
|
||||
canvas.Fill();
|
||||
canvas.SetFillColor(DeviceGray.BLACK);
|
||||
canvas.MoveTo(doc.GetDefaultPageSize().GetLeft(), doc.GetDefaultPageSize().GetBottom());
|
||||
canvas.LineTo(doc.GetDefaultPageSize().GetRight(), doc.GetDefaultPageSize().GetBottom());
|
||||
canvas.LineTo(doc.GetDefaultPageSize().GetRight(), doc.GetDefaultPageSize().GetTop());
|
||||
canvas.Fill();
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.DEVICECMYK_MAY_BE_USED_ONLY_IF_THE_FILE_HAS_A_CMYK_PDFA_OUTPUT_INTENT_OR_DEFAULTCMYK_IN_USAGE_CONTEXT
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ColorCheckTest5() {
|
||||
PdfWriter writer = new PdfWriter(new MemoryStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, outputIntent);
|
||||
PdfCanvas canvas = new PdfCanvas(doc.AddNewPage());
|
||||
String shortText = "text";
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", PdfFontFactory.EmbeddingStrategy.PREFER_EMBEDDED
|
||||
);
|
||||
canvas.SetFontAndSize(font, 12);
|
||||
canvas.SetTextRenderingMode(PdfCanvasConstants.TextRenderingMode.CLIP);
|
||||
canvas.SetFillColor(ColorConstants.RED).BeginText().ShowText(shortText).EndText();
|
||||
canvas.SetTextRenderingMode(PdfCanvasConstants.TextRenderingMode.STROKE);
|
||||
canvas.SetStrokeColor(new DeviceCmyk(0.1f, 0.1f, 0.1f, 0.1f)).BeginText().ShowText(shortText).EndText();
|
||||
canvas.SetTextRenderingMode(PdfCanvasConstants.TextRenderingMode.FILL);
|
||||
canvas.SetFillColor(DeviceGray.GRAY).BeginText().ShowText(shortText).EndText();
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.DEVICECMYK_MAY_BE_USED_ONLY_IF_THE_FILE_HAS_A_CMYK_PDFA_OUTPUT_INTENT_OR_DEFAULTCMYK_IN_USAGE_CONTEXT
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ColorCheckTest6() {
|
||||
String outPdf = destinationFolder + "pdfA2b_colorCheckTest6.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA2b_colorCheckTest6.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, outputIntent);
|
||||
PdfCanvas canvas = new PdfCanvas(doc.AddNewPage());
|
||||
String shortText = "text";
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", PdfFontFactory.EmbeddingStrategy.PREFER_EMBEDDED
|
||||
);
|
||||
canvas.SetFontAndSize(font, 12);
|
||||
canvas.SetStrokeColor(new DeviceCmyk(0.1f, 0.1f, 0.1f, 0.1f));
|
||||
canvas.SetFillColor(ColorConstants.RED);
|
||||
canvas.BeginText().ShowText(shortText).EndText();
|
||||
canvas.SetFillColor(DeviceGray.GRAY).BeginText().ShowText(shortText).EndText();
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.DEVICECMYK_MAY_BE_USED_ONLY_IF_THE_FILE_HAS_A_CMYK_PDFA_OUTPUT_INTENT_OR_DEFAULTCMYK_IN_USAGE_CONTEXT
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ColorCheckTest7() {
|
||||
String outPdf = destinationFolder + "pdfA2b_colorCheckTest7.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA2b_colorCheckTest7.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, outputIntent);
|
||||
PdfCanvas canvas = new PdfCanvas(doc.AddNewPage());
|
||||
String shortText = "text";
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", PdfFontFactory.EmbeddingStrategy.PREFER_EMBEDDED
|
||||
);
|
||||
canvas.SetFontAndSize(font, 12);
|
||||
canvas.SetTextRenderingMode(PdfCanvasConstants.TextRenderingMode.STROKE);
|
||||
canvas.SetFillColor(new DeviceCmyk(0.1f, 0.1f, 0.1f, 0.1f)).BeginText().ShowText(shortText).EndText();
|
||||
canvas.SetTextRenderingMode(PdfCanvasConstants.TextRenderingMode.STROKE);
|
||||
canvas.SetFillColor(DeviceGray.GRAY).BeginText().ShowText(shortText).EndText();
|
||||
canvas.SetTextRenderingMode(PdfCanvasConstants.TextRenderingMode.INVISIBLE);
|
||||
canvas.SetFillColor(new DeviceCmyk(0.1f, 0.1f, 0.1f, 0.1f)).BeginText().ShowText(shortText).EndText();
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.DEVICECMYK_MAY_BE_USED_ONLY_IF_THE_FILE_HAS_A_CMYK_PDFA_OUTPUT_INTENT_OR_DEFAULTCMYK_IN_USAGE_CONTEXT
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void DefaultTextColorCheckTest() {
|
||||
String outPdf = destinationFolder + "defaultColorCheck.pdf";
|
||||
PdfDocument pdfDocument = new PdfADocument(new PdfWriter(outPdf), PdfAConformanceLevel.PDF_A_2B, null);
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "Identity-H", PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
PdfPage page = pdfDocument.AddNewPage();
|
||||
PdfCanvas canvas = new PdfCanvas(page);
|
||||
canvas.SaveState();
|
||||
canvas.BeginText().MoveText(36, 750).SetFontAndSize(font, 16).ShowText("some text").EndText().RestoreState
|
||||
();
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfDocument.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException.IF_DEVICE_RGB_CMYK_GRAY_USED_IN_FILE_THAT_FILE_SHALL_CONTAIN_PDFA_OUTPUTINTENT_OR_DEFAULT_RGB_CMYK_GRAY_IN_USAGE_CONTEXT
|
||||
), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void DefaultTextColorCheckForInvisibleTextTest() {
|
||||
String outPdf = destinationFolder + "defaultColorCheckInvisibleText.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA2b_defaultColorCheckInvisibleText.pdf";
|
||||
PdfDocument pdfDocument = new PdfADocument(new PdfWriter(outPdf), PdfAConformanceLevel.PDF_A_2B, null);
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "Identity-H", PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
PdfPage page = pdfDocument.AddNewPage();
|
||||
PdfCanvas canvas = new PdfCanvas(page);
|
||||
canvas.SaveState();
|
||||
canvas.BeginText().SetTextRenderingMode(PdfCanvasConstants.TextRenderingMode.INVISIBLE).MoveText(36, 750).
|
||||
SetFontAndSize(font, 16).ShowText("some text").EndText().RestoreState();
|
||||
pdfDocument.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void DefaultStrokeColorCheckTest() {
|
||||
String outPdf = destinationFolder + "defaultColorCheck.pdf";
|
||||
PdfDocument pdfDocument = new PdfADocument(new PdfWriter(outPdf), PdfAConformanceLevel.PDF_A_2B, null);
|
||||
PdfPage page = pdfDocument.AddNewPage();
|
||||
PdfCanvas canvas = new PdfCanvas(page);
|
||||
canvas.SaveState();
|
||||
float[] whitePoint = new float[] { 0.9505f, 1f, 1.089f };
|
||||
float[] gamma = new float[] { 2.2f, 2.2f, 2.2f };
|
||||
float[] matrix = new float[] { 0.4124f, 0.2126f, 0.0193f, 0.3576f, 0.7152f, 0.1192f, 0.1805f, 0.0722f, 0.9505f
|
||||
};
|
||||
PdfCieBasedCs.CalRgb calRgb = new PdfCieBasedCs.CalRgb(whitePoint, null, gamma, matrix);
|
||||
canvas.GetResources().SetDefaultRgb(calRgb);
|
||||
canvas.SetFillColor(ColorConstants.BLUE);
|
||||
canvas.MoveTo(pdfDocument.GetDefaultPageSize().GetLeft(), pdfDocument.GetDefaultPageSize().GetBottom());
|
||||
canvas.LineTo(pdfDocument.GetDefaultPageSize().GetRight(), pdfDocument.GetDefaultPageSize().GetBottom());
|
||||
canvas.LineTo(pdfDocument.GetDefaultPageSize().GetRight(), pdfDocument.GetDefaultPageSize().GetTop());
|
||||
canvas.Stroke();
|
||||
// We set fill color but stroked so the exception should be thrown
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfDocument.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException.IF_DEVICE_RGB_CMYK_GRAY_USED_IN_FILE_THAT_FILE_SHALL_CONTAIN_PDFA_OUTPUTINTENT_OR_DEFAULT_RGB_CMYK_GRAY_IN_USAGE_CONTEXT
|
||||
), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void EgsCheckTest1() {
|
||||
PdfWriter writer = new PdfWriter(new MemoryStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, outputIntent);
|
||||
doc.AddNewPage();
|
||||
PdfCanvas canvas = new PdfCanvas(doc.GetLastPage());
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => canvas.SetExtGState(new
|
||||
PdfExtGState().Put(PdfName.HTP, new PdfName("Test"))));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.AN_EXTGSTATE_DICTIONARY_SHALL_NOT_CONTAIN_THE_HTP_KEY
|
||||
, e.Message);
|
||||
canvas.Rectangle(30, 30, 100, 100).Fill();
|
||||
doc.Close();
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void EgsCheckTest2() {
|
||||
PdfWriter writer = new PdfWriter(new MemoryStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
using (PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, outputIntent)) {
|
||||
doc.AddNewPage();
|
||||
PdfCanvas canvas = new PdfCanvas(doc.GetLastPage());
|
||||
PdfDictionary dict = new PdfDictionary();
|
||||
dict.Put(PdfName.HalftoneType, new PdfNumber(5));
|
||||
dict.Put(PdfName.HalftoneName, new PdfName("Test"));
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => canvas.SetExtGState(new
|
||||
PdfExtGState().SetHalftone(dict)));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.HALFTONES_SHALL_NOT_CONTAIN_HALFTONENAME, e.Message
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ImageCheckTest1() {
|
||||
PdfWriter writer = new PdfWriter(new MemoryStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, outputIntent);
|
||||
doc.AddNewPage();
|
||||
PdfCanvas canvas = new PdfCanvas(doc.GetLastPage());
|
||||
canvas.AddImageAt(ImageDataFactory.Create(sourceFolder + "jpeg2000/p0_01.j2k"), 300, 300, false);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.ONLY_JPX_BASELINE_SET_OF_FEATURES_SHALL_BE_USED,
|
||||
e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ImageCheckTest2() {
|
||||
PdfWriter writer = new PdfWriter(new MemoryStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, outputIntent);
|
||||
doc.AddNewPage();
|
||||
PdfCanvas canvas = new PdfCanvas(doc.GetLastPage());
|
||||
canvas.AddImageAt(ImageDataFactory.Create(sourceFolder + "jpeg2000/file5.jp2"), 300, 300, false);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.EXACTLY_ONE_COLOUR_SPACE_SPECIFICATION_SHALL_HAVE_THE_VALUE_0X01_IN_THE_APPROX_FIELD
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ImageCheckTest3() {
|
||||
PdfWriter writer = new PdfWriter(new MemoryStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, outputIntent);
|
||||
doc.AddNewPage();
|
||||
PdfCanvas canvas = new PdfCanvas(doc.GetLastPage());
|
||||
canvas.AddImageAt(ImageDataFactory.Create(sourceFolder + "jpeg2000/file7.jp2"), 300, 300, false);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.EXACTLY_ONE_COLOUR_SPACE_SPECIFICATION_SHALL_HAVE_THE_VALUE_0X01_IN_THE_APPROX_FIELD
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// NOTE: resultant file of this test fails acrobat's preflight check,
|
||||
/// but it seems to me that preflight fails to check jpeg2000 file.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// NOTE: resultant file of this test fails acrobat's preflight check,
|
||||
/// but it seems to me that preflight fails to check jpeg2000 file.
|
||||
/// This file also fails check on http://www.pdf-tools.com/pdf/validate-pdfa-online.aspx,
|
||||
/// but there it's stated that "The key ColorSpace is required but missing" but according to spec, jpeg2000 images
|
||||
/// can omit ColorSpace entry if color space is defined implicitly in the image itself.
|
||||
/// </remarks>
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ImageCheckTest4() {
|
||||
String outPdf = destinationFolder + "pdfA2b_imageCheckTest4.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA2b_imageCheckTest4.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, outputIntent);
|
||||
PdfCanvas canvas;
|
||||
for (int i = 1; i < 5; ++i) {
|
||||
canvas = new PdfCanvas(doc.AddNewPage());
|
||||
canvas.AddImageAt(ImageDataFactory.Create(MessageFormatUtil.Format(sourceFolder + "jpeg2000/file{0}.jp2",
|
||||
i.ToString())), 300, 300, false);
|
||||
}
|
||||
canvas = new PdfCanvas(doc.AddNewPage());
|
||||
canvas.AddImageAt(ImageDataFactory.Create(sourceFolder + "jpeg2000/file6.jp2"), 300, 300, false);
|
||||
for (int i = 8; i < 10; ++i) {
|
||||
canvas = new PdfCanvas(doc.AddNewPage());
|
||||
canvas.AddImageAt(ImageDataFactory.Create(MessageFormatUtil.Format(sourceFolder + "jpeg2000/file{0}.jp2",
|
||||
i.ToString())), 300, 300, false);
|
||||
}
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void TransparencyCheckTest1() {
|
||||
PdfWriter writer = new PdfWriter(new MemoryStream());
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, null);
|
||||
PdfCanvas canvas = new PdfCanvas(doc.AddNewPage());
|
||||
canvas.SaveState();
|
||||
canvas.SetExtGState(new PdfExtGState().SetBlendMode(PdfName.Darken));
|
||||
canvas.Rectangle(100, 100, 100, 100);
|
||||
canvas.Fill();
|
||||
canvas.RestoreState();
|
||||
canvas.SaveState();
|
||||
canvas.SetExtGState(new PdfExtGState().SetBlendMode(PdfName.Lighten));
|
||||
canvas.Rectangle(200, 200, 100, 100);
|
||||
canvas.Fill();
|
||||
canvas.RestoreState();
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.THE_DOCUMENT_DOES_NOT_CONTAIN_A_PDFA_OUTPUTINTENT_BUT_PAGE_CONTAINS_TRANSPARENCY_AND_DOES_NOT_CONTAIN_BLENDING_COLOR_SPACE
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void TransparencyCheckTest2() {
|
||||
String outPdf = destinationFolder + "pdfA2b_transparencyCheckTest2.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA2b_transparencyCheckTest2.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, outputIntent);
|
||||
PdfCanvas canvas = new PdfCanvas(doc.AddNewPage());
|
||||
canvas.SaveState();
|
||||
canvas.SetExtGState(new PdfExtGState().SetBlendMode(PdfName.Darken));
|
||||
canvas.Rectangle(100, 100, 100, 100);
|
||||
canvas.Fill();
|
||||
canvas.RestoreState();
|
||||
canvas.SaveState();
|
||||
canvas.SetExtGState(new PdfExtGState().SetBlendMode(PdfName.Lighten));
|
||||
canvas.Rectangle(200, 200, 100, 100);
|
||||
canvas.Fill();
|
||||
canvas.RestoreState();
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void TransparencyCheckTest3() {
|
||||
PdfWriter writer = new PdfWriter(new MemoryStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
using (PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, outputIntent)) {
|
||||
PdfCanvas canvas = new PdfCanvas(doc.AddNewPage());
|
||||
canvas.SaveState();
|
||||
canvas.SetExtGState(new PdfExtGState().SetBlendMode(PdfName.Darken));
|
||||
canvas.Rectangle(100, 100, 100, 100);
|
||||
canvas.Fill();
|
||||
canvas.RestoreState();
|
||||
canvas.SaveState();
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => canvas.SetExtGState(new
|
||||
PdfExtGState().SetBlendMode(new PdfName("UnknownBlendMode"))));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.ONLY_STANDARD_BLEND_MODES_SHALL_BE_USED_FOR_THE_VALUE_OF_THE_BM_KEY_IN_AN_EXTENDED_GRAPHIC_STATE_DICTIONARY
|
||||
, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ColourSpaceTest01() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
PdfColorSpace alternateSpace = new PdfDeviceCs.Rgb();
|
||||
//Tint transformation function is a stream
|
||||
byte[] samples = new byte[] { 0x00, 0x00, 0x00, 0x01, 0x01, 0x01 };
|
||||
PdfArray domain = new PdfArray(new float[] { 0, 1 });
|
||||
PdfArray range = new PdfArray(new float[] { 0, 1, 0, 1, 0, 1 });
|
||||
PdfArray size = new PdfArray(new float[] { 2 });
|
||||
PdfNumber bitsPerSample = new PdfNumber(8);
|
||||
PdfFunction.Type0 type0 = new PdfFunction.Type0(domain, range, size, bitsPerSample, samples);
|
||||
PdfColorSpace separationColourSpace = new PdfSpecialCs.Separation("separationTestFunction0", alternateSpace
|
||||
, type0);
|
||||
//Add to document
|
||||
page.GetResources().AddColorSpace(separationColourSpace);
|
||||
doc.Close();
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ColourSpaceTest02() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
PdfColorSpace alternateSpace = new PdfDeviceCs.Rgb();
|
||||
//Tint transformation function is a dictionary
|
||||
PdfArray domain = new PdfArray(new float[] { 0, 1 });
|
||||
PdfArray range = new PdfArray(new float[] { 0, 1, 0, 1, 0, 1 });
|
||||
PdfArray C0 = new PdfArray(new float[] { 0, 0, 0 });
|
||||
PdfArray C1 = new PdfArray(new float[] { 1, 1, 1 });
|
||||
PdfNumber n = new PdfNumber(1);
|
||||
PdfFunction.Type2 type2 = new PdfFunction.Type2(domain, range, C0, C1, n);
|
||||
PdfColorSpace separationColourSpace = new PdfSpecialCs.Separation("separationTestFunction2", alternateSpace
|
||||
, type2);
|
||||
//Add to document
|
||||
page.GetResources().AddColorSpace(separationColourSpace);
|
||||
doc.Close();
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ColourSpaceTest03() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
PdfColorSpace alternateSpace = new PdfDeviceCs.Rgb();
|
||||
//Tint transformation function is a dictionary
|
||||
PdfArray domain = new PdfArray(new float[] { 0, 1 });
|
||||
PdfArray range = new PdfArray(new float[] { 0, 1, 0, 1, 0, 1 });
|
||||
PdfArray C0 = new PdfArray(new float[] { 0, 0, 0 });
|
||||
PdfArray C1 = new PdfArray(new float[] { 1, 1, 1 });
|
||||
PdfNumber n = new PdfNumber(1);
|
||||
PdfFunction.Type2 type2 = new PdfFunction.Type2(domain, range, C0, C1, n);
|
||||
PdfCanvas canvas = new PdfCanvas(page);
|
||||
String separationName = "separationTest";
|
||||
canvas.SetColor(new Separation(separationName, alternateSpace, type2, 0.5f), true);
|
||||
PdfDictionary attributes = new PdfDictionary();
|
||||
PdfDictionary colorantsDict = new PdfDictionary();
|
||||
colorantsDict.Put(new PdfName(separationName), new PdfSpecialCs.Separation(separationName, alternateSpace,
|
||||
type2).GetPdfObject());
|
||||
attributes.Put(PdfName.Colorants, colorantsDict);
|
||||
DeviceN deviceN = new DeviceN(new PdfSpecialCs.NChannel(JavaCollectionsUtil.SingletonList(separationName),
|
||||
alternateSpace, type2, attributes), new float[] { 0.5f });
|
||||
canvas.SetColor(deviceN, true);
|
||||
doc.Close();
|
||||
}
|
||||
|
||||
private void CompareResult(String outPdf, String cmpPdf) {
|
||||
String result = new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_");
|
||||
if (result != null) {
|
||||
NUnit.Framework.Assert.Fail(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
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.IO.Image;
|
||||
using TSpdf.Kernel.Geom;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Pdf.Canvas;
|
||||
using TSpdf.Kernel.Pdf.Layer;
|
||||
using TSpdf.Kernel.Utils;
|
||||
using TSpdf.Layout.Element;
|
||||
using TSpdf.Test;
|
||||
using TSpdf.Test.Pdfa;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfA2LayoutOcgTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/PdfA2LayoutOcgTest/";
|
||||
|
||||
[NUnit.Framework.SetUp]
|
||||
public virtual void Configure() {
|
||||
CreateDestinationFolder(destinationFolder);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckIfOcgForPdfA2Works() {
|
||||
String fileName = "createdOcgPdfA.pdf";
|
||||
Stream colorStream = new FileStream(sourceFolder + "color/sRGB_CS_profile.icm", FileMode.Open, FileAccess.Read
|
||||
);
|
||||
String outFileName = destinationFolder + fileName;
|
||||
String cmpFileName = sourceFolder + "cmp/PdfA2LayoutOcgTest/cmp_" + fileName;
|
||||
PdfDocument pdfDoc = new PdfADocument(new PdfWriter(outFileName), PdfAConformanceLevel.PDF_A_2A, new PdfOutputIntent
|
||||
("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", colorStream));
|
||||
pdfDoc.SetTagged();
|
||||
pdfDoc.GetCatalog().SetLang(new PdfString("en-US"));
|
||||
pdfDoc.AddNewPage();
|
||||
TSpdf.Layout.Element.Image image1 = new Image(ImageDataFactory.Create(sourceFolder + "images/manualTransparency_for_png.png"
|
||||
));
|
||||
PdfCanvas pdfCanvas = new PdfCanvas(pdfDoc, 1);
|
||||
TSpdf.Layout.Canvas canvas1 = new TSpdf.Layout.Canvas(pdfCanvas, new Rectangle(0, 0, 590, 420));
|
||||
PdfLayer imageLayer1 = new PdfLayer("*SomeTest_image$here@.1", pdfDoc);
|
||||
imageLayer1.SetOn(true);
|
||||
pdfCanvas.BeginLayer(imageLayer1);
|
||||
canvas1.Add(image1);
|
||||
pdfCanvas.EndLayer();
|
||||
canvas1.Close();
|
||||
pdfDoc.Close();
|
||||
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
|
||||
, "diff01_"));
|
||||
NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(outFileName));
|
||||
}
|
||||
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
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.IO.Source;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Pdfa.Exceptions;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfA2PageCheckTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CatalogCheck01() {
|
||||
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
page.GetPdfObject().Put(PdfName.PresSteps, new PdfDictionary());
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.THE_PAGE_DICTIONARY_SHALL_NOT_CONTAIN_PRESSTEPS_ENTRY
|
||||
, e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
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.Pdf;
|
||||
using TSpdf.Kernel.Utils;
|
||||
using TSpdf.Test;
|
||||
using TSpdf.Test.Pdfa;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfA3CatalogCheckTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
public static readonly String cmpFolder = sourceFolder + "cmp/PdfA3CatalogCheckTest/";
|
||||
|
||||
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/PdfA3CatalogCheckTest/";
|
||||
|
||||
[NUnit.Framework.OneTimeSetUp]
|
||||
public static void BeforeClass() {
|
||||
CreateOrClearDestinationFolder(destinationFolder);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CatalogCheck01() {
|
||||
String outPdf = destinationFolder + "pdfA3b_catalogCheck01.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA3b_catalogCheck01.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_3B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfDictionary ocProperties = new PdfDictionary();
|
||||
PdfDictionary d = new PdfDictionary();
|
||||
d.Put(PdfName.Name, new PdfString("CustomName"));
|
||||
PdfDictionary orderItem = new PdfDictionary();
|
||||
orderItem.Put(PdfName.Name, new PdfString("CustomName2"));
|
||||
PdfArray ocgs = new PdfArray();
|
||||
ocgs.Add(orderItem);
|
||||
ocProperties.Put(PdfName.OCGs, ocgs);
|
||||
ocProperties.Put(PdfName.D, d);
|
||||
doc.GetCatalog().Put(PdfName.OCProperties, ocProperties);
|
||||
doc.Close();
|
||||
NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(outPdf));
|
||||
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
|
||||
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
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.Commons.Utils;
|
||||
using TSpdf.Kernel.Font;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Pdf.Canvas;
|
||||
using TSpdf.Kernel.Pdf.Filespec;
|
||||
using TSpdf.Kernel.Utils;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfA3EmbeddedFilesCheckTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
public static readonly String cmpFolder = sourceFolder + "cmp/PdfA3EmbeddedFilesCheckTest/";
|
||||
|
||||
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/PdfA3EmbeddedFilesCheckTest/";
|
||||
|
||||
[NUnit.Framework.OneTimeSetUp]
|
||||
public static void BeforeClass() {
|
||||
CreateOrClearDestinationFolder(destinationFolder);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void FileSpecCheckTest01() {
|
||||
String outPdf = destinationFolder + "pdfA3b_fileSpecCheckTest01.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA3b_fileSpecCheckTest01.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument pdfDocument = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_3B, outputIntent);
|
||||
PdfPage page = pdfDocument.AddNewPage();
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
PdfCanvas canvas = new PdfCanvas(page);
|
||||
canvas.SaveState().BeginText().MoveText(36, 700).SetFontAndSize(font, 36).ShowText("Hello World!").EndText
|
||||
().RestoreState();
|
||||
MemoryStream txt = new MemoryStream();
|
||||
FormattingStreamWriter @out = new FormattingStreamWriter(txt);
|
||||
@out.Write("<foo><foo2>Hello world</foo2></foo>");
|
||||
@out.Dispose();
|
||||
pdfDocument.AddAssociatedFile("foo file", PdfFileSpec.CreateEmbeddedFileSpec(pdfDocument, txt.ToArray(), "foo file"
|
||||
, "foo.xml", PdfName.ApplicationXml, null, PdfName.Source));
|
||||
pdfDocument.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void FileSpecCheckTest02() {
|
||||
String outPdf = destinationFolder + "pdfA3b_fileSpecCheckTest02.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA3b_fileSpecCheckTest02.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument pdfDocument = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_3B, outputIntent);
|
||||
PdfPage page = pdfDocument.AddNewPage();
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
PdfCanvas canvas = new PdfCanvas(page);
|
||||
canvas.SaveState().BeginText().MoveText(36, 700).SetFontAndSize(font, 36).ShowText("Hello World!").EndText
|
||||
().RestoreState();
|
||||
MemoryStream txt = new MemoryStream();
|
||||
FormattingStreamWriter @out = new FormattingStreamWriter(txt);
|
||||
@out.Write("<foo><foo2>Hello world</foo2></foo>");
|
||||
@out.Dispose();
|
||||
pdfDocument.AddAssociatedFile("foo file", PdfFileSpec.CreateEmbeddedFileSpec(pdfDocument, txt.ToArray(), "foo file"
|
||||
, "foo.xml", null, PdfName.Unspecified));
|
||||
pdfDocument.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void FileSpecCheckTest03() {
|
||||
String outPdf = destinationFolder + "pdfA3b_fileSpecCheckTest03.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA3b_fileSpecCheckTest03.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument pdfDocument = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_3B, outputIntent);
|
||||
PdfPage page = pdfDocument.AddNewPage();
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
PdfCanvas canvas = new PdfCanvas(page);
|
||||
canvas.SaveState().BeginText().MoveText(36, 700).SetFontAndSize(font, 36).ShowText("Hello World!").EndText
|
||||
().RestoreState();
|
||||
byte[] somePdf = new byte[25];
|
||||
pdfDocument.AddAssociatedFile("some pdf file", PdfFileSpec.CreateEmbeddedFileSpec(pdfDocument, somePdf, "some pdf file"
|
||||
, "foo.pdf", PdfName.ApplicationPdf, null, PdfName.Data));
|
||||
pdfDocument.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void FileSpecCheckTest04() {
|
||||
String outPdf = destinationFolder + "pdfA3b_fileSpecCheckTest04.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_pdfA3b_fileSpecCheckTest04.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument pdfDocument = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_3B, outputIntent);
|
||||
PdfPage page = pdfDocument.AddNewPage();
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
PdfCanvas canvas = new PdfCanvas(page);
|
||||
canvas.SaveState().BeginText().MoveText(36, 700).SetFontAndSize(font, 36).ShowText("Hello World!").EndText
|
||||
().RestoreState();
|
||||
MemoryStream txt = new MemoryStream();
|
||||
FormattingStreamWriter @out = new FormattingStreamWriter(txt);
|
||||
@out.Write("<foo><foo2>Hello world</foo2></foo>");
|
||||
@out.Dispose();
|
||||
pdfDocument.AddAssociatedFile("foo file", PdfFileSpec.CreateEmbeddedFileSpec(pdfDocument, txt.ToArray(), "foo file"
|
||||
, "foo.xml", PdfName.Unspecified));
|
||||
pdfDocument.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
private void CompareResult(String outPdf, String cmpPdf) {
|
||||
String result = new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_");
|
||||
if (result != null) {
|
||||
NUnit.Framework.Assert.Fail(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
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.IO.Source;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.XMP;
|
||||
using TSpdf.Pdfa.Logs;
|
||||
using TSpdf.Test;
|
||||
using TSpdf.Test.Attributes;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
[NUnit.Framework.Category("UnitTest")]
|
||||
public class PdfAAgnosticPdfDocumentUnitTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/AgnosticPdfDocumentUnitTest/";
|
||||
|
||||
[NUnit.Framework.OneTimeSetUp]
|
||||
public static void BeforeClass() {
|
||||
CreateOrClearDestinationFolder(destinationFolder);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void LoadPdfDocumentTest() {
|
||||
PdfAAgnosticPdfDocumentUnitTest.TestAgnosticPdfDocument pdfDoc = new PdfAAgnosticPdfDocumentUnitTest.TestAgnosticPdfDocument
|
||||
(this, new PdfReader(sourceFolder + "pdfs/simpleDoc.pdf"), new PdfWriter(new ByteArrayOutputStream()));
|
||||
pdfDoc.FlushObjectPublic(pdfDoc.GetPage(1).GetPdfObject(), true);
|
||||
NUnit.Framework.Assert.IsTrue(pdfDoc.GetPage(1).GetPdfObject().IsFlushed());
|
||||
pdfDoc.CheckIsoConformancePublic();
|
||||
// Does nothing for PdfDocument
|
||||
NUnit.Framework.Assert.IsFalse(pdfDoc.GetPageFactoryPublic() is PdfAPageFactory);
|
||||
NUnit.Framework.Assert.IsNull(pdfDoc.GetConformanceLevel());
|
||||
pdfDoc.UpdateXmpMetadataPublic();
|
||||
XMPMeta xmpMeta = XMPMetaFactory.ParseFromBuffer(pdfDoc.GetXmpMetadata(true));
|
||||
NUnit.Framework.Assert.IsNull(xmpMeta.GetProperty(XMPConst.NS_PDFA_ID, XMPConst.PART));
|
||||
NUnit.Framework.Assert.IsNull(xmpMeta.GetProperty(XMPConst.NS_PDFA_ID, XMPConst.CONFORMANCE));
|
||||
pdfDoc.Close();
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
[LogMessage(PdfALogMessageConstant.PDFA_OBJECT_FLUSHING_WAS_NOT_PERFORMED)]
|
||||
public virtual void LoadPdfADocumentTest() {
|
||||
PdfAAgnosticPdfDocumentUnitTest.TestAgnosticPdfDocument pdfADoc = new PdfAAgnosticPdfDocumentUnitTest.TestAgnosticPdfDocument
|
||||
(this, new PdfReader(sourceFolder + "pdfs/pdfa.pdf"), new PdfWriter(new ByteArrayOutputStream()), new
|
||||
StampingProperties());
|
||||
pdfADoc.FlushObjectPublic(pdfADoc.GetPage(1).GetPdfObject(), true);
|
||||
NUnit.Framework.Assert.IsFalse(pdfADoc.GetPage(1).GetPdfObject().IsFlushed());
|
||||
pdfADoc.CheckIsoConformancePublic();
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceLevel.PDF_A_2B, pdfADoc.GetConformanceLevel());
|
||||
NUnit.Framework.Assert.IsTrue(pdfADoc.GetPageFactoryPublic() is PdfAPageFactory);
|
||||
pdfADoc.UpdateXmpMetadataPublic();
|
||||
XMPMeta xmpMeta = XMPMetaFactory.ParseFromBuffer(pdfADoc.GetXmpMetadata(true));
|
||||
NUnit.Framework.Assert.IsNotNull(xmpMeta.GetProperty(XMPConst.NS_PDFA_ID, XMPConst.PART));
|
||||
NUnit.Framework.Assert.IsNotNull(xmpMeta.GetProperty(XMPConst.NS_PDFA_ID, XMPConst.CONFORMANCE));
|
||||
// Extra PdfA error message check
|
||||
pdfADoc.FlushObjectPublic(pdfADoc.GetCatalog().GetPdfObject(), true);
|
||||
NUnit.Framework.Assert.IsFalse(pdfADoc.GetCatalog().GetPdfObject().IsFlushed());
|
||||
pdfADoc.Close();
|
||||
}
|
||||
|
||||
private class TestAgnosticPdfDocument : PdfAAgnosticPdfDocument {
|
||||
public TestAgnosticPdfDocument(PdfAAgnosticPdfDocumentUnitTest _enclosing, PdfReader reader, PdfWriter writer
|
||||
)
|
||||
: base(reader, writer, new StampingProperties()) {
|
||||
this._enclosing = _enclosing;
|
||||
}
|
||||
|
||||
public TestAgnosticPdfDocument(PdfAAgnosticPdfDocumentUnitTest _enclosing, PdfReader reader, PdfWriter writer
|
||||
, StampingProperties properties)
|
||||
: base(reader, writer, properties) {
|
||||
this._enclosing = _enclosing;
|
||||
}
|
||||
|
||||
public virtual void CheckIsoConformancePublic() {
|
||||
base.CheckIsoConformance();
|
||||
}
|
||||
|
||||
public virtual IPdfPageFactory GetPageFactoryPublic() {
|
||||
return base.GetPageFactory();
|
||||
}
|
||||
|
||||
public virtual void UpdateXmpMetadataPublic() {
|
||||
base.UpdateXmpMetadata();
|
||||
}
|
||||
|
||||
public virtual void FlushObjectPublic(PdfObject pdfObject, bool canBeInObjStm) {
|
||||
base.FlushObject(pdfObject, canBeInObjStm);
|
||||
}
|
||||
|
||||
private readonly PdfAAgnosticPdfDocumentUnitTest _enclosing;
|
||||
}
|
||||
}
|
||||
}
|
||||
108
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfAAppendModeTest.cs
Normal file
108
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfAAppendModeTest.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
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.Font;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Pdf.Canvas;
|
||||
using TSpdf.Kernel.Utils;
|
||||
using TSpdf.Test;
|
||||
using TSpdf.Test.Pdfa;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfAAppendModeTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
public const String testDirName = "PdfAAppendModeTest/";
|
||||
|
||||
public static readonly String cmpFolder = sourceFolder + "cmp/" + testDirName;
|
||||
|
||||
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/" + testDirName;
|
||||
|
||||
[NUnit.Framework.OneTimeSetUp]
|
||||
public static void BeforeClass() {
|
||||
CreateOrClearDestinationFolder(destinationFolder);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void AddPageInAppendModeTest() {
|
||||
String inputFile = destinationFolder + "in_addPageInAppendModeTest.pdf";
|
||||
String outputFile = destinationFolder + "out_addPageInAppendModeTest.pdf";
|
||||
String cmpFile = cmpFolder + "cmp_addPageInAppendModeTest.pdf";
|
||||
CreateInputPdfADocument(inputFile);
|
||||
PdfDocument pdfADocument = new PdfADocument(new PdfReader(inputFile), new PdfWriter(outputFile), new StampingProperties
|
||||
().UseAppendMode());
|
||||
PdfCanvas canvas = new PdfCanvas(pdfADocument.AddNewPage());
|
||||
canvas.SaveState().BeginText().MoveText(36, 750).SetFontAndSize(PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf"
|
||||
, PdfFontFactory.EmbeddingStrategy.PREFER_EMBEDDED), 16).ShowText("This page 2").EndText().RestoreState
|
||||
();
|
||||
canvas.Release();
|
||||
pdfADocument.Close();
|
||||
NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(inputFile));
|
||||
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
|
||||
NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(outputFile));
|
||||
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
|
||||
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outputFile, cmpFile, destinationFolder, "diff_"
|
||||
));
|
||||
}
|
||||
|
||||
private static void CreateInputPdfADocument(String docName) {
|
||||
PdfWriter writer = new PdfWriter(docName);
|
||||
PdfADocument pdfDoc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1A, new PdfOutputIntent("Custom"
|
||||
, "", "http://www.color.org", "sRGB IEC61966-2.1", new FileStream(sourceFolder + "sRGB Color Space Profile.icm"
|
||||
, FileMode.Open, FileAccess.Read)));
|
||||
pdfDoc.SetTagged();
|
||||
pdfDoc.GetCatalog().SetLang(new PdfString("en-US"));
|
||||
PdfCanvas canvas = new PdfCanvas(pdfDoc.AddNewPage());
|
||||
canvas.SaveState().BeginText().MoveText(36, 750).SetFontAndSize(PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf"
|
||||
, PdfFontFactory.EmbeddingStrategy.PREFER_EMBEDDED), 16).ShowText("This page 1").EndText().RestoreState
|
||||
();
|
||||
canvas.Release();
|
||||
pdfDoc.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
207
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfABarcodeTest.cs
Normal file
207
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfABarcodeTest.cs
Normal file
@@ -0,0 +1,207 @@
|
||||
/*
|
||||
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.Barcodes;
|
||||
using TSpdf.Kernel.Font;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Pdf.Xobject;
|
||||
using TSpdf.Kernel.Utils;
|
||||
using TSpdf.Layout;
|
||||
using TSpdf.Layout.Element;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfABarcodeTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
public static readonly String cmpFolder = sourceFolder + "cmp/PdfABarcodeTest/";
|
||||
|
||||
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/PdfABarcodeTest/";
|
||||
|
||||
[NUnit.Framework.OneTimeSetUp]
|
||||
public static void BeforeClass() {
|
||||
CreateOrClearDestinationFolder(destinationFolder);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void BarcodeMSITest() {
|
||||
String outPdf = destinationFolder + "barcodeMSITest.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_barcodeMSITest.pdf";
|
||||
Document doc = CreatePdfATaggedDocument(outPdf);
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
font.SetSubset(true);
|
||||
BarcodeMSI codeMSI = new BarcodeMSI(doc.GetPdfDocument(), font);
|
||||
FillBarcode1D(codeMSI, "1234567");
|
||||
PdfFormXObject barcode = codeMSI.CreateFormXObject(doc.GetPdfDocument());
|
||||
Image img = new Image(barcode).SetMargins(0, 0, 0, 0);
|
||||
img.GetAccessibilityProperties().SetAlternateDescription("hello world!");
|
||||
doc.Add(img);
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void BarcodeInter25Test() {
|
||||
String outPdf = destinationFolder + "barcodeInter25Test.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_barcodeInter25Test.pdf";
|
||||
Document doc = CreatePdfATaggedDocument(outPdf);
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
font.SetSubset(true);
|
||||
BarcodeInter25 codeInter25 = new BarcodeInter25(doc.GetPdfDocument(), font);
|
||||
FillBarcode1D(codeInter25, "1234567");
|
||||
PdfFormXObject barcode = codeInter25.CreateFormXObject(doc.GetPdfDocument());
|
||||
Image img = new Image(barcode).SetMargins(0, 0, 0, 0);
|
||||
img.GetAccessibilityProperties().SetAlternateDescription("hello world!");
|
||||
doc.Add(img);
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void BarcodeEANTest() {
|
||||
String outPdf = destinationFolder + "barcodeEANTest.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_barcodeEANTest.pdf";
|
||||
Document doc = CreatePdfATaggedDocument(outPdf);
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
font.SetSubset(true);
|
||||
BarcodeEAN codeEAN = new BarcodeEAN(doc.GetPdfDocument(), font);
|
||||
FillBarcode1D(codeEAN, "9781935182610");
|
||||
PdfFormXObject barcode = codeEAN.CreateFormXObject(doc.GetPdfDocument());
|
||||
Image img = new Image(barcode).SetMargins(0, 0, 0, 0);
|
||||
img.GetAccessibilityProperties().SetAlternateDescription("hello world!");
|
||||
doc.Add(img);
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void BarcodeCodabarTest() {
|
||||
String outPdf = destinationFolder + "barcodeCodabarTest.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_barcodeCodabarTest.pdf";
|
||||
Document doc = CreatePdfATaggedDocument(outPdf);
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
font.SetSubset(true);
|
||||
BarcodeCodabar codeCodabar = new BarcodeCodabar(doc.GetPdfDocument(), font);
|
||||
FillBarcode1D(codeCodabar, "A123A");
|
||||
PdfFormXObject barcode = codeCodabar.CreateFormXObject(doc.GetPdfDocument());
|
||||
Image img = new Image(barcode).SetMargins(0, 0, 0, 0);
|
||||
img.GetAccessibilityProperties().SetAlternateDescription("hello world!");
|
||||
doc.Add(img);
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void Barcode39Test() {
|
||||
String outPdf = destinationFolder + "barcode39Test.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_barcode39Test.pdf";
|
||||
Document doc = CreatePdfATaggedDocument(outPdf);
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
font.SetSubset(true);
|
||||
Barcode39 code39 = new Barcode39(doc.GetPdfDocument(), font);
|
||||
FillBarcode1D(code39, "1234567");
|
||||
PdfFormXObject barcode = code39.CreateFormXObject(doc.GetPdfDocument());
|
||||
Image img = new Image(barcode).SetMargins(0, 0, 0, 0);
|
||||
img.GetAccessibilityProperties().SetAlternateDescription("hello world!");
|
||||
doc.Add(img);
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void Barcode128Test() {
|
||||
String outPdf = destinationFolder + "barcode128Test.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_barcode128Test.pdf";
|
||||
Document doc = CreatePdfATaggedDocument(outPdf);
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
font.SetSubset(true);
|
||||
Barcode128 code128 = new Barcode128(doc.GetPdfDocument(), font);
|
||||
FillBarcode1D(code128, "1234567");
|
||||
PdfFormXObject barcode = code128.CreateFormXObject(doc.GetPdfDocument());
|
||||
Image img = new Image(barcode).SetMargins(0, 0, 0, 0);
|
||||
img.GetAccessibilityProperties().SetAlternateDescription("hello world!");
|
||||
doc.Add(img);
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
private void FillBarcode1D(Barcode1D barcode1D, String code) {
|
||||
barcode1D.SetCode(code);
|
||||
barcode1D.SetCodeType(Barcode128.CODE128);
|
||||
barcode1D.SetSize(10);
|
||||
barcode1D.SetBaseline(barcode1D.GetSize());
|
||||
barcode1D.SetGenerateChecksum(true);
|
||||
barcode1D.SetX(1);
|
||||
barcode1D.SetN(5);
|
||||
barcode1D.SetBarHeight(20);
|
||||
barcode1D.SetChecksumText(false);
|
||||
}
|
||||
|
||||
private Document CreatePdfATaggedDocument(String outPdf) {
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfDocument pdfDocument = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom"
|
||||
, "", "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
Document doc = new Document(pdfDocument);
|
||||
pdfDocument.SetTagged();
|
||||
return doc;
|
||||
}
|
||||
|
||||
private void CompareResult(String outFile, String cmpFile) {
|
||||
String differences = new CompareTool().CompareByContent(outFile, cmpFile, destinationFolder, "diff_");
|
||||
if (differences != null) {
|
||||
NUnit.Framework.Assert.Fail(differences);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
450
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfACheckfieldTest.cs
Normal file
450
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfACheckfieldTest.cs
Normal file
@@ -0,0 +1,450 @@
|
||||
/*
|
||||
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.Forms.Fields;
|
||||
using TSpdf.Kernel.Colors;
|
||||
using TSpdf.Kernel.Geom;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Utils;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfACheckfieldTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
public static readonly String cmpFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/cmp/PdfACheckfieldTest/";
|
||||
|
||||
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/PdfACheckfieldTest/";
|
||||
|
||||
[NUnit.Framework.OneTimeSetUp]
|
||||
public static void BeforeClass() {
|
||||
CreateDestinationFolder(destinationFolder);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA1aCheckFieldOffAppearanceTest() {
|
||||
String name = "pdfA1a_checkFieldOffAppearance";
|
||||
String outPath = destinationFolder + name + ".pdf";
|
||||
String cmpPath = cmpFolder + "cmp_" + name + ".pdf";
|
||||
String diff = "diff_" + name + "_";
|
||||
PdfWriter writer = new PdfWriter(outPath);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1A, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.SetTagged();
|
||||
doc.GetCatalog().SetLang(new PdfString("en-US"));
|
||||
doc.AddNewPage();
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
|
||||
PdfFormField chk = new CheckBoxFormFieldBuilder(doc, "name").SetWidgetRectangle(new Rectangle(100, 500, 50
|
||||
, 50)).SetCheckType(PdfFormField.TYPE_CHECK).SetConformanceLevel(PdfAConformanceLevel.PDF_A_1A).CreateCheckBox
|
||||
().SetValue("Off");
|
||||
chk.GetFirstFormAnnotation().SetBorderColor(ColorConstants.BLACK);
|
||||
chk.GetFirstFormAnnotation().SetBorderWidth(1);
|
||||
form.AddField(chk);
|
||||
doc.Close();
|
||||
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff
|
||||
));
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA1aCheckFieldOnAppearanceTest() {
|
||||
String name = "pdfA1a_checkFieldOnAppearance";
|
||||
String outPath = destinationFolder + name + ".pdf";
|
||||
String cmpPath = cmpFolder + "cmp_" + name + ".pdf";
|
||||
String diff = "diff_" + name + "_";
|
||||
PdfWriter writer = new PdfWriter(outPath);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1A, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.SetTagged();
|
||||
doc.GetCatalog().SetLang(new PdfString("en-US"));
|
||||
doc.AddNewPage();
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
|
||||
PdfFormField chk = new CheckBoxFormFieldBuilder(doc, "name").SetWidgetRectangle(new Rectangle(100, 500, 50
|
||||
, 50)).SetCheckType(PdfFormField.TYPE_CHECK).SetConformanceLevel(PdfAConformanceLevel.PDF_A_1A).CreateCheckBox
|
||||
().SetValue("On");
|
||||
chk.GetFirstFormAnnotation().SetBorderColor(ColorConstants.BLACK);
|
||||
chk.GetFirstFormAnnotation().SetBorderWidth(1);
|
||||
form.AddField(chk);
|
||||
doc.Close();
|
||||
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff
|
||||
));
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA1bCheckFieldOffAppearanceTest() {
|
||||
String name = "pdfA1b_checkFieldOffAppearance";
|
||||
String outPath = destinationFolder + name + ".pdf";
|
||||
String cmpPath = cmpFolder + "cmp_" + name + ".pdf";
|
||||
String diff = "diff_" + name + "_";
|
||||
PdfWriter writer = new PdfWriter(outPath);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
|
||||
PdfFormField chk = new CheckBoxFormFieldBuilder(doc, "name").SetWidgetRectangle(new Rectangle(100, 500, 50
|
||||
, 50)).SetCheckType(PdfFormField.TYPE_CHECK).SetConformanceLevel(PdfAConformanceLevel.PDF_A_1B).CreateCheckBox
|
||||
().SetValue("Off");
|
||||
chk.GetFirstFormAnnotation().SetBorderColor(ColorConstants.BLACK);
|
||||
chk.GetFirstFormAnnotation().SetBorderWidth(1);
|
||||
form.AddField(chk);
|
||||
doc.Close();
|
||||
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff
|
||||
));
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA1bCheckFieldOnAppearanceTest() {
|
||||
String name = "pdfA1b_checkFieldOnAppearance";
|
||||
String outPath = destinationFolder + name + ".pdf";
|
||||
String cmpPath = cmpFolder + "cmp_" + name + ".pdf";
|
||||
String diff = "diff_" + name + "_";
|
||||
PdfWriter writer = new PdfWriter(outPath);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
|
||||
PdfFormField chk = new CheckBoxFormFieldBuilder(doc, "name").SetWidgetRectangle(new Rectangle(100, 500, 50
|
||||
, 50)).SetCheckType(PdfFormField.TYPE_CHECK).SetConformanceLevel(PdfAConformanceLevel.PDF_A_1B).CreateCheckBox
|
||||
().SetValue("On");
|
||||
chk.GetFirstFormAnnotation().SetBorderColor(ColorConstants.BLACK);
|
||||
chk.GetFirstFormAnnotation().SetBorderWidth(1);
|
||||
form.AddField(chk);
|
||||
doc.Close();
|
||||
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff
|
||||
));
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA2aCheckFieldOffAppearanceTest() {
|
||||
String name = "pdfA2a_checkFieldOffAppearance";
|
||||
String outPath = destinationFolder + name + ".pdf";
|
||||
String cmpPath = cmpFolder + "cmp_" + name + ".pdf";
|
||||
String diff = "diff_" + name + "_";
|
||||
PdfWriter writer = new PdfWriter(outPath);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2A, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.SetTagged();
|
||||
doc.GetCatalog().SetLang(new PdfString("en-US"));
|
||||
doc.AddNewPage();
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
|
||||
PdfFormField chk = new CheckBoxFormFieldBuilder(doc, "name").SetWidgetRectangle(new Rectangle(100, 500, 50
|
||||
, 50)).SetCheckType(PdfFormField.TYPE_CHECK).SetConformanceLevel(PdfAConformanceLevel.PDF_A_2A).CreateCheckBox
|
||||
().SetValue("Off");
|
||||
chk.GetFirstFormAnnotation().SetBorderColor(ColorConstants.BLACK);
|
||||
chk.GetFirstFormAnnotation().SetBorderWidth(1);
|
||||
form.AddField(chk);
|
||||
doc.Close();
|
||||
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff
|
||||
));
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA2aCheckFieldOnAppearanceTest() {
|
||||
String name = "pdfA2a_checkFieldOnAppearance";
|
||||
String outPath = destinationFolder + name + ".pdf";
|
||||
String cmpPath = cmpFolder + "cmp_" + name + ".pdf";
|
||||
String diff = "diff_" + name + "_";
|
||||
PdfWriter writer = new PdfWriter(outPath);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2A, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.SetTagged();
|
||||
doc.GetCatalog().SetLang(new PdfString("en-US"));
|
||||
doc.AddNewPage();
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
|
||||
PdfFormField chk = new CheckBoxFormFieldBuilder(doc, "name").SetWidgetRectangle(new Rectangle(100, 500, 50
|
||||
, 50)).SetCheckType(PdfFormField.TYPE_CHECK).SetConformanceLevel(PdfAConformanceLevel.PDF_A_2A).CreateCheckBox
|
||||
().SetValue("On");
|
||||
chk.GetFirstFormAnnotation().SetBorderColor(ColorConstants.BLACK);
|
||||
chk.GetFirstFormAnnotation().SetBorderWidth(1);
|
||||
form.AddField(chk);
|
||||
doc.Close();
|
||||
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff
|
||||
));
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA2bCheckFieldOffAppearanceTest() {
|
||||
String name = "pdfA2b_checkFieldOffAppearance";
|
||||
String outPath = destinationFolder + name + ".pdf";
|
||||
String cmpPath = cmpFolder + "cmp_" + name + ".pdf";
|
||||
String diff = "diff_" + name + "_";
|
||||
PdfWriter writer = new PdfWriter(outPath);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
|
||||
PdfFormField chk = new CheckBoxFormFieldBuilder(doc, "name").SetWidgetRectangle(new Rectangle(100, 500, 50
|
||||
, 50)).SetCheckType(PdfFormField.TYPE_CHECK).SetConformanceLevel(PdfAConformanceLevel.PDF_A_2B).CreateCheckBox
|
||||
().SetValue("Off");
|
||||
chk.GetFirstFormAnnotation().SetBorderColor(ColorConstants.BLACK);
|
||||
chk.GetFirstFormAnnotation().SetBorderWidth(1);
|
||||
form.AddField(chk);
|
||||
doc.Close();
|
||||
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff
|
||||
));
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA2bCheckFieldOnAppearanceTest() {
|
||||
String name = "pdfA2b_checkFieldOnAppearance";
|
||||
String outPath = destinationFolder + name + ".pdf";
|
||||
String cmpPath = cmpFolder + "cmp_" + name + ".pdf";
|
||||
String diff = "diff_" + name + "_";
|
||||
PdfWriter writer = new PdfWriter(outPath);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
|
||||
PdfFormField chk = new CheckBoxFormFieldBuilder(doc, "name").SetWidgetRectangle(new Rectangle(100, 500, 50
|
||||
, 50)).SetCheckType(PdfFormField.TYPE_CHECK).SetConformanceLevel(PdfAConformanceLevel.PDF_A_2B).CreateCheckBox
|
||||
().SetValue("On");
|
||||
chk.GetFirstFormAnnotation().SetBorderColor(ColorConstants.BLACK);
|
||||
chk.GetFirstFormAnnotation().SetBorderWidth(1);
|
||||
form.AddField(chk);
|
||||
doc.Close();
|
||||
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff
|
||||
));
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA2uCheckFieldOffAppearanceTest() {
|
||||
String name = "pdfA2u_checkFieldOffAppearance";
|
||||
String outPath = destinationFolder + name + ".pdf";
|
||||
String cmpPath = cmpFolder + "cmp_" + name + ".pdf";
|
||||
String diff = "diff_" + name + "_";
|
||||
PdfWriter writer = new PdfWriter(outPath);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2U, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
|
||||
PdfFormField chk = new CheckBoxFormFieldBuilder(doc, "name").SetWidgetRectangle(new Rectangle(100, 500, 50
|
||||
, 50)).SetCheckType(PdfFormField.TYPE_CHECK).SetConformanceLevel(PdfAConformanceLevel.PDF_A_2U).CreateCheckBox
|
||||
().SetValue("Off");
|
||||
chk.GetFirstFormAnnotation().SetBorderColor(ColorConstants.BLACK);
|
||||
chk.GetFirstFormAnnotation().SetBorderWidth(1);
|
||||
form.AddField(chk);
|
||||
doc.Close();
|
||||
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff
|
||||
));
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA2uCheckFieldOnAppearanceTest() {
|
||||
String name = "pdfA2u_checkFieldOnAppearance";
|
||||
String outPath = destinationFolder + name + ".pdf";
|
||||
String cmpPath = cmpFolder + "cmp_" + name + ".pdf";
|
||||
String diff = "diff_" + name + "_";
|
||||
PdfWriter writer = new PdfWriter(outPath);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2U, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
|
||||
PdfFormField chk = new CheckBoxFormFieldBuilder(doc, "name").SetWidgetRectangle(new Rectangle(100, 500, 50
|
||||
, 50)).SetCheckType(PdfFormField.TYPE_CHECK).SetConformanceLevel(PdfAConformanceLevel.PDF_A_2U).CreateCheckBox
|
||||
().SetValue("On");
|
||||
chk.GetFirstFormAnnotation().SetBorderColor(ColorConstants.BLACK);
|
||||
chk.GetFirstFormAnnotation().SetBorderWidth(1);
|
||||
form.AddField(chk);
|
||||
doc.Close();
|
||||
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff
|
||||
));
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA3aCheckFieldOffAppearanceTest() {
|
||||
String name = "pdfA3a_checkFieldOffAppearance";
|
||||
String outPath = destinationFolder + name + ".pdf";
|
||||
String cmpPath = cmpFolder + "cmp_" + name + ".pdf";
|
||||
String diff = "diff_" + name + "_";
|
||||
PdfWriter writer = new PdfWriter(outPath);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_3A, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.SetTagged();
|
||||
doc.GetCatalog().SetLang(new PdfString("en-US"));
|
||||
doc.AddNewPage();
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
|
||||
PdfFormField chk = new CheckBoxFormFieldBuilder(doc, "name").SetWidgetRectangle(new Rectangle(100, 500, 50
|
||||
, 50)).SetCheckType(PdfFormField.TYPE_CHECK).SetConformanceLevel(PdfAConformanceLevel.PDF_A_3A).CreateCheckBox
|
||||
().SetValue("Off");
|
||||
chk.GetFirstFormAnnotation().SetBorderColor(ColorConstants.BLACK);
|
||||
chk.GetFirstFormAnnotation().SetBorderWidth(1);
|
||||
form.AddField(chk);
|
||||
doc.Close();
|
||||
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff
|
||||
));
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA3aCheckFieldOnAppearanceTest() {
|
||||
String name = "pdfA3a_checkFieldOnAppearance";
|
||||
String outPath = destinationFolder + name + ".pdf";
|
||||
String cmpPath = cmpFolder + "cmp_" + name + ".pdf";
|
||||
String diff = "diff_" + name + "_";
|
||||
PdfWriter writer = new PdfWriter(outPath);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_3A, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.SetTagged();
|
||||
doc.GetCatalog().SetLang(new PdfString("en-US"));
|
||||
doc.AddNewPage();
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
|
||||
PdfFormField chk = new CheckBoxFormFieldBuilder(doc, "name").SetWidgetRectangle(new Rectangle(100, 500, 50
|
||||
, 50)).SetCheckType(PdfFormField.TYPE_CHECK).SetConformanceLevel(PdfAConformanceLevel.PDF_A_3A).CreateCheckBox
|
||||
().SetValue("On");
|
||||
chk.GetFirstFormAnnotation().SetBorderColor(ColorConstants.BLACK);
|
||||
chk.GetFirstFormAnnotation().SetBorderWidth(1);
|
||||
form.AddField(chk);
|
||||
doc.Close();
|
||||
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff
|
||||
));
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA3bCheckFieldOffAppearanceTest() {
|
||||
String name = "pdfA3b_checkFieldOffAppearance";
|
||||
String outPath = destinationFolder + name + ".pdf";
|
||||
String cmpPath = cmpFolder + "cmp_" + name + ".pdf";
|
||||
String diff = "diff_" + name + "_";
|
||||
PdfWriter writer = new PdfWriter(outPath);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_3B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
|
||||
PdfFormField chk = new CheckBoxFormFieldBuilder(doc, "name").SetWidgetRectangle(new Rectangle(100, 500, 50
|
||||
, 50)).SetCheckType(PdfFormField.TYPE_CHECK).SetConformanceLevel(PdfAConformanceLevel.PDF_A_3B).CreateCheckBox
|
||||
().SetValue("Off");
|
||||
chk.GetFirstFormAnnotation().SetBorderColor(ColorConstants.BLACK);
|
||||
chk.GetFirstFormAnnotation().SetBorderWidth(1);
|
||||
form.AddField(chk);
|
||||
doc.Close();
|
||||
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff
|
||||
));
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA3bCheckFieldOnAppearanceTest() {
|
||||
String name = "pdfA3b_checkFieldOnAppearance";
|
||||
String outPath = destinationFolder + name + ".pdf";
|
||||
String cmpPath = cmpFolder + "cmp_" + name + ".pdf";
|
||||
String diff = "diff_" + name + "_";
|
||||
PdfWriter writer = new PdfWriter(outPath);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_3B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
|
||||
PdfFormField chk = new CheckBoxFormFieldBuilder(doc, "name").SetWidgetRectangle(new Rectangle(100, 500, 50
|
||||
, 50)).SetCheckType(PdfFormField.TYPE_CHECK).SetConformanceLevel(PdfAConformanceLevel.PDF_A_3B).CreateCheckBox
|
||||
().SetValue("On");
|
||||
chk.GetFirstFormAnnotation().SetBorderColor(ColorConstants.BLACK);
|
||||
chk.GetFirstFormAnnotation().SetBorderWidth(1);
|
||||
form.AddField(chk);
|
||||
doc.Close();
|
||||
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff
|
||||
));
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA3uCheckFieldOffAppearanceTest() {
|
||||
String name = "pdfA3u_checkFieldOffAppearance";
|
||||
String outPath = destinationFolder + name + ".pdf";
|
||||
String cmpPath = cmpFolder + "cmp_" + name + ".pdf";
|
||||
String diff = "diff_" + name + "_";
|
||||
PdfWriter writer = new PdfWriter(outPath);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_3U, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
|
||||
PdfFormField chk = new CheckBoxFormFieldBuilder(doc, "name").SetWidgetRectangle(new Rectangle(100, 500, 50
|
||||
, 50)).SetCheckType(PdfFormField.TYPE_CHECK).SetConformanceLevel(PdfAConformanceLevel.PDF_A_3U).CreateCheckBox
|
||||
().SetValue("Off");
|
||||
chk.GetFirstFormAnnotation().SetBorderColor(ColorConstants.BLACK);
|
||||
chk.GetFirstFormAnnotation().SetBorderWidth(1);
|
||||
form.AddField(chk);
|
||||
doc.Close();
|
||||
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff
|
||||
));
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA3uCheckFieldOnAppearanceTest() {
|
||||
String name = "pdfA3u_checkFieldOnAppearance";
|
||||
String outPath = destinationFolder + name + ".pdf";
|
||||
String cmpPath = cmpFolder + "cmp_" + name + ".pdf";
|
||||
String diff = "diff_" + name + "_";
|
||||
PdfWriter writer = new PdfWriter(outPath);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_3U, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
doc.AddNewPage();
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
|
||||
PdfFormField chk = new CheckBoxFormFieldBuilder(doc, "name").SetWidgetRectangle(new Rectangle(100, 500, 50
|
||||
, 50)).SetCheckType(PdfFormField.TYPE_CHECK).SetConformanceLevel(PdfAConformanceLevel.PDF_A_3U).CreateCheckBox
|
||||
().SetValue("On");
|
||||
chk.GetFirstFormAnnotation().SetBorderColor(ColorConstants.BLACK);
|
||||
chk.GetFirstFormAnnotation().SetBorderWidth(1);
|
||||
form.AddField(chk);
|
||||
doc.Close();
|
||||
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
166
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfAFlushingTest.cs
Normal file
166
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfAFlushingTest.cs
Normal file
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
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.IO.Image;
|
||||
using TSpdf.Kernel.Geom;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Pdf.Canvas;
|
||||
using TSpdf.Kernel.Pdf.Xobject;
|
||||
using TSpdf.Kernel.Utils;
|
||||
using TSpdf.Pdfa.Logs;
|
||||
using TSpdf.Test;
|
||||
using TSpdf.Test.Attributes;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfAFlushingTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/PdfAFlushingTest/";
|
||||
|
||||
[NUnit.Framework.OneTimeSetUp]
|
||||
public static void BeforeClass() {
|
||||
CreateOrClearDestinationFolder(destinationFolder);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
[LogMessage(PdfALogMessageConstant.PDFA_OBJECT_FLUSHING_WAS_NOT_PERFORMED)]
|
||||
public virtual void FlushingTest01() {
|
||||
String outPdf = destinationFolder + "pdfA1b_flushingTest01.pdf";
|
||||
String cmpPdf = sourceFolder + "cmp/PdfAFlushingTest/cmp_pdfA1b_flushingTest01.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfCanvas canvas = new PdfCanvas(doc.AddNewPage());
|
||||
PdfImageXObject imageXObject = new PdfImageXObject(ImageDataFactory.Create(sourceFolder + "Desert.jpg"));
|
||||
imageXObject.MakeIndirect(doc);
|
||||
canvas.AddXObjectFittedIntoRectangle(imageXObject, new Rectangle(30, 300, 300, 300));
|
||||
imageXObject.Flush();
|
||||
if (imageXObject.IsFlushed()) {
|
||||
NUnit.Framework.Assert.Fail("Flushing of unchecked objects shall be forbidden.");
|
||||
}
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
[LogMessage(PdfALogMessageConstant.PDFA_PAGE_FLUSHING_WAS_NOT_PERFORMED)]
|
||||
public virtual void FlushingTest02() {
|
||||
String outPdf = destinationFolder + "pdfA2b_flushingTest02.pdf";
|
||||
String cmpPdf = sourceFolder + "cmp/PdfAFlushingTest/cmp_pdfA2b_flushingTest02.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfCanvas canvas = new PdfCanvas(doc.AddNewPage());
|
||||
PdfImageXObject imageXObject = new PdfImageXObject(ImageDataFactory.Create(sourceFolder + "Desert.jpg"));
|
||||
imageXObject.MakeIndirect(doc);
|
||||
canvas.AddXObjectFittedIntoRectangle(imageXObject, new Rectangle(30, 300, 300, 300));
|
||||
PdfPage lastPage = doc.GetLastPage();
|
||||
lastPage.Flush();
|
||||
if (lastPage.IsFlushed()) {
|
||||
NUnit.Framework.Assert.Fail("Flushing of unchecked objects shall be forbidden.");
|
||||
}
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void FlushingTest03() {
|
||||
String outPdf = destinationFolder + "pdfA3b_flushingTest03.pdf";
|
||||
String cmpPdf = sourceFolder + "cmp/PdfAFlushingTest/cmp_pdfA3b_flushingTest03.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_3B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfCanvas canvas = new PdfCanvas(doc.AddNewPage());
|
||||
PdfImageXObject imageXObject = new PdfImageXObject(ImageDataFactory.Create(sourceFolder + "Desert.jpg"));
|
||||
canvas.AddXObjectFittedIntoRectangle(imageXObject, new Rectangle(30, 300, 300, 300));
|
||||
PdfPage lastPage = doc.GetLastPage();
|
||||
lastPage.Flush(true);
|
||||
if (!imageXObject.IsFlushed()) {
|
||||
NUnit.Framework.Assert.Fail("When flushing the page along with it's resources, page check should be performed also page and all resources should be flushed."
|
||||
);
|
||||
}
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
[LogMessage(PdfALogMessageConstant.PDFA_OBJECT_FLUSHING_WAS_NOT_PERFORMED)]
|
||||
public virtual void AddUnusedStreamObjectsTest() {
|
||||
String outPdf = destinationFolder + "pdfA1b_docWithUnusedObjects_3.pdf";
|
||||
String cmpPdf = sourceFolder + "cmp/PdfAFlushingTest/cmp_pdfA1b_docWithUnusedObjects_3.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfADocument pdfDocument = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom"
|
||||
, "", "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
pdfDocument.AddNewPage();
|
||||
PdfDictionary unusedDictionary = new PdfDictionary();
|
||||
PdfArray unusedArray = (PdfArray)new PdfArray().MakeIndirect(pdfDocument);
|
||||
unusedArray.Add(new PdfNumber(42));
|
||||
PdfStream stream = new PdfStream(new byte[] { 1, 2, 34, 45 }, 0);
|
||||
unusedArray.Add(stream);
|
||||
unusedDictionary.Put(new PdfName("testName"), unusedArray);
|
||||
unusedDictionary.MakeIndirect(pdfDocument).Flush();
|
||||
unusedDictionary.Flush();
|
||||
pdfDocument.Close();
|
||||
PdfReader testerReader = new PdfReader(outPdf);
|
||||
PdfDocument testerDocument = new PdfDocument(testerReader);
|
||||
NUnit.Framework.Assert.AreEqual(testerDocument.ListIndirectReferences().Count, 11);
|
||||
testerDocument.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
private void CompareResult(String outFile, String cmpFile) {
|
||||
String differences = new CompareTool().CompareByContent(outFile, cmpFile, destinationFolder, "diff_");
|
||||
if (differences != null) {
|
||||
NUnit.Framework.Assert.Fail(differences);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
327
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfAFontTest.cs
Normal file
327
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfAFontTest.cs
Normal file
@@ -0,0 +1,327 @@
|
||||
/*
|
||||
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.Commons.Utils;
|
||||
using TSpdf.IO.Font;
|
||||
using TSpdf.Kernel.Colors;
|
||||
using TSpdf.Kernel.Font;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Pdf.Canvas;
|
||||
using TSpdf.Kernel.Utils;
|
||||
using TSpdf.Pdfa.Exceptions;
|
||||
using TSpdf.Test;
|
||||
using TSpdf.Test.Pdfa;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfAFontTest : ExtendedTSpdfTest {
|
||||
internal static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
internal static readonly String outputDir = NUnit.Framework.TestContext.CurrentContext.TestDirectory + "/test/TSpdf/pdfa/PdfAFontTest/";
|
||||
|
||||
[NUnit.Framework.OneTimeSetUp]
|
||||
public static void BeforeClass() {
|
||||
CreateOrClearDestinationFolder(outputDir);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void FontCheckPdfA1_01() {
|
||||
String outPdf = outputDir + "pdfA1b_fontCheckPdfA1_01.pdf";
|
||||
String cmpPdf = sourceFolder + "cmp/PdfAFontTest/cmp_pdfA1b_fontCheckPdfA1_01.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfDocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
PdfCanvas canvas = new PdfCanvas(page);
|
||||
canvas.SaveState().SetFillColor(ColorConstants.GREEN).BeginText().MoveText(36, 700).SetFontAndSize(font, 36
|
||||
).ShowText("Hello World! Pdf/A-1B").EndText().RestoreState();
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void FontCheckPdfA1_02() {
|
||||
PdfWriter writer = new PdfWriter(new MemoryStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfDocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", PdfEncodings.WINANSI, PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_NOT_EMBEDDED);
|
||||
PdfCanvas canvas = new PdfCanvas(page);
|
||||
canvas.SaveState().SetFillColor(ColorConstants.GREEN).BeginText().MoveText(36, 700).SetFontAndSize(font, 36
|
||||
).ShowText("Hello World! Pdf/A-1B").EndText().RestoreState();
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException.ALL_THE_FONTS_MUST_BE_EMBEDDED_THIS_ONE_IS_NOT_0
|
||||
, "FreeSans"), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void FontCheckPdfA1_03() {
|
||||
String outPdf = outputDir + "pdfA1b_fontCheckPdfA1_03.pdf";
|
||||
String cmpPdf = sourceFolder + "cmp/PdfAFontTest/cmp_pdfA1b_fontCheckPdfA1_03.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfDocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
// Identity-H must be embedded
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "Identity-H", PdfFontFactory.EmbeddingStrategy
|
||||
.PREFER_NOT_EMBEDDED);
|
||||
PdfCanvas canvas = new PdfCanvas(page);
|
||||
canvas.SaveState().SetFillColor(ColorConstants.GREEN).BeginText().MoveText(36, 700).SetFontAndSize(font, 36
|
||||
).ShowText("Hello World! Pdf/A-1B").EndText().RestoreState();
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void FontCheckPdfA1_04() {
|
||||
PdfWriter writer = new PdfWriter(new MemoryStream());
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfDocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
PdfFont font = PdfFontFactory.CreateFont("Helvetica", "WinAnsi", PdfFontFactory.EmbeddingStrategy.PREFER_EMBEDDED
|
||||
);
|
||||
PdfCanvas canvas = new PdfCanvas(page);
|
||||
canvas.SaveState().SetFillColor(ColorConstants.GREEN).BeginText().MoveText(36, 700).SetFontAndSize(font, 36
|
||||
).ShowText("Hello World! Pdf/A-1B").EndText().RestoreState();
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException.ALL_THE_FONTS_MUST_BE_EMBEDDED_THIS_ONE_IS_NOT_0
|
||||
, "Helvetica"), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void FontCheckPdfA1_05() {
|
||||
String outPdf = outputDir + "pdfA1b_fontCheckPdfA1_05.pdf";
|
||||
String cmpPdf = sourceFolder + "cmp/PdfAFontTest/cmp_pdfA1b_fontCheckPdfA1_05.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfDocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
// Identity-H must be embedded
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "NotoSansCJKtc-Light.otf", "Identity-H");
|
||||
PdfCanvas canvas = new PdfCanvas(page);
|
||||
canvas.SaveState().SetFillColor(ColorConstants.GREEN).BeginText().MoveText(36, 700).SetFontAndSize(font, 36
|
||||
).ShowText("Hello World! Pdf/A-1B").EndText().RestoreState();
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void FontCheckPdfA2_01() {
|
||||
String outPdf = outputDir + "pdfA2b_fontCheckPdfA2_01.pdf";
|
||||
String cmpPdf = sourceFolder + "cmp/PdfAFontTest/cmp_pdfA2b_fontCheckPdfA2_01.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfDocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
// Identity-H must be embedded
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "Identity-H", PdfFontFactory.EmbeddingStrategy
|
||||
.PREFER_NOT_EMBEDDED);
|
||||
PdfCanvas canvas = new PdfCanvas(page);
|
||||
canvas.SaveState().SetFillColor(ColorConstants.GREEN).BeginText().MoveText(36, 700).SetFontAndSize(font, 36
|
||||
).ShowText("Hello World! Pdf/A-2B").EndText().RestoreState();
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void FontCheckPdfA3_01() {
|
||||
String outPdf = outputDir + "pdfA3b_fontCheckPdfA3_01.pdf";
|
||||
String cmpPdf = sourceFolder + "cmp/PdfAFontTest/cmp_pdfA3b_fontCheckPdfA3_01.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfDocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_3B, new PdfOutputIntent("Custom", ""
|
||||
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
// Identity-H must be embedded
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "Identity-H", PdfFontFactory.EmbeddingStrategy
|
||||
.PREFER_NOT_EMBEDDED);
|
||||
PdfCanvas canvas = new PdfCanvas(page);
|
||||
canvas.SaveState().SetFillColor(ColorConstants.GREEN).BeginText().MoveText(36, 700).SetFontAndSize(font, 36
|
||||
).ShowText("Hello World! Pdf/A-3B").EndText().RestoreState();
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CidFontCheckTest1() {
|
||||
String outPdf = outputDir + "pdfA2b_cidFontCheckTest1.pdf";
|
||||
String cmpPdf = sourceFolder + "cmp/PdfAFontTest/cmp_pdfA2b_cidFontCheckTest1.pdf";
|
||||
GenerateAndValidatePdfA2WithCidFont("FreeSans.ttf", outPdf);
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CidFontCheckTest2() {
|
||||
String outPdf = outputDir + "pdfA2b_cidFontCheckTest2.pdf";
|
||||
String cmpPdf = sourceFolder + "cmp/PdfAFontTest/cmp_pdfA2b_cidFontCheckTest2.pdf";
|
||||
String expectedVeraPdfWarning = "The following warnings and errors were logged during validation:\n" + "WARNING: The Top DICT does not begin with ROS operator";
|
||||
GenerateAndValidatePdfA2WithCidFont("Puritan2.otf", outPdf, expectedVeraPdfWarning);
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CidFontCheckTest3() {
|
||||
String outPdf = outputDir + "pdfA2b_cidFontCheckTest3.pdf";
|
||||
String cmpPdf = sourceFolder + "cmp/PdfAFontTest/cmp_pdfA2b_cidFontCheckTest3.pdf";
|
||||
GenerateAndValidatePdfA2WithCidFont("NotoSansCJKtc-Light.otf", outPdf);
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void SymbolicTtfCharEncodingsPdfA1Test01() {
|
||||
// encoding must not be specified
|
||||
CreateDocumentWithFont("symbolicTtfCharEncodingsPdfA1Test01.pdf", "Symbols1.ttf", "", PdfAConformanceLevel
|
||||
.PDF_A_1B);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void SymbolicTtfCharEncodingsPdfA1Test02() {
|
||||
// if you specify encoding, symbolic font is treated as non-symbolic
|
||||
CreateDocumentWithFont("symbolicTtfCharEncodingsPdfA1Test02.pdf", "Symbols1.ttf", PdfEncodings.MACROMAN, PdfAConformanceLevel
|
||||
.PDF_A_1B);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void SymbolicTtfCharEncodingsPdfA1Test03() {
|
||||
// if you specify encoding, symbolic font is treated as non-symbolic
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => CreateDocumentWithFont(
|
||||
"symbolicTtfCharEncodingsPdfA1Test03.pdf", "Symbols1.ttf", "ISO-8859-1", PdfAConformanceLevel.PDF_A_1B
|
||||
));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.ALL_NON_SYMBOLIC_TRUE_TYPE_FONT_SHALL_SPECIFY_MAC_ROMAN_OR_WIN_ANSI_ENCODING_AS_THE_ENCODING_ENTRY
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void SymbolicTtfCharEncodingsPdfA1Test04() {
|
||||
// emulate behaviour with default WinAnsi, which was present in 7.1
|
||||
CreateDocumentWithFont("symbolicTtfCharEncodingsPdfA1Test04.pdf", "Symbols1.ttf", PdfEncodings.WINANSI, PdfAConformanceLevel
|
||||
.PDF_A_1B);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void SymbolicTtfCharEncodingsPdfA1Test05() {
|
||||
// Identity-H behaviour should be the same as the default one, starting from 7.2
|
||||
CreateDocumentWithFont("symbolicTtfCharEncodingsPdfA1Test05.pdf", "Symbols1.ttf", PdfEncodings.IDENTITY_H,
|
||||
PdfAConformanceLevel.PDF_A_1B);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void NonSymbolicTtfCharEncodingsPdfA1Test01() {
|
||||
// encoding must be either winansi or macroman, by default winansi is used
|
||||
CreateDocumentWithFont("nonSymbolicTtfCharEncodingsPdfA1Test01.pdf", "FreeSans.ttf", PdfEncodings.WINANSI,
|
||||
PdfAConformanceLevel.PDF_A_1B);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void NonSymbolicTtfCharEncodingsPdfA1Test02() {
|
||||
// encoding must be either winansi or macroman, by default winansi is used
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => CreateDocumentWithFont(
|
||||
"nonSymbolicTtfCharEncodingsPdfA1Test02.pdf", "FreeSans.ttf", "ISO-8859-1", PdfAConformanceLevel.PDF_A_2B
|
||||
));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.ALL_NON_SYMBOLIC_TRUE_TYPE_FONT_SHALL_SPECIFY_MAC_ROMAN_ENCODING_OR_WIN_ANSI_ENCODING
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
private void CreateDocumentWithFont(String outFileName, String fontFileName, String encoding, PdfAConformanceLevel
|
||||
conformanceLevel) {
|
||||
String outPdf = outputDir + outFileName;
|
||||
String cmpPdf = sourceFolder + "cmp/PdfAFontTest/cmp_" + outFileName;
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfDocument doc = new PdfADocument(writer, conformanceLevel, new PdfOutputIntent("Custom", "", "http://www.color.org"
|
||||
, "sRGB IEC61966-2.1", @is));
|
||||
PdfPage page = doc.AddNewPage();
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + fontFileName, encoding, PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
PdfCanvas canvas = new PdfCanvas(page);
|
||||
canvas.SaveState().BeginText().MoveText(36, 700).SetFontAndSize(font, 12).ShowText("Hello World").EndText(
|
||||
).RestoreState();
|
||||
doc.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
private void CompareResult(String outPdf, String cmpPdf) {
|
||||
String result = new CompareTool().CompareByContent(outPdf, cmpPdf, outputDir, "diff_");
|
||||
if (result != null) {
|
||||
NUnit.Framework.Assert.Fail(result);
|
||||
}
|
||||
}
|
||||
|
||||
private void GenerateAndValidatePdfA2WithCidFont(String fontFile, String outPdf) {
|
||||
GenerateAndValidatePdfA2WithCidFont(fontFile, outPdf, null);
|
||||
}
|
||||
|
||||
private void GenerateAndValidatePdfA2WithCidFont(String fontFile, String outPdf, String expectedVeraPdfWarning
|
||||
) {
|
||||
using (PdfWriter writer = new PdfWriter(outPdf)) {
|
||||
using (Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read
|
||||
)) {
|
||||
using (PdfDocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom"
|
||||
, "", "http://www.color.org", "sRGB IEC61966-2.1", @is))) {
|
||||
PdfPage page = doc.AddNewPage();
|
||||
// Identity-H must be embedded
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + fontFile, "Identity-H", PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
PdfCanvas canvas = new PdfCanvas(page);
|
||||
canvas.SaveState().BeginText().MoveText(36, 700).SetFontAndSize(font, 12).ShowText("Hello World").EndText(
|
||||
).RestoreState();
|
||||
}
|
||||
}
|
||||
}
|
||||
NUnit.Framework.Assert.AreEqual(expectedVeraPdfWarning, new VeraPdfValidator().Validate(outPdf));
|
||||
}
|
||||
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
|
||||
}
|
||||
}
|
||||
427
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfAFormFieldTest.cs
Normal file
427
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfAFormFieldTest.cs
Normal file
@@ -0,0 +1,427 @@
|
||||
/*
|
||||
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.Commons.Utils;
|
||||
using TSpdf.Forms;
|
||||
using TSpdf.Forms.Fields;
|
||||
using TSpdf.IO.Font;
|
||||
using TSpdf.Kernel.Colors;
|
||||
using TSpdf.Kernel.Exceptions;
|
||||
using TSpdf.Kernel.Font;
|
||||
using TSpdf.Kernel.Geom;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Pdf.Annot;
|
||||
using TSpdf.Kernel.Pdf.Canvas;
|
||||
using TSpdf.Kernel.Pdf.Xobject;
|
||||
using TSpdf.Kernel.Utils;
|
||||
using TSpdf.Layout;
|
||||
using TSpdf.Layout.Element;
|
||||
using TSpdf.Layout.Renderer;
|
||||
using TSpdf.Pdfa.Exceptions;
|
||||
using TSpdf.Test;
|
||||
using TSpdf.Test.Attributes;
|
||||
using TSpdf.Test.Pdfa;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfAFormFieldTest : ExtendedTSpdfTest {
|
||||
public static readonly String SOURCE_FOLDER = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
public static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/PdfAFormFieldTest/";
|
||||
|
||||
[NUnit.Framework.OneTimeSetUp]
|
||||
public static void BeforeClass() {
|
||||
CreateDestinationFolder(DESTINATION_FOLDER);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfAButtonFieldTest() {
|
||||
PdfDocument pdf;
|
||||
Stream @is = new FileStream(SOURCE_FOLDER + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read
|
||||
);
|
||||
String file = "pdfAButtonField.pdf";
|
||||
String filename = DESTINATION_FOLDER + file;
|
||||
pdf = new PdfADocument(new PdfWriter(new FileStream(filename, FileMode.Create)), PdfAConformanceLevel.PDF_A_1B
|
||||
, new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB ICC preference", @is));
|
||||
PageSize pageSize = PageSize.LETTER;
|
||||
Document doc = new Document(pdf, pageSize);
|
||||
PdfFontFactory.Register(SOURCE_FOLDER + "FreeSans.ttf", SOURCE_FOLDER + "FreeSans.ttf");
|
||||
PdfFont font = PdfFontFactory.CreateFont(SOURCE_FOLDER + "FreeSans.ttf", PdfFontFactory.EmbeddingStrategy.
|
||||
PREFER_EMBEDDED);
|
||||
PdfButtonFormField group = new RadioFormFieldBuilder(pdf, "group").SetConformanceLevel(PdfAConformanceLevel
|
||||
.PDF_A_1B).CreateRadioGroup();
|
||||
group.SetValue("");
|
||||
group.SetReadOnly(true);
|
||||
Paragraph p = new Paragraph();
|
||||
Text t = new Text("supported");
|
||||
t.SetFont(font);
|
||||
p.Add(t);
|
||||
Image ph = new Image(new PdfFormXObject(new Rectangle(10, 10)));
|
||||
Paragraph pc = new Paragraph().Add(ph);
|
||||
PdfAFormFieldTest.PdfAButtonFieldTestRenderer r = new PdfAFormFieldTest.PdfAButtonFieldTestRenderer(pc, group
|
||||
, "v1");
|
||||
pc.SetNextRenderer(r);
|
||||
p.Add(pc);
|
||||
Paragraph pc1 = new Paragraph().Add(ph);
|
||||
PdfAFormFieldTest.PdfAButtonFieldTestRenderer r1 = new PdfAFormFieldTest.PdfAButtonFieldTestRenderer(pc, group
|
||||
, "v2");
|
||||
pc1.SetNextRenderer(r1);
|
||||
Paragraph p2 = new Paragraph();
|
||||
Text t2 = new Text("supported 2");
|
||||
t2.SetFont(font);
|
||||
p2.Add(t2).Add(pc1);
|
||||
doc.Add(p);
|
||||
doc.Add(p2);
|
||||
//set generateAppearance param to false to retain custom appearance
|
||||
group.SetValue("v1", false);
|
||||
PdfAcroForm.GetAcroForm(pdf, true).AddField(group);
|
||||
pdf.Close();
|
||||
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, SOURCE_FOLDER + "cmp/PdfAFormFieldTest/cmp_"
|
||||
+ file, DESTINATION_FOLDER, "diff_"));
|
||||
}
|
||||
|
||||
internal class PdfAButtonFieldTestRenderer : ParagraphRenderer {
|
||||
private PdfButtonFormField _group;
|
||||
|
||||
private String _value;
|
||||
|
||||
public PdfAButtonFieldTestRenderer(Paragraph para, PdfButtonFormField group, String value)
|
||||
: base(para) {
|
||||
_group = group;
|
||||
_value = value;
|
||||
}
|
||||
|
||||
public override void Draw(DrawContext context) {
|
||||
int pageNumber = GetOccupiedArea().GetPageNumber();
|
||||
Rectangle bbox = GetInnerAreaBBox();
|
||||
PdfDocument pdf = context.GetDocument();
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdf, true);
|
||||
PdfFormField chk = new RadioFormFieldBuilder(pdf).SetWidgetRectangle(bbox).SetConformanceLevel(PdfAConformanceLevel
|
||||
.PDF_A_1B).CreateRadioButton(_group, _value);
|
||||
PdfFormAnnotation annotation = chk.GetFirstFormAnnotation();
|
||||
annotation.SetPage(pageNumber);
|
||||
annotation.SetVisibility(PdfFormAnnotation.VISIBLE);
|
||||
annotation.SetBorderColor(ColorConstants.BLACK);
|
||||
annotation.SetBackgroundColor(ColorConstants.WHITE);
|
||||
chk.SetReadOnly(true);
|
||||
PdfFormXObject appearance = new PdfFormXObject(bbox);
|
||||
PdfCanvas canvas = new PdfCanvas(appearance, pdf);
|
||||
canvas.SaveState().MoveTo(bbox.GetLeft(), bbox.GetBottom()).LineTo(bbox.GetRight(), bbox.GetBottom()).LineTo
|
||||
(bbox.GetRight(), bbox.GetTop()).LineTo(bbox.GetLeft(), bbox.GetTop()).LineTo(bbox.GetLeft(), bbox.GetBottom
|
||||
()).SetLineWidth(1f).Stroke().RestoreState();
|
||||
form.AddFieldAppearanceToPage(chk, pdf.GetPage(pageNumber));
|
||||
//appearance stream was set, while AS has kept as is, i.e. in Off state.
|
||||
annotation.SetAppearance(PdfName.N, "v1".Equals(_value) ? _value : "Off", appearance.GetPdfObject());
|
||||
}
|
||||
|
||||
public override IRenderer GetNextRenderer() {
|
||||
return new PdfAFormFieldTest.PdfAButtonFieldTestRenderer((Paragraph)modelElement, _group, _value);
|
||||
}
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA1DocWithPdfA1ButtonFieldTest() {
|
||||
// TODO: DEVSIX-3913 update this test after the ticket will be resolved
|
||||
String name = "pdfA1DocWithPdfA1ButtonField";
|
||||
String fileName = DESTINATION_FOLDER + name + ".pdf";
|
||||
String cmp = SOURCE_FOLDER + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1ButtonField.pdf";
|
||||
Stream @is = new FileStream(SOURCE_FOLDER + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read
|
||||
);
|
||||
PdfAConformanceLevel conformanceLevel = PdfAConformanceLevel.PDF_A_1B;
|
||||
PdfADocument pdfDoc = new PdfADocument(new PdfWriter(fileName), conformanceLevel, new PdfOutputIntent("Custom"
|
||||
, "", "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
|
||||
PdfFormField emptyField = new NonTerminalFormFieldBuilder(pdfDoc, "empty").SetConformanceLevel(conformanceLevel
|
||||
).CreateNonTerminalFormField();
|
||||
emptyField.AddKid(new PushButtonFormFieldBuilder(pdfDoc, "button").SetWidgetRectangle(new Rectangle(36, 756
|
||||
, 20, 20)).SetConformanceLevel(conformanceLevel).CreatePushButton().SetFieldFlags(PdfAnnotation.PRINT)
|
||||
.SetFieldName("button").SetValue("hello"));
|
||||
form.AddField(emptyField);
|
||||
Exception exception = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfDoc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException.ALL_THE_FONTS_MUST_BE_EMBEDDED_THIS_ONE_IS_NOT_0
|
||||
, "Helvetica"), exception.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA1DocWithPdfA1CheckBoxFieldTest() {
|
||||
String name = "pdfA1DocWithPdfA1CheckBoxField";
|
||||
String fileName = DESTINATION_FOLDER + name + ".pdf";
|
||||
String cmp = SOURCE_FOLDER + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1CheckBoxField.pdf";
|
||||
Stream @is = new FileStream(SOURCE_FOLDER + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read
|
||||
);
|
||||
PdfAConformanceLevel conformanceLevel = PdfAConformanceLevel.PDF_A_1B;
|
||||
PdfADocument pdfDoc = new PdfADocument(new PdfWriter(fileName), conformanceLevel, new PdfOutputIntent("Custom"
|
||||
, "", "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
|
||||
form.AddField(new CheckBoxFormFieldBuilder(pdfDoc, "checkBox").SetWidgetRectangle(new Rectangle(36, 726, 20
|
||||
, 20)).SetCheckType(PdfFormField.TYPE_STAR).SetConformanceLevel(conformanceLevel).CreateCheckBox().SetValue
|
||||
("1"));
|
||||
pdfDoc.Close();
|
||||
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(fileName, cmp, DESTINATION_FOLDER));
|
||||
NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(fileName));
|
||||
}
|
||||
|
||||
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
|
||||
[NUnit.Framework.Test]
|
||||
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.FIELD_VALUE_IS_NOT_CONTAINED_IN_OPT_ARRAY)]
|
||||
public virtual void PdfA1DocWithPdfA1ChoiceFieldTest() {
|
||||
// TODO: DEVSIX-3913 update this test after the ticket will be resolved
|
||||
String name = "pdfA1DocWithPdfA1ChoiceField";
|
||||
String fileName = DESTINATION_FOLDER + name + ".pdf";
|
||||
String cmp = SOURCE_FOLDER + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1ChoiceField.pdf";
|
||||
PdfFont fontFreeSans = PdfFontFactory.CreateFont(SOURCE_FOLDER + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
Stream @is = new FileStream(SOURCE_FOLDER + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read
|
||||
);
|
||||
PdfAConformanceLevel conformanceLevel = PdfAConformanceLevel.PDF_A_1B;
|
||||
PdfADocument pdfDoc = new PdfADocument(new PdfWriter(fileName), conformanceLevel, new PdfOutputIntent("Custom"
|
||||
, "", "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
|
||||
PdfArray options = new PdfArray();
|
||||
options.Add(new PdfString("Name"));
|
||||
options.Add(new PdfString("Surname"));
|
||||
PdfFormField choiceFormField = new ChoiceFormFieldBuilder(pdfDoc, "choice").SetWidgetRectangle(new Rectangle
|
||||
(36, 696, 100, 70)).SetOptions(options).SetConformanceLevel(conformanceLevel).CreateList().SetValue("1"
|
||||
, true);
|
||||
choiceFormField.SetFont(fontFreeSans);
|
||||
form.AddField(choiceFormField);
|
||||
Exception exception = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfDoc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException.ALL_THE_FONTS_MUST_BE_EMBEDDED_THIS_ONE_IS_NOT_0
|
||||
, "Helvetica"), exception.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA1DocWithPdfA1ComboBoxFieldTest() {
|
||||
// TODO: DEVSIX-3913 update this test after the ticket will be resolved
|
||||
String name = "pdfA1DocWithPdfA1ComboBoxField";
|
||||
String fileName = DESTINATION_FOLDER + name + ".pdf";
|
||||
String cmp = SOURCE_FOLDER + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1ComboBoxField.pdf";
|
||||
PdfFont fontCJK = PdfFontFactory.CreateFont(SOURCE_FOLDER + "NotoSansCJKtc-Light.otf", PdfEncodings.IDENTITY_H
|
||||
, PdfFontFactory.EmbeddingStrategy.FORCE_EMBEDDED);
|
||||
Stream @is = new FileStream(SOURCE_FOLDER + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read
|
||||
);
|
||||
PdfAConformanceLevel conformanceLevel = PdfAConformanceLevel.PDF_A_1B;
|
||||
PdfADocument pdfDoc = new PdfADocument(new PdfWriter(fileName), conformanceLevel, new PdfOutputIntent("Custom"
|
||||
, "", "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
|
||||
PdfFormField choiceFormField = new ChoiceFormFieldBuilder(pdfDoc, "combo").SetWidgetRectangle(new Rectangle
|
||||
(156, 616, 70, 70)).SetOptions(new String[] { "用", "规", "表" }).SetConformanceLevel(conformanceLevel).CreateComboBox
|
||||
().SetValue("用");
|
||||
choiceFormField.SetFont(fontCJK);
|
||||
form.AddField(choiceFormField);
|
||||
Exception exception = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfDoc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException.ALL_THE_FONTS_MUST_BE_EMBEDDED_THIS_ONE_IS_NOT_0
|
||||
, "Helvetica"), exception.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.MULTIPLE_VALUES_ON_A_NON_MULTISELECT_FIELD)]
|
||||
public virtual void PdfA1DocWithPdfA1ListFieldTest() {
|
||||
// TODO: DEVSIX-3913 update this test after the ticket will be resolved
|
||||
String name = "pdfA1DocWithPdfA1ListField";
|
||||
String fileName = DESTINATION_FOLDER + name + ".pdf";
|
||||
String cmp = SOURCE_FOLDER + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1ListField.pdf";
|
||||
PdfFont fontFreeSans = PdfFontFactory.CreateFont(SOURCE_FOLDER + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
Stream @is = new FileStream(SOURCE_FOLDER + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read
|
||||
);
|
||||
PdfAConformanceLevel conformanceLevel = PdfAConformanceLevel.PDF_A_1B;
|
||||
PdfADocument pdfDoc = new PdfADocument(new PdfWriter(fileName), conformanceLevel, new PdfOutputIntent("Custom"
|
||||
, "", "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
|
||||
PdfChoiceFormField f = new ChoiceFormFieldBuilder(pdfDoc, "list").SetWidgetRectangle(new Rectangle(86, 556
|
||||
, 50, 200)).SetOptions(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }).SetConformanceLevel
|
||||
(conformanceLevel).CreateList();
|
||||
f.SetValue("9").SetFont(fontFreeSans);
|
||||
f.SetValue("4");
|
||||
f.SetTopIndex(2);
|
||||
f.SetListSelected(new String[] { "3", "5" });
|
||||
form.AddField(f);
|
||||
Exception exception = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfDoc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException.ALL_THE_FONTS_MUST_BE_EMBEDDED_THIS_ONE_IS_NOT_0
|
||||
, "Helvetica"), exception.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA1DocWithPdfA1PushButtonFieldTest() {
|
||||
// TODO: DEVSIX-3913 update this test after the ticket will be resolved
|
||||
String name = "pdfA1DocWithPdfA1PushButtonField";
|
||||
String fileName = DESTINATION_FOLDER + name + ".pdf";
|
||||
String cmp = SOURCE_FOLDER + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1PushButtonField.pdf";
|
||||
PdfFont fontFreeSans = PdfFontFactory.CreateFont(SOURCE_FOLDER + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
Stream @is = new FileStream(SOURCE_FOLDER + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read
|
||||
);
|
||||
PdfAConformanceLevel conformanceLevel = PdfAConformanceLevel.PDF_A_1B;
|
||||
PdfADocument pdfDoc = new PdfADocument(new PdfWriter(fileName), conformanceLevel, new PdfOutputIntent("Custom"
|
||||
, "", "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
|
||||
PdfFormField pushButtonFormField = new PushButtonFormFieldBuilder(pdfDoc, "push button").SetWidgetRectangle
|
||||
(new Rectangle(36, 526, 100, 20)).SetCaption("Push").SetConformanceLevel(conformanceLevel).CreatePushButton
|
||||
();
|
||||
pushButtonFormField.SetFont(fontFreeSans).SetFontSize(12);
|
||||
form.AddField(pushButtonFormField);
|
||||
Exception exception = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfDoc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException.ALL_THE_FONTS_MUST_BE_EMBEDDED_THIS_ONE_IS_NOT_0
|
||||
, "Helvetica"), exception.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA1DocWithPdfA1RadioButtonFieldTest() {
|
||||
String name = "pdfA1DocWithPdfA1RadioButtonField";
|
||||
String fileName = DESTINATION_FOLDER + name + ".pdf";
|
||||
String cmp = SOURCE_FOLDER + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1RadioButtonField.pdf";
|
||||
Stream @is = new FileStream(SOURCE_FOLDER + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read
|
||||
);
|
||||
PdfAConformanceLevel conformanceLevel = PdfAConformanceLevel.PDF_A_1B;
|
||||
PdfADocument pdfDoc = new PdfADocument(new PdfWriter(fileName), conformanceLevel, new PdfOutputIntent("Custom"
|
||||
, "", "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
|
||||
PdfButtonFormField radioGroup = new RadioFormFieldBuilder(pdfDoc, "radio group").SetConformanceLevel(conformanceLevel
|
||||
).CreateRadioGroup();
|
||||
radioGroup.SetValue("");
|
||||
new RadioFormFieldBuilder(pdfDoc).SetWidgetRectangle(new Rectangle(36, 496, 20, 20)).SetConformanceLevel(conformanceLevel
|
||||
).CreateRadioButton(radioGroup, "1").GetFirstFormAnnotation().SetBorderWidth(2).SetBorderColor(ColorConstants
|
||||
.ORANGE);
|
||||
new RadioFormFieldBuilder(pdfDoc).SetWidgetRectangle(new Rectangle(66, 496, 20, 20)).SetConformanceLevel(conformanceLevel
|
||||
).CreateRadioButton(radioGroup, "2").GetFirstFormAnnotation().SetBorderWidth(2).SetBorderColor(ColorConstants
|
||||
.ORANGE);
|
||||
form.AddField(radioGroup);
|
||||
pdfDoc.Close();
|
||||
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(fileName, cmp, DESTINATION_FOLDER));
|
||||
NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(fileName));
|
||||
}
|
||||
|
||||
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA1DocWithPdfA1TextFieldTest() {
|
||||
// TODO: DEVSIX-3913 update this test after the ticket will be resolved
|
||||
String name = "pdfA1DocWithPdfA1TextField";
|
||||
String fileName = DESTINATION_FOLDER + name + ".pdf";
|
||||
String cmp = SOURCE_FOLDER + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1TextField.pdf";
|
||||
PdfFont fontFreeSans = PdfFontFactory.CreateFont(SOURCE_FOLDER + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
fontFreeSans.SetSubset(false);
|
||||
Stream @is = new FileStream(SOURCE_FOLDER + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read
|
||||
);
|
||||
PdfAConformanceLevel conformanceLevel = PdfAConformanceLevel.PDF_A_1B;
|
||||
PdfADocument pdfDoc = new PdfADocument(new PdfWriter(fileName), conformanceLevel, new PdfOutputIntent("Custom"
|
||||
, "", "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
|
||||
PdfFormField textFormField = new TextFormFieldBuilder(pdfDoc, "text").SetWidgetRectangle(new Rectangle(36,
|
||||
466, 90, 20)).SetConformanceLevel(conformanceLevel).CreateText().SetValue("textField").SetValue("TSpdf"
|
||||
);
|
||||
textFormField.SetFont(fontFreeSans).SetFontSize(12);
|
||||
form.AddField(textFormField);
|
||||
Exception exception = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfDoc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException.ALL_THE_FONTS_MUST_BE_EMBEDDED_THIS_ONE_IS_NOT_0
|
||||
, "Helvetica"), exception.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA1DocWithPdfA1SignatureFieldTest() {
|
||||
String name = "pdfA1DocWithPdfA1SignatureField";
|
||||
String fileName = DESTINATION_FOLDER + name + ".pdf";
|
||||
String cmp = SOURCE_FOLDER + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1SignatureField.pdf";
|
||||
PdfFont fontFreeSans = PdfFontFactory.CreateFont(SOURCE_FOLDER + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
fontFreeSans.SetSubset(false);
|
||||
Stream @is = new FileStream(SOURCE_FOLDER + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read
|
||||
);
|
||||
PdfAConformanceLevel conformanceLevel = PdfAConformanceLevel.PDF_A_1B;
|
||||
PdfADocument pdfDoc = new PdfADocument(new PdfWriter(fileName), conformanceLevel, new PdfOutputIntent("Custom"
|
||||
, "", "http://www.color.org", "sRGB IEC61966-2.1", @is));
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
|
||||
PdfFormField signFormField = new SignatureFormFieldBuilder(pdfDoc, "signature").SetConformanceLevel(conformanceLevel
|
||||
).CreateSignature();
|
||||
signFormField.SetFont(fontFreeSans).SetFontSize(20);
|
||||
form.AddField(signFormField);
|
||||
pdfDoc.Close();
|
||||
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(fileName, cmp, DESTINATION_FOLDER));
|
||||
NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(fileName));
|
||||
}
|
||||
|
||||
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
|
||||
[NUnit.Framework.Test]
|
||||
[NUnit.Framework.Ignore("DEVSIX-3913 update this test after the ticket will be resolved")]
|
||||
public virtual void MergePdfADocWithFormTest() {
|
||||
String fileName = DESTINATION_FOLDER + "pdfADocWithTextFormField.pdf";
|
||||
String mergedDocFileName = DESTINATION_FOLDER + "mergedPdfADoc.pdf";
|
||||
using (Stream @is = new FileStream(SOURCE_FOLDER + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read
|
||||
)) {
|
||||
using (PdfADocument pdfDoc = new PdfADocument(new PdfWriter(fileName), PdfAConformanceLevel.PDF_A_1B, new
|
||||
PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB ICC preference", @is))) {
|
||||
using (Document doc = new Document(pdfDoc)) {
|
||||
PdfFont font = PdfFontFactory.CreateFont(SOURCE_FOLDER + "FreeSans.ttf", PdfEncodings.WINANSI);
|
||||
doc.Add(new Paragraph(new Text("Some text").SetFont(font).SetFontSize(10)));
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
|
||||
PdfFormField field = new TextFormFieldBuilder(pdfDoc, "text").SetWidgetRectangle(new Rectangle(150, 100, 100
|
||||
, 20)).SetConformanceLevel(PdfAConformanceLevel.PDF_A_1B).CreateText().SetValue("textField").SetFieldName
|
||||
("text");
|
||||
field.SetFont(font).SetFontSize(10);
|
||||
field.GetFirstFormAnnotation().SetPage(1);
|
||||
form.AddField(field, pdfDoc.GetPage(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(fileName));
|
||||
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
|
||||
PdfADocument pdfDocToMerge;
|
||||
using (Stream is_1 = new FileStream(SOURCE_FOLDER + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read
|
||||
)) {
|
||||
using (PdfDocument newDoc = new PdfDocument(new PdfReader(fileName))) {
|
||||
pdfDocToMerge = new PdfADocument(new PdfWriter(mergedDocFileName).SetSmartMode(true), PdfAConformanceLevel
|
||||
.PDF_A_1B, new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB ICC preference", is_1));
|
||||
newDoc.CopyPagesTo(1, newDoc.GetNumberOfPages(), pdfDocToMerge, new PdfPageFormCopier());
|
||||
}
|
||||
}
|
||||
Exception ex = NUnit.Framework.Assert.Catch(typeof(PdfException), () => pdfDocToMerge.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException.ALL_THE_FONTS_MUST_BE_EMBEDDED_THIS_ONE_IS_NOT_0
|
||||
, "Helvetica"), ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
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.IO.Font;
|
||||
using TSpdf.Kernel.Font;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Layout;
|
||||
using TSpdf.Layout.Element;
|
||||
using TSpdf.Pdfa.Checker;
|
||||
using TSpdf.Pdfa.Exceptions;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfAIndirectObjectsCountLimitTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ValidAmountOfIndirectObjectsTest() {
|
||||
PdfA1Checker testChecker = new _PdfA1Checker_77(PdfAConformanceLevel.PDF_A_1B);
|
||||
using (Stream icm = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read
|
||||
)) {
|
||||
using (Stream fos = new MemoryStream()) {
|
||||
using (Document document = new Document(new PdfADocument(new PdfWriter(fos), PdfAConformanceLevel.PDF_A_1B
|
||||
, GetOutputIntent(icm)))) {
|
||||
PdfADocument pdfa = (PdfADocument)document.GetPdfDocument();
|
||||
pdfa.checker = testChecker;
|
||||
document.Add(BuildContent());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class _PdfA1Checker_77 : PdfA1Checker {
|
||||
public _PdfA1Checker_77(PdfAConformanceLevel baseArg1)
|
||||
: base(baseArg1) {
|
||||
}
|
||||
|
||||
protected internal override long GetMaxNumberOfIndirectObjects() {
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
|
||||
// generated document contains exactly 10 indirect objects. Given 10 is the allowed
|
||||
// limit per "mock specification" conformance exception shouldn't be thrown
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void InvalidAmountOfIndirectObjectsTest() {
|
||||
PdfA1Checker testChecker = new _PdfA1Checker_102(PdfAConformanceLevel.PDF_A_1B);
|
||||
using (Stream icm = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read
|
||||
)) {
|
||||
using (Stream fos = new MemoryStream()) {
|
||||
Document document = new Document(new PdfADocument(new PdfWriter(fos), PdfAConformanceLevel.PDF_A_1B, GetOutputIntent
|
||||
(icm)));
|
||||
PdfADocument pdfa = (PdfADocument)document.GetPdfDocument();
|
||||
pdfa.checker = testChecker;
|
||||
document.Add(BuildContent());
|
||||
// generated document contains exactly 10 indirect objects. Given 9 is the allowed
|
||||
// limit per "mock specification" conformance exception should be thrown as the limit
|
||||
// is exceeded
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => document.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.MAXIMUM_NUMBER_OF_INDIRECT_OBJECTS_EXCEEDED, e.Message
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class _PdfA1Checker_102 : PdfA1Checker {
|
||||
public _PdfA1Checker_102(PdfAConformanceLevel baseArg1)
|
||||
: base(baseArg1) {
|
||||
}
|
||||
|
||||
protected internal override long GetMaxNumberOfIndirectObjects() {
|
||||
return 9;
|
||||
}
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void InvalidAmountOfIndirectObjectsAppendModeTest() {
|
||||
PdfA1Checker testChecker = new _PdfA1Checker_130(PdfAConformanceLevel.PDF_A_1B);
|
||||
using (Stream fis = new FileStream(sourceFolder + "pdfs/pdfa10IndirectObjects.pdf", FileMode.Open, FileAccess.Read
|
||||
)) {
|
||||
using (Stream fos = new MemoryStream()) {
|
||||
PdfADocument pdfa = new PdfADocument(new PdfReader(fis), new PdfWriter(fos), new StampingProperties().UseAppendMode
|
||||
());
|
||||
pdfa.checker = testChecker;
|
||||
pdfa.AddNewPage();
|
||||
// during closing of pdfa object exception will be thrown as new document will contain
|
||||
// 12 indirect objects and limit per "mock specification" conformance will be exceeded
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfa.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.MAXIMUM_NUMBER_OF_INDIRECT_OBJECTS_EXCEEDED, e.Message
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class _PdfA1Checker_130 : PdfA1Checker {
|
||||
public _PdfA1Checker_130(PdfAConformanceLevel baseArg1)
|
||||
: base(baseArg1) {
|
||||
}
|
||||
|
||||
protected internal override long GetMaxNumberOfIndirectObjects() {
|
||||
return 11;
|
||||
}
|
||||
}
|
||||
|
||||
private Paragraph BuildContent() {
|
||||
PdfFontFactory.Register(sourceFolder + "FreeSans.ttf", sourceFolder + "FreeSans.ttf");
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", PdfEncodings.WINANSI, PdfFontFactory.EmbeddingStrategy
|
||||
.PREFER_EMBEDDED);
|
||||
Paragraph p = new Paragraph(Guid.NewGuid().ToString());
|
||||
p.SetMinWidth(1e6f);
|
||||
p.SetFont(font);
|
||||
return p;
|
||||
}
|
||||
|
||||
private PdfOutputIntent GetOutputIntent(Stream inputStream) {
|
||||
return new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB ICC preference", inputStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
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.Kernel.Pdf;
|
||||
using TSpdf.Pdfa.Logs;
|
||||
using TSpdf.Test;
|
||||
using TSpdf.Test.Attributes;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfAIndirectResourcesTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/pdfs/";
|
||||
|
||||
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/PdfAIndirectResourcesTest/";
|
||||
|
||||
[NUnit.Framework.SetUp]
|
||||
public virtual void Configure() {
|
||||
CreateDestinationFolder(destinationFolder);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
[LogMessage(PdfAConformanceLogMessageConstant.CATALOG_SHOULD_CONTAIN_LANG_ENTRY)]
|
||||
public virtual void IndirectResources01Test() {
|
||||
String fileName = destinationFolder + "indirectResources01Test.pdf";
|
||||
PdfADocument pdfDoc = new PdfADocument(new PdfReader(sourceFolder + "indirectResources01.pdf"), new PdfWriter
|
||||
(fileName));
|
||||
pdfDoc.Close();
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void IndirectResources02Test() {
|
||||
String fileName = destinationFolder + "indirectResources02Test.pdf";
|
||||
PdfWriter writer = new PdfAIndirectResourcesTest.CustomPdfWriter(fileName, 19);
|
||||
PdfADocument pdfDoc = new PdfADocument(new PdfReader(sourceFolder + "indirectResources02.pdf"), writer);
|
||||
pdfDoc.Close();
|
||||
}
|
||||
|
||||
private class CustomPdfWriter : PdfWriter {
|
||||
private int objectToFlushNumber;
|
||||
|
||||
public CustomPdfWriter(String filename, int objectToFlushNumber)
|
||||
: base(filename) {
|
||||
this.objectToFlushNumber = objectToFlushNumber;
|
||||
}
|
||||
|
||||
protected override void FlushWaitingObjects(ICollection<PdfIndirectReference> forbiddenToFlush) {
|
||||
// Because of flushing order in PdfDocument is uncertain, flushWaitingObjects() method is overridden
|
||||
// to simulate the issue when the certain PdfObject A, that exists in the Catalog entry and in the resources
|
||||
// of another PdfObject B, is flushed before the flushing of the PdfObject B.
|
||||
base.document.GetPdfObject(objectToFlushNumber).Flush();
|
||||
base.FlushWaitingObjects(forbiddenToFlush);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
100
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfALongStringTest.cs
Normal file
100
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfALongStringTest.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
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.Text;
|
||||
using TSpdf.Kernel.Font;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Layout;
|
||||
using TSpdf.Layout.Element;
|
||||
using TSpdf.Pdfa.Exceptions;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfALongStringTest : ExtendedTSpdfTest {
|
||||
private static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
private static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/PdfALongStringTest/";
|
||||
|
||||
private const String LOREM_IPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis condimentum, tortor sit amet fermentum pharetra, sem felis finibus enim, vel consectetur nunc justo at nisi. In hac habitasse platea dictumst. Donec quis suscipit eros. Nam urna purus, scelerisque in placerat in, convallis vel sapien. Suspendisse sed lacus sit amet orci ornare vulputate. In hac habitasse platea dictumst. Ut eu aliquet felis, at consectetur neque.";
|
||||
|
||||
private const int STRING_LENGTH_LIMIT = 32767;
|
||||
|
||||
[NUnit.Framework.OneTimeSetUp]
|
||||
public static void BeforeClass() {
|
||||
CreateDestinationFolder(destinationFolder);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void RunTest() {
|
||||
String file = "pdfALongString.pdf";
|
||||
String filename = destinationFolder + file;
|
||||
using (Stream icm = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read
|
||||
)) {
|
||||
using (FileStream fos = new FileStream(filename, FileMode.Create)) {
|
||||
Document document = new Document(new PdfADocument(new PdfWriter(fos), PdfAConformanceLevel.PDF_A_3U, new PdfOutputIntent
|
||||
("Custom", "", "http://www.color.org", "sRGB ICC preference", icm)));
|
||||
StringBuilder stringBuilder = new StringBuilder(LOREM_IPSUM);
|
||||
while (stringBuilder.Length < STRING_LENGTH_LIMIT) {
|
||||
stringBuilder.Append(stringBuilder.ToString());
|
||||
}
|
||||
PdfFontFactory.Register(sourceFolder + "FreeSans.ttf", sourceFolder + "FreeSans.ttf");
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", PdfFontFactory.EmbeddingStrategy.PREFER_EMBEDDED
|
||||
);
|
||||
Paragraph p = new Paragraph(stringBuilder.ToString());
|
||||
p.SetMinWidth(1e6f);
|
||||
p.SetFont(font);
|
||||
document.Add(p);
|
||||
// when document is closing, ISO conformance check is performed
|
||||
// this document contain a string which is longer than it is allowed
|
||||
// per specification. That is why conformance exception should be thrown
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => document.Close());
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.PDF_STRING_IS_TOO_LONG, e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
211
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfAPageTest.cs
Normal file
211
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfAPageTest.cs
Normal file
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
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.Events;
|
||||
using TSpdf.Kernel.Geom;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Layout;
|
||||
using TSpdf.Layout.Element;
|
||||
using TSpdf.Pdfa.Logs;
|
||||
using TSpdf.Test;
|
||||
using TSpdf.Test.Attributes;
|
||||
using TSpdf.Test.Pdfa;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfAPageTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
private static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/PdfAPageTest/";
|
||||
|
||||
[NUnit.Framework.OneTimeSetUp]
|
||||
public static void BeforeClass() {
|
||||
CreateOrClearDestinationFolder(destinationFolder);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
[LogMessage(PdfALogMessageConstant.PDFA_PAGE_FLUSHING_WAS_NOT_PERFORMED)]
|
||||
public virtual void CheckThatFlushingPreventedWhenAddingElementToDocument() {
|
||||
// Expected log message that page flushing was not performed
|
||||
String outPdf = destinationFolder + "checkThatFlushingPreventedWhenAddingElementToDocument.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
PdfADocument pdfDoc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1A, new PdfOutputIntent("Custom"
|
||||
, "", "http://www.color.org", "sRGB IEC61966-2.1", new FileStream(sourceFolder + "sRGB Color Space Profile.icm"
|
||||
, FileMode.Open, FileAccess.Read)));
|
||||
pdfDoc.SetTagged();
|
||||
pdfDoc.GetCatalog().SetLang(new PdfString("en-US"));
|
||||
PdfAPageTest.EndPageEventHandler eventHandler = new PdfAPageTest.EndPageEventHandler();
|
||||
pdfDoc.AddEventHandler(PdfDocumentEvent.END_PAGE, eventHandler);
|
||||
int pageCount = 3;
|
||||
Document document = new Document(pdfDoc, PageSize.A4);
|
||||
for (int i = 1; i < pageCount; i++) {
|
||||
// Adding a area break causes a new page to be added and an attempt to flush the page will occur,
|
||||
// but flushing these pages will be prevented due to a condition added to the PdfAPage#flush method
|
||||
document.Add(new AreaBreak());
|
||||
}
|
||||
// Before closing document have 3 pages, but no one call of end page event
|
||||
NUnit.Framework.Assert.AreEqual(pageCount, document.GetPdfDocument().GetNumberOfPages());
|
||||
NUnit.Framework.Assert.AreEqual(0, eventHandler.GetCounter());
|
||||
document.Close();
|
||||
// During the closing event was called on each document page
|
||||
NUnit.Framework.Assert.AreEqual(pageCount, eventHandler.GetCounter());
|
||||
NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(outPdf));
|
||||
}
|
||||
|
||||
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
|
||||
[NUnit.Framework.Test]
|
||||
[LogMessage(PdfALogMessageConstant.PDFA_PAGE_FLUSHING_WAS_NOT_PERFORMED)]
|
||||
public virtual void CheckThatFlushingPreventedWithFalseFlushResourcesContentStreams() {
|
||||
// Expected log message that page flushing was not performed
|
||||
String outPdf = destinationFolder + "checkThatFlushingPreventedWithFalseFlushResourcesContentStreams.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
PdfADocument pdfDoc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1A, new PdfOutputIntent("Custom"
|
||||
, "", "http://www.color.org", "sRGB IEC61966-2.1", new FileStream(sourceFolder + "sRGB Color Space Profile.icm"
|
||||
, FileMode.Open, FileAccess.Read)));
|
||||
pdfDoc.SetTagged();
|
||||
pdfDoc.GetCatalog().SetLang(new PdfString("en-US"));
|
||||
PdfAPageTest.EndPageEventHandler eventHandler = new PdfAPageTest.EndPageEventHandler();
|
||||
pdfDoc.AddEventHandler(PdfDocumentEvent.END_PAGE, eventHandler);
|
||||
int pageCount = 3;
|
||||
for (int i = 0; i < pageCount; i++) {
|
||||
pdfDoc.AddNewPage().Flush(false);
|
||||
}
|
||||
NUnit.Framework.Assert.AreEqual(pageCount, pdfDoc.GetNumberOfPages());
|
||||
NUnit.Framework.Assert.AreEqual(0, eventHandler.GetCounter());
|
||||
pdfDoc.Close();
|
||||
NUnit.Framework.Assert.AreEqual(pageCount, eventHandler.GetCounter());
|
||||
NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(outPdf));
|
||||
}
|
||||
|
||||
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckFlushingWhenPdfDocumentIsClosing() {
|
||||
String outPdf = destinationFolder + "checkFlushingWhenPdfDocumentIsClosing.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
PdfADocument pdfDoc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1A, new PdfOutputIntent("Custom"
|
||||
, "", "http://www.color.org", "sRGB IEC61966-2.1", new FileStream(sourceFolder + "sRGB Color Space Profile.icm"
|
||||
, FileMode.Open, FileAccess.Read)));
|
||||
pdfDoc.SetTagged();
|
||||
pdfDoc.GetCatalog().SetLang(new PdfString("en-US"));
|
||||
PdfAPageTest.EndPageEventHandler eventHandler = new PdfAPageTest.EndPageEventHandler();
|
||||
pdfDoc.AddEventHandler(PdfDocumentEvent.END_PAGE, eventHandler);
|
||||
int pageCount = 3;
|
||||
for (int i = 0; i < pageCount; i++) {
|
||||
pdfDoc.AddNewPage();
|
||||
}
|
||||
NUnit.Framework.Assert.AreEqual(pageCount, pdfDoc.GetNumberOfPages());
|
||||
NUnit.Framework.Assert.AreEqual(0, eventHandler.GetCounter());
|
||||
pdfDoc.Close();
|
||||
NUnit.Framework.Assert.AreEqual(pageCount, eventHandler.GetCounter());
|
||||
NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(outPdf));
|
||||
}
|
||||
|
||||
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckFlushingWithTrueFlushResourcesContentStreams() {
|
||||
String outPdf = destinationFolder + "checkFlushingWithTrueFlushResourcesContentStreams.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
PdfADocument pdfDoc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1A, new PdfOutputIntent("Custom"
|
||||
, "", "http://www.color.org", "sRGB IEC61966-2.1", new FileStream(sourceFolder + "sRGB Color Space Profile.icm"
|
||||
, FileMode.Open, FileAccess.Read)));
|
||||
pdfDoc.SetTagged();
|
||||
pdfDoc.GetCatalog().SetLang(new PdfString("en-US"));
|
||||
PdfAPageTest.EndPageEventHandler eventHandler = new PdfAPageTest.EndPageEventHandler();
|
||||
pdfDoc.AddEventHandler(PdfDocumentEvent.END_PAGE, eventHandler);
|
||||
int pageCount = 3;
|
||||
for (int i = 0; i < pageCount; i++) {
|
||||
pdfDoc.AddNewPage().Flush(true);
|
||||
}
|
||||
NUnit.Framework.Assert.AreEqual(pageCount, pdfDoc.GetNumberOfPages());
|
||||
NUnit.Framework.Assert.AreEqual(pageCount, eventHandler.GetCounter());
|
||||
pdfDoc.Close();
|
||||
NUnit.Framework.Assert.AreEqual(pageCount, eventHandler.GetCounter());
|
||||
NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(outPdf));
|
||||
}
|
||||
|
||||
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckFlushingOfCheckedPage() {
|
||||
String outPdf = destinationFolder + "checkFlushingOfCheckedPage.pdf";
|
||||
PdfWriter writer = new PdfWriter(outPdf);
|
||||
PdfADocument pdfDoc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1A, new PdfOutputIntent("Custom"
|
||||
, "", "http://www.color.org", "sRGB IEC61966-2.1", new FileStream(sourceFolder + "sRGB Color Space Profile.icm"
|
||||
, FileMode.Open, FileAccess.Read)));
|
||||
pdfDoc.SetTagged();
|
||||
pdfDoc.GetCatalog().SetLang(new PdfString("en-US"));
|
||||
PdfAPageTest.EndPageEventHandler eventHandler = new PdfAPageTest.EndPageEventHandler();
|
||||
pdfDoc.AddEventHandler(PdfDocumentEvent.END_PAGE, eventHandler);
|
||||
int pageCount = 3;
|
||||
for (int i = 0; i < pageCount; i++) {
|
||||
PdfPage page = pdfDoc.AddNewPage();
|
||||
pdfDoc.checker.CheckSinglePage(page);
|
||||
page.Flush(false);
|
||||
}
|
||||
NUnit.Framework.Assert.AreEqual(pageCount, pdfDoc.GetNumberOfPages());
|
||||
NUnit.Framework.Assert.AreEqual(pageCount, eventHandler.GetCounter());
|
||||
pdfDoc.Close();
|
||||
NUnit.Framework.Assert.AreEqual(pageCount, eventHandler.GetCounter());
|
||||
NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(outPdf));
|
||||
}
|
||||
|
||||
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
|
||||
internal class EndPageEventHandler : TSpdf.Kernel.Events.IEventHandler {
|
||||
private int counter = 0;
|
||||
|
||||
internal EndPageEventHandler() {
|
||||
}
|
||||
|
||||
public virtual int GetCounter() {
|
||||
return counter;
|
||||
}
|
||||
|
||||
public virtual void HandleEvent(Event @event) {
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
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.Commons.Utils;
|
||||
using TSpdf.Forms;
|
||||
using TSpdf.Forms.Fields;
|
||||
using TSpdf.Kernel.Font;
|
||||
using TSpdf.Kernel.Geom;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Pdfa.Exceptions;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfAPushbuttonfieldTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
public static readonly String cmpFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/cmp/PdfAPushbuttonfieldTest/";
|
||||
|
||||
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/PdfAPushbuttonfieldTest/";
|
||||
|
||||
[NUnit.Framework.OneTimeSetUp]
|
||||
public static void BeforeClass() {
|
||||
CreateDestinationFolder(destinationFolder);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA1bButtonAppearanceTest() {
|
||||
// TODO: DEVSIX-3913 update this test after the ticket will be resolved
|
||||
String name = "pdfA1b_ButtonAppearanceTest";
|
||||
String outPath = destinationFolder + name + ".pdf";
|
||||
String cmpPath = cmpFolder + "cmp_" + name + ".pdf";
|
||||
String diff = "diff_" + name + "_";
|
||||
PdfWriter writer = new PdfWriter(outPath);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent);
|
||||
doc.SetTagged();
|
||||
doc.GetCatalog().SetLang(new PdfString("en-US"));
|
||||
doc.AddNewPage();
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
|
||||
Rectangle rect = new Rectangle(36, 626, 100, 40);
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
PdfFormField button = new PushButtonFormFieldBuilder(doc, "push button").SetWidgetRectangle(rect).SetCaption
|
||||
("push").SetConformanceLevel(PdfAConformanceLevel.PDF_A_1B).CreatePushButton();
|
||||
button.SetFont(font).SetFontSize(12);
|
||||
form.AddField(button);
|
||||
Exception exception = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException.ALL_THE_FONTS_MUST_BE_EMBEDDED_THIS_ONE_IS_NOT_0
|
||||
, "Helvetica"), exception.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA1bButtonAppearanceRegenerateTest() {
|
||||
// TODO: DEVSIX-3913 update this test after the ticket will be resolved
|
||||
String name = "pdfA1b_ButtonAppearanceRegenerateTest";
|
||||
String outPath = destinationFolder + name + ".pdf";
|
||||
String cmpPath = cmpFolder + "cmp_" + name + ".pdf";
|
||||
String diff = "diff_" + name + "_";
|
||||
PdfWriter writer = new PdfWriter(outPath);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent);
|
||||
doc.SetTagged();
|
||||
doc.GetCatalog().SetLang(new PdfString("en-US"));
|
||||
doc.AddNewPage();
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
|
||||
Rectangle rect = new Rectangle(36, 626, 100, 40);
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
PdfFormField button = new PushButtonFormFieldBuilder(doc, "push button").SetWidgetRectangle(rect).SetCaption
|
||||
("push").SetConformanceLevel(PdfAConformanceLevel.PDF_A_1B).CreatePushButton();
|
||||
button.SetFont(font).SetFontSize(12);
|
||||
button.RegenerateField();
|
||||
form.AddField(button);
|
||||
Exception exception = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException.ALL_THE_FONTS_MUST_BE_EMBEDDED_THIS_ONE_IS_NOT_0
|
||||
, "Helvetica"), exception.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA1bButtonAppearanceSetValueTest() {
|
||||
// TODO: DEVSIX-3913 update this test after the ticket will be resolved
|
||||
String name = "pdfA1b_ButtonAppearanceSetValueTest";
|
||||
String outPath = destinationFolder + name + ".pdf";
|
||||
String cmpPath = cmpFolder + "cmp_" + name + ".pdf";
|
||||
String diff = "diff_" + name + "_";
|
||||
PdfWriter writer = new PdfWriter(outPath);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent);
|
||||
doc.SetTagged();
|
||||
doc.GetCatalog().SetLang(new PdfString("en-US"));
|
||||
doc.AddNewPage();
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
|
||||
Rectangle rect = new Rectangle(36, 626, 100, 40);
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
PdfFormField button = new PushButtonFormFieldBuilder(doc, "push button").SetWidgetRectangle(rect).SetCaption
|
||||
("push").SetConformanceLevel(PdfAConformanceLevel.PDF_A_1B).CreatePushButton();
|
||||
button.SetFont(font).SetFontSize(12);
|
||||
button.SetValue("button");
|
||||
form.AddField(button);
|
||||
Exception exception = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => doc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException.ALL_THE_FONTS_MUST_BE_EMBEDDED_THIS_ONE_IS_NOT_0
|
||||
, "Helvetica"), exception.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
103
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfARadiofieldTest.cs
Normal file
103
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfARadiofieldTest.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
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.Forms.Fields;
|
||||
using TSpdf.Kernel.Colors;
|
||||
using TSpdf.Kernel.Geom;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Utils;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfARadiofieldTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
public static readonly String cmpFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/cmp/PdfARadiofieldTest/";
|
||||
|
||||
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/PdfARadiofieldTest/";
|
||||
|
||||
[NUnit.Framework.OneTimeSetUp]
|
||||
public static void BeforeClass() {
|
||||
CreateDestinationFolder(destinationFolder);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA1aRadioFieldOffAppearanceTest() {
|
||||
String name = "pdfA1a_radioFieldOffAppearance";
|
||||
String outPath = destinationFolder + name + ".pdf";
|
||||
String cmpPath = cmpFolder + "cmp_" + name + ".pdf";
|
||||
String diff = "diff_" + name + "_";
|
||||
PdfWriter writer = new PdfWriter(outPath);
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent);
|
||||
doc.SetTagged();
|
||||
doc.GetCatalog().SetLang(new PdfString("en-US"));
|
||||
doc.AddNewPage();
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
|
||||
PdfButtonFormField group = new RadioFormFieldBuilder(doc, "group").SetConformanceLevel(PdfAConformanceLevel
|
||||
.PDF_A_1B).CreateRadioGroup();
|
||||
group.SetValue("1", true);
|
||||
group.SetReadOnly(true);
|
||||
Rectangle rect1 = new Rectangle(36, 700, 20, 20);
|
||||
Rectangle rect2 = new Rectangle(36, 680, 20, 20);
|
||||
new RadioFormFieldBuilder(doc).SetWidgetRectangle(rect1).SetConformanceLevel(PdfAConformanceLevel.PDF_A_1B
|
||||
).CreateRadioButton(group, "1").GetFirstFormAnnotation().SetBorderWidth(2).SetBorderColor(ColorConstants
|
||||
.RED).SetBackgroundColor(ColorConstants.LIGHT_GRAY).SetVisibility(PdfFormAnnotation.VISIBLE);
|
||||
new RadioFormFieldBuilder(doc).SetWidgetRectangle(rect2).SetConformanceLevel(PdfAConformanceLevel.PDF_A_1B
|
||||
).CreateRadioButton(group, "2").GetFirstFormAnnotation().SetBorderWidth(2).SetBorderColor(ColorConstants
|
||||
.RED).SetBackgroundColor(ColorConstants.LIGHT_GRAY).SetVisibility(PdfFormAnnotation.VISIBLE);
|
||||
form.AddField(group);
|
||||
doc.Close();
|
||||
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
101
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfAStampingModeTest.cs
Normal file
101
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfAStampingModeTest.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
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;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Utils;
|
||||
using TSpdf.Test;
|
||||
using TSpdf.Test.Pdfa;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfAStampingModeTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/PdfAStampingModeTest/";
|
||||
|
||||
public static readonly String cmpFolder = sourceFolder + "cmp/PdfAStampingModeTest/";
|
||||
|
||||
[NUnit.Framework.OneTimeSetUp]
|
||||
public static void BeforeClass() {
|
||||
CreateOrClearDestinationFolder(destinationFolder);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA1FieldStampingModeTest01() {
|
||||
String fileName = "pdfA1FieldStampingModeTest01.pdf";
|
||||
PdfADocument pdfDoc = new PdfADocument(new PdfReader(sourceFolder + "pdfs/pdfA1DocumentWithPdfA1Fields01.pdf"
|
||||
), new PdfWriter(destinationFolder + fileName));
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, false);
|
||||
form.GetField("checkBox").SetValue("0");
|
||||
pdfDoc.Close();
|
||||
CompareTool compareTool = new CompareTool();
|
||||
NUnit.Framework.Assert.IsNull(compareTool.CompareByContent(destinationFolder + fileName, cmpFolder + "cmp_"
|
||||
+ fileName, destinationFolder, "diff_"));
|
||||
NUnit.Framework.Assert.IsNull(compareTool.CompareXmp(destinationFolder + fileName, cmpFolder + "cmp_" + fileName
|
||||
, true));
|
||||
NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(destinationFolder + fileName));
|
||||
}
|
||||
|
||||
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void PdfA2FieldStampingModeTest01() {
|
||||
String fileName = "pdfA2FieldStampingModeTest01.pdf";
|
||||
PdfADocument pdfDoc = new PdfADocument(new PdfReader(sourceFolder + "pdfs/pdfA2DocumentWithPdfA2Fields01.pdf"
|
||||
), new PdfWriter(destinationFolder + fileName));
|
||||
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, false);
|
||||
form.GetField("checkBox").SetValue("0");
|
||||
pdfDoc.Close();
|
||||
CompareTool compareTool = new CompareTool();
|
||||
NUnit.Framework.Assert.IsNull(compareTool.CompareByContent(destinationFolder + fileName, cmpFolder + "cmp_"
|
||||
+ fileName, destinationFolder, "diff_"));
|
||||
NUnit.Framework.Assert.IsNull(compareTool.CompareXmp(destinationFolder + fileName, cmpFolder + "cmp_" + fileName
|
||||
, true));
|
||||
NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(destinationFolder + fileName));
|
||||
}
|
||||
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
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.Commons.Utils;
|
||||
using TSpdf.IO.Image;
|
||||
using TSpdf.Kernel.Font;
|
||||
using TSpdf.Kernel.Geom;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Pdf.Canvas;
|
||||
using TSpdf.Kernel.Pdf.Colorspace;
|
||||
using TSpdf.Kernel.Pdf.Extgstate;
|
||||
using TSpdf.Kernel.Pdf.Xobject;
|
||||
using TSpdf.Kernel.Utils;
|
||||
using TSpdf.Pdfa.Exceptions;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfATransparencyCheckTest : ExtendedTSpdfTest {
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
public static readonly String cmpFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/cmp/PdfATransparencyCheckTest/";
|
||||
|
||||
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/PdfATransparencyCheckTest/";
|
||||
|
||||
[NUnit.Framework.OneTimeSetUp]
|
||||
public static void BeforeClass() {
|
||||
CreateOrClearDestinationFolder(destinationFolder);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void TextTransparencyNoOutputIntentTest() {
|
||||
PdfWriter writer = new PdfWriter(new MemoryStream());
|
||||
PdfDocument pdfDocument = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_3B, null);
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "Identity-H", PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
PdfPage page1 = pdfDocument.AddNewPage();
|
||||
PdfCanvas canvas = new PdfCanvas(page1);
|
||||
canvas.SaveState();
|
||||
canvas.BeginText().MoveText(36, 750).SetFontAndSize(font, 16).ShowText("Page 1 without transparency").EndText
|
||||
().RestoreState();
|
||||
PdfPage page2 = pdfDocument.AddNewPage();
|
||||
canvas = new PdfCanvas(page2);
|
||||
canvas.SaveState();
|
||||
PdfExtGState state = new PdfExtGState();
|
||||
state.SetFillOpacity(0.6f);
|
||||
canvas.SetExtGState(state);
|
||||
canvas.BeginText().MoveText(36, 750).SetFontAndSize(font, 16).ShowText("Page 2 with transparency").EndText
|
||||
().RestoreState();
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfDocument.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException.THE_DOCUMENT_DOES_NOT_CONTAIN_A_PDFA_OUTPUTINTENT_BUT_PAGE_CONTAINS_TRANSPARENCY_AND_DOES_NOT_CONTAIN_BLENDING_COLOR_SPACE
|
||||
), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void TransparentTextWithGroupColorSpaceTest() {
|
||||
String outPdf = destinationFolder + "transparencyAndCS.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_transparencyAndCS.pdf";
|
||||
PdfDocument pdfDocument = new PdfADocument(new PdfWriter(outPdf), PdfAConformanceLevel.PDF_A_3B, null);
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "Identity-H", PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
PdfPage page = pdfDocument.AddNewPage();
|
||||
page.GetResources().SetDefaultGray(new PdfCieBasedCs.CalGray(GetCalGrayArray()));
|
||||
PdfCanvas canvas = new PdfCanvas(page);
|
||||
canvas.SaveState();
|
||||
PdfExtGState state = new PdfExtGState();
|
||||
state.SetFillOpacity(0.6f);
|
||||
canvas.SetExtGState(state);
|
||||
canvas.BeginText().MoveText(36, 750).SetFontAndSize(font, 16).ShowText("Page 1 with transparency").EndText
|
||||
().RestoreState();
|
||||
PdfDictionary groupObj = new PdfDictionary();
|
||||
groupObj.Put(PdfName.CS, new PdfCieBasedCs.CalGray(GetCalGrayArray()).GetPdfObject());
|
||||
groupObj.Put(PdfName.Type, PdfName.Group);
|
||||
groupObj.Put(PdfName.S, PdfName.Transparency);
|
||||
page.GetPdfObject().Put(PdfName.Group, groupObj);
|
||||
PdfPage page2 = pdfDocument.AddNewPage();
|
||||
page2.GetResources().SetDefaultGray(new PdfCieBasedCs.CalGray(GetCalGrayArray()));
|
||||
canvas = new PdfCanvas(page2);
|
||||
canvas.SaveState();
|
||||
canvas.BeginText().MoveText(36, 750).SetFontAndSize(font, 16).ShowText("Page 2 without transparency").EndText
|
||||
().RestoreState();
|
||||
pdfDocument.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ImageTransparencyTest() {
|
||||
PdfDocument pdfDoc = new PdfADocument(new PdfWriter(new MemoryStream()), PdfAConformanceLevel.PDF_A_3B, null
|
||||
);
|
||||
PdfPage page = pdfDoc.AddNewPage();
|
||||
PdfCanvas canvas = new PdfCanvas(page);
|
||||
page.GetResources().SetDefaultRgb(new PdfCieBasedCs.CalRgb(new float[] { 0.3f, 0.4f, 0.5f }));
|
||||
canvas.SaveState();
|
||||
canvas.AddImageFittedIntoRectangle(ImageDataFactory.Create(sourceFolder + "TSpdf.png"), new Rectangle(0, 0
|
||||
, page.GetPageSize().GetWidth() / 2, page.GetPageSize().GetHeight() / 2), false);
|
||||
canvas.RestoreState();
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfDoc.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException.THE_DOCUMENT_DOES_NOT_CONTAIN_A_PDFA_OUTPUTINTENT_BUT_PAGE_CONTAINS_TRANSPARENCY_AND_DOES_NOT_CONTAIN_BLENDING_COLOR_SPACE
|
||||
), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void NestedXObjectWithTransparencyTest() {
|
||||
PdfWriter writer = new PdfWriter(new MemoryStream());
|
||||
PdfDocument pdfDocument = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_3B, null);
|
||||
PdfFormXObject form1 = new PdfFormXObject(new Rectangle(0, 0, 50, 50));
|
||||
PdfCanvas canvas1 = new PdfCanvas(form1, pdfDocument);
|
||||
canvas1.SaveState();
|
||||
PdfExtGState state = new PdfExtGState();
|
||||
state.SetFillOpacity(0.6f);
|
||||
canvas1.SetExtGState(state);
|
||||
canvas1.Circle(25, 25, 10);
|
||||
canvas1.Fill();
|
||||
canvas1.RestoreState();
|
||||
canvas1.Release();
|
||||
form1.Flush();
|
||||
//Create form XObject and flush to document.
|
||||
PdfFormXObject form = new PdfFormXObject(new Rectangle(0, 0, 50, 50));
|
||||
PdfCanvas canvas = new PdfCanvas(form, pdfDocument);
|
||||
canvas.Rectangle(10, 10, 30, 30);
|
||||
canvas.Stroke();
|
||||
canvas.AddXObjectAt(form1, 0, 0);
|
||||
canvas.Release();
|
||||
form.Flush();
|
||||
//Create page1 and add forms to the page.
|
||||
PdfPage page1 = pdfDocument.AddNewPage();
|
||||
canvas = new PdfCanvas(page1);
|
||||
canvas.AddXObjectAt(form, 0, 0);
|
||||
canvas.Release();
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfDocument.Close());
|
||||
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(PdfAConformanceException.THE_DOCUMENT_DOES_NOT_CONTAIN_A_PDFA_OUTPUTINTENT_BUT_PAGE_CONTAINS_TRANSPARENCY_AND_DOES_NOT_CONTAIN_BLENDING_COLOR_SPACE
|
||||
), e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void TestTransparencyObjectsAbsence() {
|
||||
String outPdf = destinationFolder + "transparencyObjectsAbsence.pdf";
|
||||
String cmpPdf = cmpFolder + "cmp_transparencyObjectsAbsence.pdf";
|
||||
PdfDocument pdfDocument = new PdfADocument(new PdfWriter(outPdf), PdfAConformanceLevel.PDF_A_3B, null);
|
||||
PdfPage page = pdfDocument.AddNewPage();
|
||||
PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "Identity-H", PdfFontFactory.EmbeddingStrategy
|
||||
.FORCE_EMBEDDED);
|
||||
PdfCanvas canvas = new PdfCanvas(page);
|
||||
page.GetResources().SetDefaultGray(new PdfCieBasedCs.CalGray(GetCalGrayArray()));
|
||||
canvas.BeginText().MoveText(36, 750).SetFontAndSize(font, 16).ShowText("Page 1").EndText();
|
||||
PdfDictionary groupObj = new PdfDictionary();
|
||||
groupObj.Put(PdfName.Type, PdfName.Group);
|
||||
groupObj.Put(PdfName.S, PdfName.Transparency);
|
||||
page.GetPdfObject().Put(PdfName.Group, groupObj);
|
||||
pdfDocument.Close();
|
||||
CompareResult(outPdf, cmpPdf);
|
||||
}
|
||||
|
||||
private void CompareResult(String outPdf, String cmpPdf) {
|
||||
String result = new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_");
|
||||
if (result != null) {
|
||||
NUnit.Framework.Assert.Fail(result);
|
||||
}
|
||||
}
|
||||
|
||||
private PdfArray GetCalGrayArray() {
|
||||
PdfDictionary dictionary = new PdfDictionary();
|
||||
dictionary.Put(PdfName.Gamma, new PdfNumber(2.2));
|
||||
PdfArray whitePointArray = new PdfArray();
|
||||
whitePointArray.Add(new PdfNumber(0.9505));
|
||||
whitePointArray.Add(new PdfNumber(1.0));
|
||||
whitePointArray.Add(new PdfNumber(1.089));
|
||||
dictionary.Put(PdfName.WhitePoint, whitePointArray);
|
||||
PdfArray array = new PdfArray();
|
||||
array.Add(PdfName.CalGray);
|
||||
array.Add(dictionary);
|
||||
return array;
|
||||
}
|
||||
}
|
||||
}
|
||||
145
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfAXmpTest.cs
Normal file
145
TSpdf.tests/TSpdf.pdfa.tests/TSpdf/pdfa/PdfAXmpTest.cs
Normal 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 TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Utils;
|
||||
using TSpdf.Kernel.XMP;
|
||||
using TSpdf.Kernel.XMP.Options;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa {
|
||||
[NUnit.Framework.Category("IntegrationTest")]
|
||||
public class PdfAXmpTest : ExtendedTSpdfTest {
|
||||
public static readonly String cmpFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/cmp/PdfAXmpTest/";
|
||||
|
||||
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
|
||||
+ "/test/TSpdf/pdfa/PdfAXmpTest/";
|
||||
|
||||
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
|
||||
.CurrentContext.TestDirectory) + "/resources/TSpdf/pdfa/";
|
||||
|
||||
[NUnit.Framework.OneTimeSetUp]
|
||||
public static void BeforeClass() {
|
||||
CreateOrClearDestinationFolder(destinationFolder);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void KeywordsInfoTestPdfA1b() {
|
||||
String outFile = destinationFolder + "keywordsInfoTestPdfA1b.pdf";
|
||||
String cmpFile = cmpFolder + "cmp_keywordsInfoTestPdfA1b.pdf";
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument doc = new PdfADocument(new PdfWriter(outFile), PdfAConformanceLevel.PDF_A_1B, outputIntent);
|
||||
doc.AddNewPage();
|
||||
doc.GetDocumentInfo().SetKeywords("key1, key2 , key3;key4,key5");
|
||||
doc.Close();
|
||||
CompareTool ct = new CompareTool();
|
||||
NUnit.Framework.Assert.IsNull(ct.CompareByContent(outFile, cmpFile, destinationFolder));
|
||||
NUnit.Framework.Assert.IsNull(ct.CompareDocumentInfo(outFile, cmpFile));
|
||||
NUnit.Framework.Assert.IsNull(ct.CompareXmp(outFile, cmpFile, true));
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void KeywordsInfoTestPdfA2b() {
|
||||
String outFile = destinationFolder + "keywordsInfoTestPdfA2b.pdf";
|
||||
String cmpFile = cmpFolder + "cmp_keywordsInfoTestPdfA2b.pdf";
|
||||
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
|
||||
PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
|
||||
, @is);
|
||||
PdfADocument doc = new PdfADocument(new PdfWriter(outFile), PdfAConformanceLevel.PDF_A_2B, outputIntent);
|
||||
doc.AddNewPage();
|
||||
doc.GetDocumentInfo().SetKeywords("key1, key2 , key3;key4,key5");
|
||||
doc.Close();
|
||||
CompareTool ct = new CompareTool();
|
||||
NUnit.Framework.Assert.IsNull(ct.CompareByContent(outFile, cmpFile, destinationFolder));
|
||||
NUnit.Framework.Assert.IsNull(ct.CompareDocumentInfo(outFile, cmpFile));
|
||||
NUnit.Framework.Assert.IsNull(ct.CompareXmp(outFile, cmpFile, true));
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void SaveAndReadDocumentWithCanonicalXmpMetadata() {
|
||||
String outFile = destinationFolder + "saveAndReadDocumentWithCanonicalXmpMetadata.pdf";
|
||||
String cmpFile = cmpFolder + "cmp_saveAndReadDocumentWithCanonicalXmpMetadata.pdf";
|
||||
PdfAConformanceLevel conformanceLevel = PdfAConformanceLevel.PDF_A_2B;
|
||||
PdfOutputIntent outputIntent;
|
||||
using (Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read
|
||||
)) {
|
||||
outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", @is);
|
||||
}
|
||||
using (PdfADocument doc = new PdfADocument(new PdfWriter(outFile), conformanceLevel, outputIntent)) {
|
||||
doc.AddNewPage();
|
||||
XMPMeta xmp = XMPMetaFactory.Create();
|
||||
xmp.SetProperty(XMPConst.NS_PDFA_ID, XMPConst.PART, conformanceLevel.GetPart(), new PropertyOptions().SetSchemaNode
|
||||
(true));
|
||||
xmp.SetProperty(XMPConst.NS_PDFA_ID, XMPConst.CONFORMANCE, conformanceLevel.GetConformance(), new PropertyOptions
|
||||
().SetSchemaNode(true));
|
||||
SerializeOptions options = new SerializeOptions().SetUseCanonicalFormat(true).SetUseCompactFormat(false);
|
||||
doc.SetXmpMetadata(xmp, options);
|
||||
doc.SetTagged();
|
||||
}
|
||||
// Closing document and reopening it to flush it XMP metadata ModifyDate
|
||||
using (PdfDocument doc_1 = new PdfDocument(new PdfReader(outFile))) {
|
||||
using (PdfDocument cmpDoc = new PdfDocument(new PdfReader(cmpFile))) {
|
||||
byte[] rdf = doc_1.GetXmpMetadata();
|
||||
byte[] expectedRdf = cmpDoc.GetXmpMetadata();
|
||||
// Comparing angle brackets, since it's the main difference between canonical and compact format.
|
||||
NUnit.Framework.Assert.AreEqual(Count(expectedRdf, (byte)'<'), Count(rdf, (byte)'<'));
|
||||
NUnit.Framework.Assert.IsNull(new CompareTool().CompareXmp(cmpFile, outFile, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int Count(byte[] array, byte b) {
|
||||
int counter = 0;
|
||||
foreach (byte each in array) {
|
||||
if (each == b) {
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
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.Pdfa.Exceptions;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa.Checker {
|
||||
[NUnit.Framework.Category("UnitTest")]
|
||||
public class PdfA1CheckerTest : ExtendedTSpdfTest {
|
||||
private PdfA1Checker pdfA1Checker = new PdfA1Checker(PdfAConformanceLevel.PDF_A_1B);
|
||||
|
||||
[NUnit.Framework.SetUp]
|
||||
public virtual void Before() {
|
||||
pdfA1Checker.SetFullCheckMode(true);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckCatalogDictionaryWithoutAAEntry() {
|
||||
PdfDictionary catalog = new PdfDictionary();
|
||||
catalog.Put(PdfName.AA, new PdfDictionary());
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfA1Checker.CheckCatalogValidEntries
|
||||
(catalog));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.A_CATALOG_DICTIONARY_SHALL_NOT_CONTAIN_AA_ENTRY,
|
||||
e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckCatalogDictionaryWithoutOCPropertiesEntry() {
|
||||
PdfDictionary catalog = new PdfDictionary();
|
||||
catalog.Put(PdfName.OCProperties, new PdfDictionary());
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfA1Checker.CheckCatalogValidEntries
|
||||
(catalog));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.A_CATALOG_DICTIONARY_SHALL_NOT_CONTAIN_OCPROPERTIES_KEY
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckCatalogDictionaryWithoutEmbeddedFiles() {
|
||||
PdfDictionary names = new PdfDictionary();
|
||||
names.Put(PdfName.EmbeddedFiles, new PdfDictionary());
|
||||
PdfDictionary catalog = new PdfDictionary();
|
||||
catalog.Put(PdfName.Names, names);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfA1Checker.CheckCatalogValidEntries
|
||||
(catalog));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.A_NAME_DICTIONARY_SHALL_NOT_CONTAIN_THE_EMBEDDED_FILES_KEY
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckValidCatalog() {
|
||||
pdfA1Checker.CheckCatalogValidEntries(new PdfDictionary());
|
||||
}
|
||||
|
||||
// checkCatalogValidEntries doesn't change the state of any object
|
||||
// and doesn't return any value. The only result is exception which
|
||||
// was or wasn't thrown. Successful scenario is tested here therefore
|
||||
// no assertion is provided
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckSignatureTest() {
|
||||
PdfDictionary dict = new PdfDictionary();
|
||||
pdfA1Checker.CheckSignature(dict);
|
||||
NUnit.Framework.Assert.IsTrue(pdfA1Checker.ObjectIsChecked(dict));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,575 @@
|
||||
/*
|
||||
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.Kernel.Colors;
|
||||
using TSpdf.Kernel.Font;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Pdf.Colorspace;
|
||||
using TSpdf.Kernel.Pdf.Function;
|
||||
using TSpdf.Kernel.Pdf.Xobject;
|
||||
using TSpdf.Pdfa.Exceptions;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa.Checker {
|
||||
[NUnit.Framework.Category("UnitTest")]
|
||||
public class PdfA1ImplementationLimitsCheckerTest : ExtendedTSpdfTest {
|
||||
private PdfA1Checker pdfA1Checker = new PdfA1Checker(PdfAConformanceLevel.PDF_A_1B);
|
||||
|
||||
private const int MAX_ARRAY_CAPACITY = 8191;
|
||||
|
||||
private const int MAX_DICTIONARY_CAPACITY = 4095;
|
||||
|
||||
[NUnit.Framework.SetUp]
|
||||
public virtual void Before() {
|
||||
pdfA1Checker.SetFullCheckMode(true);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ValidObjectsTest() {
|
||||
int maxNameLength = pdfA1Checker.GetMaxNameLength();
|
||||
int maxStringLength = pdfA1Checker.GetMaxStringLength();
|
||||
int maxArrayCapacity = MAX_ARRAY_CAPACITY;
|
||||
int maxDictionaryCapacity = MAX_DICTIONARY_CAPACITY;
|
||||
long maxIntegerValue = pdfA1Checker.GetMaxIntegerValue();
|
||||
long minIntegerValue = pdfA1Checker.GetMinIntegerValue();
|
||||
double maxRealValue = pdfA1Checker.GetMaxRealValue();
|
||||
NUnit.Framework.Assert.AreEqual(65535, maxStringLength);
|
||||
NUnit.Framework.Assert.AreEqual(127, maxNameLength);
|
||||
PdfString longString = PdfACheckerTestUtils.GetLongString(maxStringLength);
|
||||
PdfName longName = PdfACheckerTestUtils.GetLongName(maxNameLength);
|
||||
PdfArray longArray = PdfACheckerTestUtils.GetLongArray(maxArrayCapacity);
|
||||
PdfDictionary longDictionary = PdfACheckerTestUtils.GetLongDictionary(maxDictionaryCapacity);
|
||||
NUnit.Framework.Assert.AreEqual(2147483647, maxIntegerValue);
|
||||
NUnit.Framework.Assert.AreEqual(-2147483648, minIntegerValue);
|
||||
NUnit.Framework.Assert.AreEqual(32767, maxRealValue, 0.001);
|
||||
PdfNumber largeInteger = new PdfNumber(maxIntegerValue);
|
||||
PdfNumber negativeInteger = new PdfNumber(minIntegerValue);
|
||||
PdfNumber largeReal = new PdfNumber(maxRealValue - 0.001);
|
||||
PdfObject[] largeObjects = new PdfObject[] { longName, longString, longArray, longDictionary, largeInteger
|
||||
, negativeInteger, largeReal };
|
||||
// No exceptions should not be thrown as all values match the
|
||||
// limitations provided in specification
|
||||
foreach (PdfObject largeObject in largeObjects) {
|
||||
pdfA1Checker.CheckPdfObject(largeObject);
|
||||
CheckInArray(largeObject);
|
||||
CheckInDictionary(largeObject);
|
||||
CheckInComplexStructure(largeObject);
|
||||
CheckInContentStream(largeObject);
|
||||
CheckInArrayInContentStream(largeObject);
|
||||
CheckInDictionaryInContentStream(largeObject);
|
||||
CheckInFormXObject(largeObject);
|
||||
CheckInTilingPattern(largeObject);
|
||||
CheckInType3Font(largeObject);
|
||||
}
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ValidStreamTest() {
|
||||
PdfStream longStream = PdfACheckerTestUtils.GetStreamWithLongDictionary(MAX_DICTIONARY_CAPACITY);
|
||||
// No exceptions should not be thrown as the stream match the
|
||||
// limitations provided in specification
|
||||
pdfA1Checker.CheckPdfObject(longStream);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void IndependentLongStringTest() {
|
||||
PdfString longString = BuildLongString();
|
||||
// An exception should be thrown as provided String is longer then
|
||||
// it is allowed per specification
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfA1Checker.CheckPdfObject
|
||||
(longString));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.PDF_STRING_IS_TOO_LONG, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void IndependentLongNameTest() {
|
||||
PdfName longName = BuildLongName();
|
||||
// An exception should be thrown as provided name is longer then
|
||||
// it is allowed per specification
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfA1Checker.CheckPdfObject
|
||||
(longName));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.PDF_NAME_IS_TOO_LONG, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void IndependentLargeIntegerTest() {
|
||||
PdfNumber largeNumber = new PdfNumber(pdfA1Checker.GetMaxIntegerValue() + 1L);
|
||||
// An exception should be thrown as provided integer is larger then
|
||||
// it is allowed per specification
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfA1Checker.CheckPdfObject
|
||||
(largeNumber));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.INTEGER_NUMBER_IS_OUT_OF_RANGE, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void IndependentLargeNegativeIntegerTest() {
|
||||
PdfNumber largeNumber = new PdfNumber(pdfA1Checker.GetMinIntegerValue() - 1L);
|
||||
// An exception should be thrown as provided integer is smaller then
|
||||
// it is allowed per specification
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfA1Checker.CheckPdfObject
|
||||
(largeNumber));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.INTEGER_NUMBER_IS_OUT_OF_RANGE, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void IndependentLargeRealTest() {
|
||||
PdfNumber largeNumber = new PdfNumber(pdfA1Checker.GetMaxRealValue() + 1.0);
|
||||
// TODO DEVSIX-4182
|
||||
// An exception is not thrown as any number greater then 32767 is considered as Integer
|
||||
pdfA1Checker.CheckPdfObject(largeNumber);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void IndependentLongArrayTest() {
|
||||
PdfArray longArray = BuildLongArray();
|
||||
// An exception should be thrown as provided array has more elements then
|
||||
// it is allowed per specification
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfA1Checker.CheckPdfObject
|
||||
(longArray));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.MAXIMUM_ARRAY_CAPACITY_IS_EXCEEDED, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void IndependentLongDictionaryTest() {
|
||||
PdfDictionary longDictionary = BuildLongDictionary();
|
||||
// An exception should be thrown as provided dictionary has more entries
|
||||
// then it is allowed per specification
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfA1Checker.CheckPdfObject
|
||||
(longDictionary));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.MAXIMUM_DICTIONARY_CAPACITY_IS_EXCEEDED, e.Message
|
||||
);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void IndependentStreamWithLongDictionaryTest() {
|
||||
PdfStream longStream = BuildStreamWithLongDictionary();
|
||||
// An exception should be thrown as dictionary of the stream has more entries
|
||||
// then it is allowed per specification
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfA1Checker.CheckPdfObject
|
||||
(longStream));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.MAXIMUM_DICTIONARY_CAPACITY_IS_EXCEEDED, e.Message
|
||||
);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void LongStringInDictionaryTest() {
|
||||
PdfString longString = BuildLongString();
|
||||
// An exception should be thrown as dictionary contains value which is longer then
|
||||
// it is allowed per specification
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => CheckInDictionary(longString
|
||||
));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.PDF_STRING_IS_TOO_LONG, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void LongNameAsKeyInDictionaryTest() {
|
||||
PdfName longName = BuildLongName();
|
||||
PdfDictionary dict = new PdfDictionary();
|
||||
dict.Put(new PdfName("Key1"), new PdfString("value1"));
|
||||
dict.Put(new PdfName("Key2"), new PdfString("value2"));
|
||||
dict.Put(longName, new PdfString("value3"));
|
||||
// An exception should be thrown as dictionary contains key which is longer then
|
||||
// it is allowed per specification
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfA1Checker.CheckPdfObject
|
||||
(dict));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.PDF_NAME_IS_TOO_LONG, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void LongStringInArrayTest() {
|
||||
PdfString longString = BuildLongString();
|
||||
// An exception should be thrown as one element is longer then
|
||||
// it is allowed per specification
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => CheckInArray(longString
|
||||
));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.PDF_STRING_IS_TOO_LONG, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void LongStringInContentStreamTest() {
|
||||
PdfString longString = BuildLongString();
|
||||
// An exception should be thrown as content stream has a string which
|
||||
// is longer then it is allowed per specification
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => CheckInContentStream(longString
|
||||
));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.PDF_STRING_IS_TOO_LONG, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void LongNameInContentStreamTest() {
|
||||
PdfName longName = BuildLongName();
|
||||
// An exception should be thrown as content stream has a name which
|
||||
// is longer then it is allowed per specification
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => CheckInContentStream(longName
|
||||
));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.PDF_NAME_IS_TOO_LONG, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void LargeIntegerInContentStreamTest() {
|
||||
PdfNumber largeNumber = new PdfNumber(pdfA1Checker.GetMaxIntegerValue() + 1L);
|
||||
// An exception should be thrown as provided integer is larger then
|
||||
// it is allowed per specification
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => CheckInContentStream(largeNumber
|
||||
));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.INTEGER_NUMBER_IS_OUT_OF_RANGE, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void LargeNegativeIntegerInContentStreamTest() {
|
||||
PdfNumber largeNumber = new PdfNumber(pdfA1Checker.GetMinIntegerValue() - 1L);
|
||||
// An exception should be thrown as provided integer is smaller then
|
||||
// it is allowed per specification
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => CheckInContentStream(largeNumber
|
||||
));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.INTEGER_NUMBER_IS_OUT_OF_RANGE, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void LargeRealInContentStreamTest() {
|
||||
PdfNumber largeNumber = new PdfNumber(pdfA1Checker.GetMaxRealValue() + 1.0);
|
||||
// TODO DEVSIX-4182
|
||||
// An exception is not thrown as any number greater then 32767 is considered as Integer
|
||||
CheckInContentStream(largeNumber);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void LongArrayInContentStreamTest() {
|
||||
PdfArray longArray = BuildLongArray();
|
||||
// An exception should be thrown as provided array has more elements then
|
||||
// it is allowed per specification
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => CheckInContentStream(longArray
|
||||
));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.MAXIMUM_ARRAY_CAPACITY_IS_EXCEEDED, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void LongDictionaryInContentStream() {
|
||||
PdfDictionary longDictionary = BuildLongDictionary();
|
||||
// An exception should be thrown as provided dictionary has more entries
|
||||
// then it is allowed per specification
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => CheckInContentStream(longDictionary
|
||||
));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.MAXIMUM_DICTIONARY_CAPACITY_IS_EXCEEDED, e.Message
|
||||
);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ContentStreamIsNotCheckedForNotModifiedObjectTest() {
|
||||
pdfA1Checker.SetFullCheckMode(false);
|
||||
PdfString longString = BuildLongString();
|
||||
PdfArray longArray = BuildLongArray();
|
||||
PdfDictionary longDictionary = BuildLongDictionary();
|
||||
// An exception should not be thrown as content stream considered as not modified
|
||||
// and won't be tested
|
||||
CheckInContentStream(longString);
|
||||
CheckInContentStream(longArray);
|
||||
CheckInContentStream(longDictionary);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void IndirectObjectIsNotCheckTest() {
|
||||
pdfA1Checker.SetFullCheckMode(false);
|
||||
PdfStream longStream = BuildStreamWithLongDictionary();
|
||||
// An exception should not be thrown as pdf stream is an indirect object
|
||||
// it is ignored during array / dictionary validation as it is expected
|
||||
// to be validated and flushed independently
|
||||
CheckInArray(longStream);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void LongStringInArrayInContentStreamTest() {
|
||||
PdfString longString = BuildLongString();
|
||||
// An exception should be thrown as content stream has a string which
|
||||
// is longer then it is allowed per specification
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => CheckInArrayInContentStream
|
||||
(longString));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.PDF_STRING_IS_TOO_LONG, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void LongStringInDictionaryInContentStreamTest() {
|
||||
PdfString longString = BuildLongString();
|
||||
// An exception should be thrown as content stream has a string which
|
||||
// is longer then it is allowed per specification
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => CheckInDictionaryInContentStream
|
||||
(longString));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.PDF_STRING_IS_TOO_LONG, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void LongNameAsKeyInDictionaryInContentStreamTest() {
|
||||
PdfName longName = BuildLongName();
|
||||
PdfDictionary dict = new PdfDictionary();
|
||||
dict.Put(new PdfName("Key1"), new PdfString("value1"));
|
||||
dict.Put(new PdfName("Key2"), new PdfString("value2"));
|
||||
dict.Put(longName, new PdfString("value3"));
|
||||
// An exception should be thrown as content stream has a string which
|
||||
// is longer then it is allowed per specification
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => CheckInContentStream(dict
|
||||
));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.PDF_NAME_IS_TOO_LONG, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void LongStringInComplexStructureTest() {
|
||||
PdfString longString = BuildLongString();
|
||||
// An exception should be thrown as there is a string element which
|
||||
// doesn't match the limitations provided in specification
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => CheckInComplexStructure
|
||||
(longString));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.PDF_STRING_IS_TOO_LONG, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void LongArrayInComplexStructureTest() {
|
||||
PdfArray longArray = BuildLongArray();
|
||||
// An exception should be thrown as provided array has more elements then
|
||||
// it is allowed per specification
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => CheckInComplexStructure
|
||||
(longArray));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.MAXIMUM_ARRAY_CAPACITY_IS_EXCEEDED, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void LongDictionaryInComplexStructureTest() {
|
||||
PdfDictionary longDictionary = BuildLongDictionary();
|
||||
// An exception should be thrown as provided dictionary has more entries
|
||||
// then it is allowed per specification
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => CheckInComplexStructure
|
||||
(longDictionary));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.MAXIMUM_DICTIONARY_CAPACITY_IS_EXCEEDED, e.Message
|
||||
);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void LongStringInPdfFormXObjectTest() {
|
||||
PdfString longString = BuildLongString();
|
||||
// An exception should be thrown as form xobject content stream has a string which
|
||||
// is longer then it is allowed per specification
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => CheckInFormXObject(longString
|
||||
));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.PDF_STRING_IS_TOO_LONG, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void LongStringInTilingPatternTest() {
|
||||
PdfString longString = BuildLongString();
|
||||
// An exception should be thrown as tiling pattern's content stream has a string which
|
||||
// is longer then it is allowed per specification
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => CheckInTilingPattern(longString
|
||||
));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.PDF_STRING_IS_TOO_LONG, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void LongStringInShadingPatternTest() {
|
||||
PdfString longString = BuildLongString();
|
||||
// An exception should not be thrown as shading pattern doesn't have
|
||||
// content stream to validate
|
||||
CheckInShadingPattern(longString);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void LongStringInType3FontTest() {
|
||||
PdfString longString = BuildLongString();
|
||||
// An exception should be thrown as content stream of type3 font has a string which
|
||||
// is longer then it is allowed per specification
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => CheckInType3Font(longString
|
||||
));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.PDF_STRING_IS_TOO_LONG, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void DeviceNColorspaceWithMoreThan8Components() {
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => CheckColorspace(BuildDeviceNColorspace
|
||||
(10)));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.THE_NUMBER_OF_COLOR_COMPONENTS_IN_DEVICE_N_COLORSPACE_SHOULD_NOT_EXCEED
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void DeviceNColorspaceWith8Components() {
|
||||
CheckColorspace(BuildDeviceNColorspace(8));
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void DeviceNColorspaceWithLessThan8Components() {
|
||||
CheckColorspace(BuildDeviceNColorspace(2));
|
||||
}
|
||||
|
||||
private PdfString BuildLongString() {
|
||||
int maxAllowedLength = pdfA1Checker.GetMaxStringLength();
|
||||
int testLength = maxAllowedLength + 1;
|
||||
NUnit.Framework.Assert.AreEqual(65536, testLength);
|
||||
return PdfACheckerTestUtils.GetLongString(testLength);
|
||||
}
|
||||
|
||||
private PdfName BuildLongName() {
|
||||
int maxAllowedLength = pdfA1Checker.GetMaxNameLength();
|
||||
int testLength = maxAllowedLength + 1;
|
||||
NUnit.Framework.Assert.AreEqual(128, testLength);
|
||||
return PdfACheckerTestUtils.GetLongName(testLength);
|
||||
}
|
||||
|
||||
private PdfArray BuildLongArray() {
|
||||
int testLength = MAX_ARRAY_CAPACITY + 1;
|
||||
return PdfACheckerTestUtils.GetLongArray(testLength);
|
||||
}
|
||||
|
||||
private PdfDictionary BuildLongDictionary() {
|
||||
int testLength = MAX_DICTIONARY_CAPACITY + 1;
|
||||
return PdfACheckerTestUtils.GetLongDictionary(testLength);
|
||||
}
|
||||
|
||||
private PdfStream BuildStreamWithLongDictionary() {
|
||||
int testLength = MAX_DICTIONARY_CAPACITY + 1;
|
||||
return PdfACheckerTestUtils.GetStreamWithLongDictionary(testLength);
|
||||
}
|
||||
|
||||
private void CheckInDictionary(PdfObject @object) {
|
||||
PdfDictionary dict = new PdfDictionary();
|
||||
dict.Put(new PdfName("Key1"), new PdfString("value1"));
|
||||
dict.Put(new PdfName("Key2"), new PdfString("value2"));
|
||||
dict.Put(new PdfName("Key3"), @object);
|
||||
pdfA1Checker.CheckPdfObject(dict);
|
||||
}
|
||||
|
||||
private void CheckInArray(PdfObject @object) {
|
||||
PdfArray array = new PdfArray();
|
||||
array.Add(new PdfString("value1"));
|
||||
array.Add(new PdfString("value2"));
|
||||
array.Add(@object);
|
||||
pdfA1Checker.CheckPdfObject(array);
|
||||
}
|
||||
|
||||
private void CheckInContentStream(PdfObject @object) {
|
||||
String byteContent = PdfACheckerTestUtils.GetStreamWithValue(@object);
|
||||
byte[] newContent = byteContent.GetBytes(System.Text.Encoding.UTF8);
|
||||
PdfStream stream = new PdfStream(newContent);
|
||||
pdfA1Checker.CheckContentStream(stream);
|
||||
}
|
||||
|
||||
private void CheckInArrayInContentStream(PdfObject @object) {
|
||||
CheckInContentStream(new PdfArray(@object));
|
||||
}
|
||||
|
||||
private void CheckInDictionaryInContentStream(PdfObject @object) {
|
||||
PdfDictionary dict = new PdfDictionary();
|
||||
dict.Put(new PdfName("value"), @object);
|
||||
CheckInContentStream(dict);
|
||||
}
|
||||
|
||||
private void CheckInComplexStructure(PdfObject @object) {
|
||||
PdfDictionary dict1 = new PdfDictionary();
|
||||
dict1.Put(new PdfName("Key1"), new PdfString("value1"));
|
||||
dict1.Put(new PdfName("Key2"), new PdfString("value2"));
|
||||
dict1.Put(new PdfName("Key3"), @object);
|
||||
PdfArray array = new PdfArray();
|
||||
array.Add(new PdfString("value3"));
|
||||
array.Add(new PdfString("value4"));
|
||||
array.Add(dict1);
|
||||
PdfDictionary dict = new PdfDictionary();
|
||||
dict.Put(new PdfName("Key4"), new PdfString("value5"));
|
||||
dict.Put(new PdfName("Key5"), new PdfString("value6"));
|
||||
dict.Put(new PdfName("Key6"), array);
|
||||
pdfA1Checker.CheckPdfObject(array);
|
||||
}
|
||||
|
||||
private void CheckInFormXObject(PdfObject @object) {
|
||||
String newContentString = PdfACheckerTestUtils.GetStreamWithValue(@object);
|
||||
byte[] newContent = newContentString.GetBytes(System.Text.Encoding.UTF8);
|
||||
PdfStream stream = new PdfStream(newContent);
|
||||
PdfXObject xobject = new PdfFormXObject(stream);
|
||||
pdfA1Checker.CheckFormXObject(xobject.GetPdfObject());
|
||||
}
|
||||
|
||||
private void CheckInTilingPattern(PdfObject @object) {
|
||||
String newContentString = PdfACheckerTestUtils.GetStreamWithValue(@object);
|
||||
byte[] newContent = newContentString.GetBytes(System.Text.Encoding.UTF8);
|
||||
PdfPattern pattern = new PdfPattern.Tiling(200, 200);
|
||||
((PdfStream)pattern.GetPdfObject()).SetData(newContent);
|
||||
Color color = new PatternColor(pattern);
|
||||
pdfA1Checker.CheckColor(color, new PdfDictionary(), true, null);
|
||||
}
|
||||
|
||||
private void CheckInShadingPattern(PdfObject @object) {
|
||||
String newContentString = PdfACheckerTestUtils.GetStreamWithValue(@object);
|
||||
byte[] newContent = newContentString.GetBytes(System.Text.Encoding.UTF8);
|
||||
PdfStream stream = new PdfStream(newContent);
|
||||
PdfPattern pattern = new PdfPattern.Shading(stream);
|
||||
pdfA1Checker.CheckPdfObject(pattern.GetPdfObject());
|
||||
}
|
||||
|
||||
private void CheckInType3Font(PdfObject @object) {
|
||||
String newContentString = PdfACheckerTestUtils.GetStreamWithValue(@object);
|
||||
byte[] newContent = newContentString.GetBytes(System.Text.Encoding.UTF8);
|
||||
PdfFont font = PdfFontFactory.CreateType3Font(null, true);
|
||||
PdfDictionary charProcs = new PdfDictionary();
|
||||
charProcs.Put(PdfName.A, new PdfStream(newContent));
|
||||
PdfDictionary dictionary = font.GetPdfObject();
|
||||
dictionary.Put(PdfName.Subtype, PdfName.Type3);
|
||||
dictionary.Put(PdfName.CharProcs, charProcs);
|
||||
pdfA1Checker.CheckFont(font);
|
||||
}
|
||||
|
||||
private void CheckColorspace(PdfColorSpace colorSpace) {
|
||||
PdfDictionary currentColorSpaces = new PdfDictionary();
|
||||
pdfA1Checker.CheckColorSpace(colorSpace, currentColorSpaces, false, false);
|
||||
}
|
||||
|
||||
private PdfColorSpace BuildDeviceNColorspace(int numberOfComponents) {
|
||||
IList<String> tmpArray = new List<String>(numberOfComponents);
|
||||
float[] transformArray = new float[numberOfComponents * 2];
|
||||
for (int i = 0; i < numberOfComponents; i++) {
|
||||
tmpArray.Add("MyColor" + i + 1);
|
||||
transformArray[i * 2] = 0;
|
||||
transformArray[i * 2 + 1] = 1;
|
||||
}
|
||||
PdfFunction.Type4 function = new PdfFunction.Type4(new PdfArray(transformArray), new PdfArray(new float[]
|
||||
{ 0, 1, 0, 1, 0, 1 }), "{0}".GetBytes(TSpdf.Commons.Utils.EncodingUtil.ISO_8859_1));
|
||||
return new PdfSpecialCs.DeviceN(tmpArray, new PdfDeviceCs.Rgb(), function);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
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.Font;
|
||||
using TSpdf.Kernel.Geom;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Pdf.Xobject;
|
||||
using TSpdf.Pdfa.Exceptions;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa.Checker {
|
||||
[NUnit.Framework.Category("UnitTest")]
|
||||
public class PdfA2CheckerGlyphsTest : ExtendedTSpdfTest {
|
||||
private readonly PdfA2Checker pdfA2Checker = new PdfA2Checker(PdfAConformanceLevel.PDF_A_2B);
|
||||
|
||||
[NUnit.Framework.SetUp]
|
||||
public virtual void Before() {
|
||||
pdfA2Checker.SetFullCheckMode(true);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckValidFontGlyphsTest() {
|
||||
using (MemoryStream bos = new MemoryStream()) {
|
||||
using (PdfWriter writer = new PdfWriter(bos)) {
|
||||
using (PdfDocument document = new PdfDocument(writer)) {
|
||||
document.AddNewPage();
|
||||
PdfDictionary charProcs = new PdfDictionary();
|
||||
charProcs.Put(PdfName.A, new PdfStream());
|
||||
charProcs.Put(PdfName.B, new PdfStream());
|
||||
PdfArray differences = new PdfArray();
|
||||
differences.Add(new PdfNumber(41));
|
||||
differences.Add(PdfName.A);
|
||||
differences.Add(new PdfNumber(82));
|
||||
differences.Add(PdfName.B);
|
||||
PdfFont font = CreateFontWithCharProcsAndEncodingDifferences(document, charProcs, differences);
|
||||
// no assertions as we want to ensure that in this case the next method won't throw an exception
|
||||
pdfA2Checker.CheckFontGlyphs(font, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckInvalidFontGlyphsTest() {
|
||||
using (MemoryStream bos = new MemoryStream()) {
|
||||
using (PdfWriter writer = new PdfWriter(bos)) {
|
||||
using (PdfDocument document = new PdfDocument(writer)) {
|
||||
document.AddNewPage();
|
||||
PdfFormXObject formXObject = new PdfFormXObject(new Rectangle(0f, 0f));
|
||||
formXObject.GetPdfObject().Put(PdfName.Subtype2, PdfName.PS);
|
||||
PdfDictionary charProcs = new PdfDictionary();
|
||||
charProcs.Put(PdfName.A, new PdfStream());
|
||||
charProcs.Put(PdfName.B, formXObject.GetPdfObject());
|
||||
PdfArray differences = new PdfArray();
|
||||
differences.Add(new PdfNumber(41));
|
||||
differences.Add(PdfName.A);
|
||||
differences.Add(new PdfNumber(82));
|
||||
differences.Add(PdfName.B);
|
||||
PdfFont font = CreateFontWithCharProcsAndEncodingDifferences(document, charProcs, differences);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfA2Checker.CheckFontGlyphs
|
||||
(font, null));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.A_FORM_XOBJECT_DICTIONARY_SHALL_NOT_CONTAIN_SUBTYPE2_KEY_WITH_A_VALUE_OF_PS
|
||||
, e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PdfFont CreateFontWithCharProcsAndEncodingDifferences(PdfDocument document, PdfDictionary charProcs
|
||||
, PdfArray differences) {
|
||||
PdfDictionary encoding = new PdfDictionary();
|
||||
encoding.Put(PdfName.Type, PdfName.Encoding);
|
||||
encoding.Put(PdfName.Differences, differences);
|
||||
PdfDictionary fontDictionary = new PdfDictionary();
|
||||
fontDictionary.Put(PdfName.Type, PdfName.Font);
|
||||
fontDictionary.Put(PdfName.Subtype, PdfName.Type3);
|
||||
fontDictionary.Put(PdfName.Encoding, encoding);
|
||||
fontDictionary.Put(PdfName.CharProcs, charProcs);
|
||||
fontDictionary.Put(PdfName.FontMatrix, new PdfArray(new float[] { 0f, 0f, 0f, 0f, 0f, 0f }));
|
||||
fontDictionary.Put(PdfName.Widths, new PdfArray(new float[0]));
|
||||
fontDictionary.MakeIndirect(document);
|
||||
return PdfFontFactory.CreateFont(fontDictionary);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,353 @@
|
||||
/*
|
||||
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.Kernel.Colors;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Pdf.Colorspace;
|
||||
using TSpdf.Kernel.Pdf.Function;
|
||||
using TSpdf.Pdfa.Exceptions;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa.Checker {
|
||||
[NUnit.Framework.Category("UnitTest")]
|
||||
public class PdfA2CheckerTest : ExtendedTSpdfTest {
|
||||
private PdfA2Checker pdfA2Checker = new PdfA2Checker(PdfAConformanceLevel.PDF_A_2B);
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckNameEntryShouldBeUniqueBetweenDefaultAndAdditionalConfigs() {
|
||||
PdfDictionary ocProperties = new PdfDictionary();
|
||||
PdfDictionary d = new PdfDictionary();
|
||||
d.Put(PdfName.Name, new PdfString("CustomName"));
|
||||
PdfArray configs = new PdfArray();
|
||||
PdfDictionary config = new PdfDictionary();
|
||||
config.Put(PdfName.Name, new PdfString("CustomName"));
|
||||
configs.Add(config);
|
||||
ocProperties.Put(PdfName.D, d);
|
||||
ocProperties.Put(PdfName.Configs, configs);
|
||||
PdfDictionary catalog = new PdfDictionary();
|
||||
catalog.Put(PdfName.OCProperties, ocProperties);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfA2Checker.CheckCatalogValidEntries
|
||||
(catalog));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.VALUE_OF_NAME_ENTRY_SHALL_BE_UNIQUE_AMONG_ALL_OPTIONAL_CONTENT_CONFIGURATION_DICTIONARIES
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckNameEntryShouldBeUniqueBetweenAdditionalConfigs() {
|
||||
PdfDictionary ocProperties = new PdfDictionary();
|
||||
PdfDictionary d = new PdfDictionary();
|
||||
d.Put(PdfName.Name, new PdfString("CustomName"));
|
||||
PdfArray configs = new PdfArray();
|
||||
PdfDictionary config = new PdfDictionary();
|
||||
config.Put(PdfName.Name, new PdfString("CustomName1"));
|
||||
configs.Add(config);
|
||||
config = new PdfDictionary();
|
||||
config.Put(PdfName.Name, new PdfString("CustomName1"));
|
||||
configs.Add(config);
|
||||
ocProperties.Put(PdfName.D, d);
|
||||
ocProperties.Put(PdfName.Configs, configs);
|
||||
PdfDictionary catalog = new PdfDictionary();
|
||||
catalog.Put(PdfName.OCProperties, ocProperties);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfA2Checker.CheckCatalogValidEntries
|
||||
(catalog));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.VALUE_OF_NAME_ENTRY_SHALL_BE_UNIQUE_AMONG_ALL_OPTIONAL_CONTENT_CONFIGURATION_DICTIONARIES
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckOCCDContainName() {
|
||||
PdfDictionary ocProperties = new PdfDictionary();
|
||||
PdfDictionary d = new PdfDictionary();
|
||||
PdfArray configs = new PdfArray();
|
||||
PdfDictionary config = new PdfDictionary();
|
||||
config.Put(PdfName.Name, new PdfString("CustomName1"));
|
||||
configs.Add(config);
|
||||
config = new PdfDictionary();
|
||||
config.Put(PdfName.Name, new PdfString("CustomName2"));
|
||||
configs.Add(config);
|
||||
ocProperties.Put(PdfName.D, d);
|
||||
ocProperties.Put(PdfName.Configs, configs);
|
||||
PdfDictionary catalog = new PdfDictionary();
|
||||
catalog.Put(PdfName.OCProperties, ocProperties);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfA2Checker.CheckCatalogValidEntries
|
||||
(catalog));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.OPTIONAL_CONTENT_CONFIGURATION_DICTIONARY_SHALL_CONTAIN_NAME_ENTRY
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckOrderArrayDoesNotContainRedundantReferences() {
|
||||
PdfDictionary ocProperties = new PdfDictionary();
|
||||
PdfDictionary d = new PdfDictionary();
|
||||
d.Put(PdfName.Name, new PdfString("CustomName"));
|
||||
PdfArray configs = new PdfArray();
|
||||
PdfDictionary config = new PdfDictionary();
|
||||
config.Put(PdfName.Name, new PdfString("CustomName1"));
|
||||
PdfArray order = new PdfArray();
|
||||
PdfDictionary orderItem = new PdfDictionary();
|
||||
orderItem.Put(PdfName.Name, new PdfString("CustomName2"));
|
||||
order.Add(orderItem);
|
||||
PdfDictionary orderItem1 = new PdfDictionary();
|
||||
orderItem1.Put(PdfName.Name, new PdfString("CustomName3"));
|
||||
order.Add(orderItem1);
|
||||
config.Put(PdfName.Order, order);
|
||||
PdfArray ocgs = new PdfArray();
|
||||
ocgs.Add(orderItem);
|
||||
ocProperties.Put(PdfName.OCGs, ocgs);
|
||||
configs.Add(config);
|
||||
ocProperties.Put(PdfName.D, d);
|
||||
ocProperties.Put(PdfName.Configs, configs);
|
||||
PdfDictionary catalog = new PdfDictionary();
|
||||
catalog.Put(PdfName.OCProperties, ocProperties);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfA2Checker.CheckCatalogValidEntries
|
||||
(catalog));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.ORDER_ARRAY_SHALL_CONTAIN_REFERENCES_TO_ALL_OCGS,
|
||||
e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckOrderArrayContainsReferencesToAllOCGs() {
|
||||
PdfDictionary ocProperties = new PdfDictionary();
|
||||
PdfDictionary d = new PdfDictionary();
|
||||
d.Put(PdfName.Name, new PdfString("CustomName"));
|
||||
PdfArray configs = new PdfArray();
|
||||
PdfDictionary config = new PdfDictionary();
|
||||
config.Put(PdfName.Name, new PdfString("CustomName1"));
|
||||
PdfArray order = new PdfArray();
|
||||
PdfDictionary orderItem = new PdfDictionary();
|
||||
orderItem.Put(PdfName.Name, new PdfString("CustomName2"));
|
||||
order.Add(orderItem);
|
||||
PdfDictionary orderItem1 = new PdfDictionary();
|
||||
orderItem1.Put(PdfName.Name, new PdfString("CustomName3"));
|
||||
config.Put(PdfName.Order, order);
|
||||
PdfArray ocgs = new PdfArray();
|
||||
ocgs.Add(orderItem);
|
||||
ocgs.Add(orderItem1);
|
||||
ocProperties.Put(PdfName.OCGs, ocgs);
|
||||
configs.Add(config);
|
||||
ocProperties.Put(PdfName.D, d);
|
||||
ocProperties.Put(PdfName.Configs, configs);
|
||||
PdfDictionary catalog = new PdfDictionary();
|
||||
catalog.Put(PdfName.OCProperties, ocProperties);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfA2Checker.CheckCatalogValidEntries
|
||||
(catalog));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.ORDER_ARRAY_SHALL_CONTAIN_REFERENCES_TO_ALL_OCGS,
|
||||
e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckOrderArrayAndOCGsMatch() {
|
||||
PdfDictionary ocProperties = new PdfDictionary();
|
||||
PdfDictionary d = new PdfDictionary();
|
||||
d.Put(PdfName.Name, new PdfString("CustomName"));
|
||||
PdfArray configs = new PdfArray();
|
||||
PdfDictionary config = new PdfDictionary();
|
||||
config.Put(PdfName.Name, new PdfString("CustomName1"));
|
||||
PdfArray order = new PdfArray();
|
||||
PdfDictionary orderItem = new PdfDictionary();
|
||||
orderItem.Put(PdfName.Name, new PdfString("CustomName2"));
|
||||
order.Add(orderItem);
|
||||
PdfDictionary orderItem1 = new PdfDictionary();
|
||||
orderItem1.Put(PdfName.Name, new PdfString("CustomName3"));
|
||||
order.Add(orderItem1);
|
||||
config.Put(PdfName.Order, order);
|
||||
PdfArray ocgs = new PdfArray();
|
||||
PdfDictionary orderItem2 = new PdfDictionary();
|
||||
orderItem2.Put(PdfName.Name, new PdfString("CustomName4"));
|
||||
ocgs.Add(orderItem2);
|
||||
PdfDictionary orderItem3 = new PdfDictionary();
|
||||
orderItem3.Put(PdfName.Name, new PdfString("CustomName5"));
|
||||
ocgs.Add(orderItem3);
|
||||
ocProperties.Put(PdfName.OCGs, ocgs);
|
||||
configs.Add(config);
|
||||
ocProperties.Put(PdfName.D, d);
|
||||
ocProperties.Put(PdfName.Configs, configs);
|
||||
PdfDictionary catalog = new PdfDictionary();
|
||||
catalog.Put(PdfName.OCProperties, ocProperties);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfA2Checker.CheckCatalogValidEntries
|
||||
(catalog));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.ORDER_ARRAY_SHALL_CONTAIN_REFERENCES_TO_ALL_OCGS,
|
||||
e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckAbsenceOfOptionalConfigEntryAllowed() {
|
||||
PdfDictionary ocProperties = new PdfDictionary();
|
||||
PdfDictionary d = new PdfDictionary();
|
||||
d.Put(PdfName.Name, new PdfString("CustomName"));
|
||||
PdfDictionary orderItem = new PdfDictionary();
|
||||
orderItem.Put(PdfName.Name, new PdfString("CustomName2"));
|
||||
PdfArray ocgs = new PdfArray();
|
||||
ocgs.Add(orderItem);
|
||||
ocProperties.Put(PdfName.OCGs, ocgs);
|
||||
ocProperties.Put(PdfName.D, d);
|
||||
PdfDictionary catalog = new PdfDictionary();
|
||||
catalog.Put(PdfName.OCProperties, ocProperties);
|
||||
pdfA2Checker.CheckCatalogValidEntries(catalog);
|
||||
}
|
||||
|
||||
// checkCatalogValidEntries doesn't change the state of any object
|
||||
// and doesn't return any value. The only result is exception which
|
||||
// was or wasn't thrown. Successful scenario is tested here therefore
|
||||
// no assertion is provided
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckAbsenceOfOptionalOrderEntryAllowed() {
|
||||
PdfDictionary ocProperties = new PdfDictionary();
|
||||
PdfDictionary d = new PdfDictionary();
|
||||
d.Put(PdfName.Name, new PdfString("CustomName"));
|
||||
PdfDictionary orderItem = new PdfDictionary();
|
||||
orderItem.Put(PdfName.Name, new PdfString("CustomName2"));
|
||||
PdfArray ocgs = new PdfArray();
|
||||
ocgs.Add(orderItem);
|
||||
PdfArray configs = new PdfArray();
|
||||
PdfDictionary config = new PdfDictionary();
|
||||
config.Put(PdfName.Name, new PdfString("CustomName1"));
|
||||
configs.Add(config);
|
||||
ocProperties.Put(PdfName.OCGs, ocgs);
|
||||
ocProperties.Put(PdfName.D, d);
|
||||
ocProperties.Put(PdfName.Configs, configs);
|
||||
PdfDictionary catalog = new PdfDictionary();
|
||||
catalog.Put(PdfName.OCProperties, ocProperties);
|
||||
pdfA2Checker.CheckCatalogValidEntries(catalog);
|
||||
}
|
||||
|
||||
// checkCatalogValidEntries doesn't change the state of any object
|
||||
// and doesn't return any value. The only result is exception which
|
||||
// was or wasn't thrown. Successful scenario is tested here therefore
|
||||
// no assertion is provided
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckCatalogDictionaryWithoutAlternatePresentations() {
|
||||
PdfDictionary names = new PdfDictionary();
|
||||
names.Put(PdfName.AlternatePresentations, new PdfDictionary());
|
||||
PdfDictionary catalog = new PdfDictionary();
|
||||
catalog.Put(PdfName.Names, names);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfA2Checker.CheckCatalogValidEntries
|
||||
(catalog));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.A_CATALOG_DICTIONARY_SHALL_NOT_CONTAIN_ALTERNATEPRESENTATIONS_NAMES_ENTRY
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckCatalogDictionaryWithoutRequirements() {
|
||||
PdfDictionary catalog = new PdfDictionary();
|
||||
catalog.Put(PdfName.Requirements, new PdfDictionary());
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfA2Checker.CheckCatalogValidEntries
|
||||
(catalog));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.A_CATALOG_DICTIONARY_SHALL_NOT_CONTAIN_REQUIREMENTS_ENTRY
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void DeviceNColorspaceNoAttributesDictionary() {
|
||||
int numberOfComponents = 2;
|
||||
IList<String> tmpArray = new List<String>(numberOfComponents);
|
||||
float[] transformArray = new float[numberOfComponents * 2];
|
||||
for (int i = 0; i < numberOfComponents; i++) {
|
||||
tmpArray.Add("MyColor" + i + 1);
|
||||
transformArray[i * 2] = 0;
|
||||
transformArray[i * 2 + 1] = 1;
|
||||
}
|
||||
PdfFunction.Type4 function = new PdfFunction.Type4(new PdfArray(transformArray), new PdfArray(new float[]
|
||||
{ 0, 1, 0, 1, 0, 1 }), "{0}".GetBytes(TSpdf.Commons.Utils.EncodingUtil.ISO_8859_1));
|
||||
PdfDictionary currentColorSpaces = new PdfDictionary();
|
||||
//TODO DEVSIX-4203 should not cause an IndexOutOfBoundException.
|
||||
// Should throw PdfAConformanceException as Colorants dictionary always must be present
|
||||
// for Pdf/A-2
|
||||
NUnit.Framework.Assert.Catch(typeof(Exception), () => pdfA2Checker.CheckColorSpace(new PdfSpecialCs.DeviceN
|
||||
(tmpArray, new PdfDeviceCs.Rgb(), function), currentColorSpaces, true, false));
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckColorShadingTest() {
|
||||
PdfDictionary patternDict = new PdfDictionary();
|
||||
patternDict.Put(PdfName.ExtGState, new PdfDictionary());
|
||||
PdfPattern.Shading pattern = new PdfPattern.Shading(patternDict);
|
||||
PdfDictionary dictionary = new PdfDictionary();
|
||||
dictionary.Put(PdfName.ColorSpace, PdfName.DeviceCMYK);
|
||||
pattern.SetShading(dictionary);
|
||||
Color color = new PatternColor(pattern);
|
||||
NUnit.Framework.Assert.DoesNotThrow(() => {
|
||||
pdfA2Checker.CheckColor(color, new PdfDictionary(), true, null);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckSignatureTest() {
|
||||
PdfDictionary signatureDict = CreateSignatureDict();
|
||||
pdfA2Checker.CheckSignature(signatureDict);
|
||||
NUnit.Framework.Assert.IsTrue(pdfA2Checker.ObjectIsChecked(signatureDict));
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckSignatureDigestMethodTest() {
|
||||
PdfDictionary signatureDict = CreateSignatureDict();
|
||||
PdfArray types = (PdfArray)signatureDict.Get(PdfName.Reference);
|
||||
PdfDictionary reference = (PdfDictionary)types.Get(0);
|
||||
PdfArray digestMethod = new PdfArray();
|
||||
digestMethod.Add(new PdfName("SHA256"));
|
||||
reference.Put(PdfName.DigestMethod, digestMethod);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfA2Checker.CheckSignature
|
||||
(signatureDict));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.SIGNATURE_REFERENCES_DICTIONARY_SHALL_NOT_CONTAIN_DIGESTLOCATION_DIGESTMETHOD_DIGESTVALUE
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
private static PdfDictionary CreateSignatureDict() {
|
||||
PdfDictionary signatureDict = new PdfDictionary();
|
||||
PdfDictionary reference = new PdfDictionary();
|
||||
PdfDictionary transformParams = new PdfDictionary();
|
||||
transformParams.Put(PdfName.P, new PdfNumber(1));
|
||||
transformParams.Put(PdfName.V, new PdfName("1.2"));
|
||||
transformParams.Put(PdfName.Type, PdfName.TransformParams);
|
||||
reference.Put(PdfName.TransformMethod, PdfName.DocMDP);
|
||||
reference.Put(PdfName.Type, PdfName.SigRef);
|
||||
reference.Put(PdfName.TransformParams, transformParams);
|
||||
PdfArray types = new PdfArray();
|
||||
types.Add(reference);
|
||||
signatureDict.Put(PdfName.Reference, types);
|
||||
return signatureDict;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
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.Geom;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Pdf.Annot;
|
||||
using TSpdf.Kernel.Pdf.Colorspace;
|
||||
using TSpdf.Kernel.Pdf.Xobject;
|
||||
using TSpdf.Pdfa.Exceptions;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa.Checker {
|
||||
[NUnit.Framework.Category("UnitTest")]
|
||||
public class PdfA2CheckerTransparencyTest : ExtendedTSpdfTest {
|
||||
private PdfA2Checker pdfA2Checker;
|
||||
|
||||
[NUnit.Framework.SetUp]
|
||||
public virtual void Before() {
|
||||
pdfA2Checker = new PdfA2Checker(PdfAConformanceLevel.PDF_A_2B);
|
||||
pdfA2Checker.SetFullCheckMode(true);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckPatternWithFormResourceCycle() {
|
||||
using (MemoryStream bos = new MemoryStream()) {
|
||||
using (PdfWriter writer = new PdfWriter(bos)) {
|
||||
using (PdfDocument document = new PdfDocument(writer)) {
|
||||
PdfFormXObject formXObject = new PdfFormXObject(new Rectangle(0f, 0f));
|
||||
formXObject.GetResources().AddForm(formXObject);
|
||||
PdfPattern.Tiling tillingPattern = new PdfPattern.Tiling(0f, 0f);
|
||||
tillingPattern.GetResources().AddForm(formXObject);
|
||||
PdfPage pageToCheck = document.AddNewPage();
|
||||
PdfResources pageResources = pageToCheck.GetResources();
|
||||
pageResources.AddPattern(new PdfPattern.Shading(new PdfDictionary()));
|
||||
pageResources.AddPattern(tillingPattern);
|
||||
EnsureTransparencyObjectsNotEmpty();
|
||||
// no assertions as we want to check that no exceptions would be thrown
|
||||
pdfA2Checker.CheckSinglePage(pageToCheck);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckAppearanceStreamsWithCycle() {
|
||||
using (MemoryStream bos = new MemoryStream()) {
|
||||
using (PdfWriter writer = new PdfWriter(bos)) {
|
||||
using (PdfDocument document = new PdfDocument(writer)) {
|
||||
PdfDictionary normalAppearance = new PdfDictionary();
|
||||
normalAppearance.Put(PdfName.ON, normalAppearance);
|
||||
normalAppearance.MakeIndirect(document);
|
||||
PdfAnnotation annotation = new PdfPopupAnnotation(new Rectangle(0f, 0f));
|
||||
annotation.SetAppearance(PdfName.N, normalAppearance);
|
||||
PdfPage pageToCheck = document.AddNewPage();
|
||||
pageToCheck.AddAnnotation(annotation);
|
||||
EnsureTransparencyObjectsNotEmpty();
|
||||
// no assertions as we want to check that no exceptions would be thrown
|
||||
pdfA2Checker.CheckPageTransparency(pageToCheck.GetPdfObject(), pageToCheck.GetResources().GetPdfObject());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckPatternWithTransparentFormResource() {
|
||||
using (MemoryStream bos = new MemoryStream()) {
|
||||
using (PdfWriter writer = new PdfWriter(bos)) {
|
||||
using (PdfDocument document = new PdfDocument(writer)) {
|
||||
PdfFormXObject formXObject = new PdfFormXObject(new Rectangle(0f, 0f));
|
||||
formXObject.SetGroup(new PdfTransparencyGroup());
|
||||
PdfPattern.Tiling tillingPattern = new PdfPattern.Tiling(0f, 0f);
|
||||
tillingPattern.GetResources().AddForm(formXObject);
|
||||
PdfPage pageToCheck = document.AddNewPage();
|
||||
PdfResources pageResources = pageToCheck.GetResources();
|
||||
pageResources.AddPattern(new PdfPattern.Shading(new PdfDictionary()));
|
||||
pageResources.AddPattern(tillingPattern);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfA2Checker.CheckSinglePage
|
||||
(pageToCheck));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.THE_DOCUMENT_DOES_NOT_CONTAIN_A_PDFA_OUTPUTINTENT_BUT_PAGE_CONTAINS_TRANSPARENCY_AND_DOES_NOT_CONTAIN_BLENDING_COLOR_SPACE
|
||||
, e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckPatternWithoutTransparentFormResource() {
|
||||
using (MemoryStream bos = new MemoryStream()) {
|
||||
using (PdfWriter writer = new PdfWriter(bos)) {
|
||||
using (PdfDocument document = new PdfDocument(writer)) {
|
||||
PdfFormXObject formXObject = new PdfFormXObject(new Rectangle(0f, 0f));
|
||||
PdfPattern.Tiling tillingPattern = new PdfPattern.Tiling(0f, 0f);
|
||||
tillingPattern.GetResources().AddForm(formXObject);
|
||||
PdfPage pageToCheck = document.AddNewPage();
|
||||
PdfResources pageResources = pageToCheck.GetResources();
|
||||
pageResources.AddPattern(new PdfPattern.Shading(new PdfDictionary()));
|
||||
pageResources.AddPattern(tillingPattern);
|
||||
EnsureTransparencyObjectsNotEmpty();
|
||||
// no assertions as we want to check that no exceptions would be thrown
|
||||
pdfA2Checker.CheckSinglePage(pageToCheck);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckAppearanceStreamWithTransparencyGroup() {
|
||||
using (MemoryStream bos = new MemoryStream()) {
|
||||
using (PdfWriter writer = new PdfWriter(bos)) {
|
||||
using (PdfDocument document = new PdfDocument(writer)) {
|
||||
PdfFormXObject formXObject = new PdfFormXObject(new Rectangle(0f, 0f));
|
||||
formXObject.SetGroup(new PdfTransparencyGroup());
|
||||
PdfAnnotation annotation = new PdfPopupAnnotation(new Rectangle(0f, 0f));
|
||||
annotation.SetNormalAppearance(formXObject.GetPdfObject());
|
||||
PdfPage pageToCheck = document.AddNewPage();
|
||||
pageToCheck.AddAnnotation(new PdfPopupAnnotation(new Rectangle(0f, 0f)));
|
||||
pageToCheck.AddAnnotation(annotation);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfA2Checker.CheckSinglePage
|
||||
(pageToCheck));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.THE_DOCUMENT_DOES_NOT_CONTAIN_A_PDFA_OUTPUTINTENT_BUT_PAGE_CONTAINS_TRANSPARENCY_AND_DOES_NOT_CONTAIN_BLENDING_COLOR_SPACE
|
||||
, e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckAppearanceStreamWithTransparencyGroup2() {
|
||||
using (MemoryStream bos = new MemoryStream()) {
|
||||
using (PdfWriter writer = new PdfWriter(bos)) {
|
||||
using (PdfDocument document = new PdfDocument(writer)) {
|
||||
PdfFormXObject formXObject = new PdfFormXObject(new Rectangle(0f, 0f));
|
||||
formXObject.SetGroup(new PdfTransparencyGroup());
|
||||
PdfFormXObject formStream = new PdfFormXObject(new Rectangle(0f, 0f));
|
||||
formStream.GetResources().AddForm(formXObject);
|
||||
PdfAnnotation annotation = new PdfPopupAnnotation(new Rectangle(0f, 0f));
|
||||
annotation.SetNormalAppearance(formStream.GetPdfObject());
|
||||
PdfPage pageToCheck = document.AddNewPage();
|
||||
pageToCheck.AddAnnotation(new PdfPopupAnnotation(new Rectangle(0f, 0f)));
|
||||
pageToCheck.AddAnnotation(annotation);
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfA2Checker.CheckSinglePage
|
||||
(pageToCheck));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.THE_DOCUMENT_DOES_NOT_CONTAIN_A_PDFA_OUTPUTINTENT_BUT_PAGE_CONTAINS_TRANSPARENCY_AND_DOES_NOT_CONTAIN_BLENDING_COLOR_SPACE
|
||||
, e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckAppearanceStreamWithoutTransparencyGroup() {
|
||||
using (MemoryStream bos = new MemoryStream()) {
|
||||
using (PdfWriter writer = new PdfWriter(bos)) {
|
||||
using (PdfDocument document = new PdfDocument(writer)) {
|
||||
PdfFormXObject formXObject = new PdfFormXObject(new Rectangle(0f, 0f));
|
||||
PdfAnnotation annotation = new PdfPopupAnnotation(new Rectangle(0f, 0f));
|
||||
annotation.SetNormalAppearance(formXObject.GetPdfObject());
|
||||
PdfPage pageToCheck = document.AddNewPage();
|
||||
pageToCheck.AddAnnotation(new PdfPopupAnnotation(new Rectangle(0f, 0f)));
|
||||
pageToCheck.AddAnnotation(annotation);
|
||||
EnsureTransparencyObjectsNotEmpty();
|
||||
// no assertions as we want to check that no exceptions would be thrown
|
||||
pdfA2Checker.CheckSinglePage(pageToCheck);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureTransparencyObjectsNotEmpty() {
|
||||
PdfFormXObject formXObject = new PdfFormXObject(new Rectangle(0f, 0f));
|
||||
formXObject.SetGroup(new PdfTransparencyGroup());
|
||||
pdfA2Checker.CheckFormXObject(formXObject.GetPdfObject());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
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.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Pdf.Colorspace;
|
||||
using TSpdf.Kernel.Pdf.Function;
|
||||
using TSpdf.Pdfa.Exceptions;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa.Checker {
|
||||
[NUnit.Framework.Category("UnitTest")]
|
||||
public class PdfA2ImplementationLimitsCheckerTest : ExtendedTSpdfTest {
|
||||
private PdfA2Checker pdfA2Checker = new PdfA2Checker(PdfAConformanceLevel.PDF_A_2B);
|
||||
|
||||
[NUnit.Framework.SetUp]
|
||||
public virtual void Before() {
|
||||
pdfA2Checker.SetFullCheckMode(true);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void IndependentLongStringTest() {
|
||||
int maxAllowedLength = pdfA2Checker.GetMaxStringLength();
|
||||
int testLength = maxAllowedLength + 1;
|
||||
NUnit.Framework.Assert.AreEqual(testLength, 32768);
|
||||
PdfString longString = PdfACheckerTestUtils.GetLongString(testLength);
|
||||
// An exception should be thrown as provided String is longer then
|
||||
// it is allowed per specification
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfA2Checker.CheckPdfObject
|
||||
(longString));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.PDF_STRING_IS_TOO_LONG, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void LongStringInContentStreamTest() {
|
||||
pdfA2Checker.SetFullCheckMode(true);
|
||||
int maxAllowedLength = pdfA2Checker.GetMaxStringLength();
|
||||
int testLength = maxAllowedLength + 1;
|
||||
NUnit.Framework.Assert.AreEqual(testLength, 32768);
|
||||
PdfString longString = PdfACheckerTestUtils.GetLongString(testLength);
|
||||
String newContentString = PdfACheckerTestUtils.GetStreamWithValue(longString);
|
||||
byte[] newContent = newContentString.GetBytes(System.Text.Encoding.UTF8);
|
||||
PdfStream stream = new PdfStream(newContent);
|
||||
// An exception should be thrown as content stream has a string which
|
||||
// is longer then it is allowed per specification
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfA2Checker.CheckContentStream
|
||||
(stream));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.PDF_STRING_IS_TOO_LONG, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void ArrayCapacityHasNoLimitsTest() {
|
||||
PdfArray longArray = PdfACheckerTestUtils.GetLongArray(999999);
|
||||
// An exception should not be thrown as there is no limits for capacity of an array
|
||||
// in PDFA 2
|
||||
pdfA2Checker.CheckPdfObject(longArray);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void DictionaryCapacityHasNoLimitsTest() {
|
||||
// Using 9999 dictionary pairs which is more than pdfA1 4095 limit (see PDF/A 4.3.2 Limits)
|
||||
PdfDictionary longDictionary = PdfACheckerTestUtils.GetLongDictionary(9999);
|
||||
// An exception should not be thrown as there is no limits for capacity of a dictionary
|
||||
// in PDFA 2
|
||||
pdfA2Checker.CheckPdfObject(longDictionary);
|
||||
// Using 9999 dictionary pairs which is more than pdfA1 4095 limit (see PDF/A 4.3.2 Limits)
|
||||
PdfStream longStream = PdfACheckerTestUtils.GetStreamWithLongDictionary(9999);
|
||||
// An exception should not be thrown as there is no limits for capacity of a dictionary
|
||||
// and stream in PDFA 2
|
||||
pdfA2Checker.CheckPdfObject(longStream);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void IndependentLargeRealTest() {
|
||||
PdfNumber largeNumber = new PdfNumber(pdfA2Checker.GetMaxRealValue());
|
||||
// TODO DEVSIX-4182
|
||||
// An exception is thrown as any number greater then 32767 is considered as Integer
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => pdfA2Checker.CheckPdfObject
|
||||
(largeNumber));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.INTEGER_NUMBER_IS_OUT_OF_RANGE, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void DeviceNColorspaceWithMoreThan32Components() {
|
||||
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfAConformanceException), () => CheckColorspace(BuildDeviceNColorspace
|
||||
(34)));
|
||||
NUnit.Framework.Assert.AreEqual(PdfAConformanceException.THE_NUMBER_OF_COLOR_COMPONENTS_IN_DEVICE_N_COLORSPACE_SHOULD_NOT_EXCEED
|
||||
, e.Message);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void DeviceNColorspaceWithLessThan32Components() {
|
||||
CheckColorspace(BuildDeviceNColorspace(16));
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void DeviceNColorspaceWith32Components() {
|
||||
CheckColorspace(BuildDeviceNColorspace(32));
|
||||
}
|
||||
|
||||
private void CheckColorspace(PdfColorSpace colorSpace) {
|
||||
PdfDictionary currentColorSpaces = new PdfDictionary();
|
||||
pdfA2Checker.CheckColorSpace(colorSpace, currentColorSpaces, true, false);
|
||||
}
|
||||
|
||||
private PdfColorSpace BuildDeviceNColorspace(int numberOfComponents) {
|
||||
IList<String> tmpArray = new List<String>(numberOfComponents);
|
||||
float[] transformArray = new float[numberOfComponents * 2];
|
||||
for (int i = 0; i < numberOfComponents; i++) {
|
||||
tmpArray.Add("MyColor" + i + 1);
|
||||
transformArray[i * 2] = 0;
|
||||
transformArray[i * 2 + 1] = 1;
|
||||
}
|
||||
PdfFunction.Type4 function = new PdfFunction.Type4(new PdfArray(transformArray), new PdfArray(new float[]
|
||||
{ 0, 1, 0, 1, 0, 1 }), "{0}".GetBytes(TSpdf.Commons.Utils.EncodingUtil.ISO_8859_1));
|
||||
//TODO DEVSIX-4205 Replace with a constructor with 4 parameters or use a setter for attributes dictionary
|
||||
PdfArray deviceNAsArray = ((PdfArray)(new PdfSpecialCs.DeviceN(tmpArray, new PdfDeviceCs.Rgb(), function))
|
||||
.GetPdfObject());
|
||||
PdfDictionary attributes = new PdfDictionary();
|
||||
deviceNAsArray.Add(attributes);
|
||||
return new PdfSpecialCs.DeviceN(deviceNAsArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
/*
|
||||
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.Collections.Generic;
|
||||
using System.IO;
|
||||
using TSpdf.Kernel.Colors;
|
||||
using TSpdf.Kernel.Font;
|
||||
using TSpdf.Kernel.Geom;
|
||||
using TSpdf.Kernel.Pdf;
|
||||
using TSpdf.Kernel.Pdf.Annot;
|
||||
using TSpdf.Kernel.Pdf.Canvas;
|
||||
using TSpdf.Kernel.Pdf.Colorspace;
|
||||
using TSpdf.Test;
|
||||
|
||||
namespace TSpdf.Pdfa.Checker {
|
||||
[NUnit.Framework.Category("UnitTest")]
|
||||
public class PdfACheckerTest : ExtendedTSpdfTest {
|
||||
private PdfAChecker pdfAChecker;
|
||||
|
||||
[NUnit.Framework.SetUp]
|
||||
public virtual void Before() {
|
||||
pdfAChecker = new PdfACheckerTest.EmptyPdfAChecker();
|
||||
pdfAChecker.SetFullCheckMode(true);
|
||||
}
|
||||
|
||||
[NUnit.Framework.Test]
|
||||
public virtual void CheckAppearanceStreamsWithCycle() {
|
||||
using (MemoryStream bos = new MemoryStream()) {
|
||||
using (PdfWriter writer = new PdfWriter(bos)) {
|
||||
using (PdfDocument document = new PdfDocument(writer)) {
|
||||
PdfDictionary normalAppearance = new PdfDictionary();
|
||||
normalAppearance.Put(PdfName.ON, normalAppearance);
|
||||
normalAppearance.MakeIndirect(document);
|
||||
PdfAnnotation annotation = new PdfPopupAnnotation(new Rectangle(0f, 0f));
|
||||
annotation.SetAppearance(PdfName.N, normalAppearance);
|
||||
PdfPage pageToCheck = document.AddNewPage();
|
||||
pageToCheck.AddAnnotation(annotation);
|
||||
// no assertions as we want to check that no exceptions would be thrown
|
||||
pdfAChecker.CheckResourcesOfAppearanceStreams(annotation.GetAppearanceDictionary());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class EmptyPdfAChecker : PdfAChecker {
|
||||
protected internal EmptyPdfAChecker()
|
||||
: base(null) {
|
||||
}
|
||||
|
||||
public override void CheckCanvasStack(char stackOperation) {
|
||||
}
|
||||
|
||||
public override void CheckInlineImage(PdfStream inlineImage, PdfDictionary currentColorSpaces) {
|
||||
}
|
||||
|
||||
public override void CheckColor(Color color, PdfDictionary currentColorSpaces, bool? fill, PdfStream contentStream
|
||||
) {
|
||||
}
|
||||
|
||||
public override void CheckColorSpace(PdfColorSpace colorSpace, PdfDictionary currentColorSpaces, bool checkAlternate
|
||||
, bool? fill) {
|
||||
}
|
||||
|
||||
public override void CheckRenderingIntent(PdfName intent) {
|
||||
}
|
||||
|
||||
public override void CheckFontGlyphs(PdfFont font, PdfStream contentStream) {
|
||||
}
|
||||
|
||||
public override void CheckExtGState(CanvasGraphicsState extGState, PdfStream contentStream) {
|
||||
}
|
||||
|
||||
public override void CheckFont(PdfFont pdfFont) {
|
||||
}
|
||||
|
||||
public override void CheckXrefTable(PdfXrefTable xrefTable) {
|
||||
}
|
||||
|
||||
protected internal override void CheckContentStream(PdfStream contentStream) {
|
||||
}
|
||||
|
||||
protected internal override void CheckContentStreamObject(PdfObject @object) {
|
||||
}
|
||||
|
||||
protected internal override long GetMaxNumberOfIndirectObjects() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected internal override ICollection<PdfName> GetForbiddenActions() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected internal override ICollection<PdfName> GetAllowedNamedActions() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected internal override void CheckAction(PdfDictionary action) {
|
||||
}
|
||||
|
||||
protected internal override void CheckAnnotation(PdfDictionary annotDic) {
|
||||
}
|
||||
|
||||
protected internal override void CheckCatalogValidEntries(PdfDictionary catalogDict) {
|
||||
}
|
||||
|
||||
protected internal override void CheckColorsUsages() {
|
||||
}
|
||||
|
||||
protected internal override void CheckImage(PdfStream image, PdfDictionary currentColorSpaces) {
|
||||
}
|
||||
|
||||
protected internal override void CheckFileSpec(PdfDictionary fileSpec) {
|
||||
}
|
||||
|
||||
protected internal override void CheckForm(PdfDictionary form) {
|
||||
}
|
||||
|
||||
protected internal override void CheckFormXObject(PdfStream form) {
|
||||
}
|
||||
|
||||
protected internal override void CheckLogicalStructure(PdfDictionary catalog) {
|
||||
}
|
||||
|
||||
protected internal override void CheckMetaData(PdfDictionary catalog) {
|
||||
}
|
||||
|
||||
protected internal override void CheckNonSymbolicTrueTypeFont(PdfTrueTypeFont trueTypeFont) {
|
||||
}
|
||||
|
||||
protected internal override void CheckOutputIntents(PdfDictionary catalog) {
|
||||
}
|
||||
|
||||
protected internal override void CheckPageObject(PdfDictionary page, PdfDictionary pageResources) {
|
||||
}
|
||||
|
||||
protected internal override void CheckPageSize(PdfDictionary page) {
|
||||
}
|
||||
|
||||
protected internal override void CheckPdfArray(PdfArray array) {
|
||||
}
|
||||
|
||||
protected internal override void CheckPdfDictionary(PdfDictionary dictionary) {
|
||||
}
|
||||
|
||||
protected internal override void CheckPdfName(PdfName name) {
|
||||
}
|
||||
|
||||
protected internal override void CheckPdfNumber(PdfNumber number) {
|
||||
}
|
||||
|
||||
protected internal override void CheckPdfStream(PdfStream stream) {
|
||||
}
|
||||
|
||||
protected internal override void CheckPdfString(PdfString @string) {
|
||||
}
|
||||
|
||||
protected internal override void CheckSymbolicTrueTypeFont(PdfTrueTypeFont trueTypeFont) {
|
||||
}
|
||||
|
||||
protected internal override void CheckTrailer(PdfDictionary trailer) {
|
||||
}
|
||||
|
||||
protected internal override void CheckPageTransparency(PdfDictionary pageDict, PdfDictionary pageResources
|
||||
) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
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;
|
||||
|
||||
namespace TSpdf.Pdfa.Checker {
|
||||
public class PdfACheckerTestUtils {
|
||||
private PdfACheckerTestUtils() {
|
||||
}
|
||||
|
||||
internal static PdfString GetLongString(int length) {
|
||||
return new PdfString(GetLongPlainString(length));
|
||||
}
|
||||
|
||||
internal static PdfName GetLongName(int length) {
|
||||
return new PdfName(GetLongPlainString(length));
|
||||
}
|
||||
|
||||
internal static PdfArray GetLongArray(int length) {
|
||||
PdfArray array = new PdfArray();
|
||||
for (int i = 0; i < length; i++) {
|
||||
array.Add(new PdfNumber(i));
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
internal static PdfDictionary GetLongDictionary(int length) {
|
||||
PdfDictionary dict = new PdfDictionary();
|
||||
for (int i = 0; i < length; i++) {
|
||||
dict.Put(new PdfName("value #" + i), new PdfNumber(i));
|
||||
}
|
||||
return dict;
|
||||
}
|
||||
|
||||
internal static PdfStream GetStreamWithLongDictionary(int length) {
|
||||
PdfStream stream = new PdfStream("Hello, world!".GetBytes());
|
||||
for (int i = 0; i < length; i++) {
|
||||
stream.Put(new PdfName("value #" + i), new PdfNumber(i));
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
internal static String GetStreamWithValue(PdfObject @object) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
PdfOutputStream stream = new PdfOutputStream(baos);
|
||||
stream.Write(@object);
|
||||
return "q\n" + "BT\n" + "/F1 12 Tf\n" + "36 787.96 Td\n" + TSpdf.Commons.Utils.JavaUtil.GetStringForBytes(
|
||||
baos.ToArray()) + " Tj\n" + "ET\n" + "Q";
|
||||
}
|
||||
|
||||
private static String GetLongPlainString(int length) {
|
||||
char charToFill = 'A';
|
||||
char[] array = new char[length];
|
||||
for (int i = 0; i < array.Length; i++) {
|
||||
array[i] = charToFill;
|
||||
}
|
||||
return new String(array);
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
TSpdf.tests/TSpdf.pdfa.tests/resources/TSpdf/pdfa/Desert.jpg
Normal file
BIN
TSpdf.tests/TSpdf.pdfa.tests/resources/TSpdf/pdfa/Desert.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 826 KiB |
BIN
TSpdf.tests/TSpdf.pdfa.tests/resources/TSpdf/pdfa/FreeSans.ttf
Normal file
BIN
TSpdf.tests/TSpdf.pdfa.tests/resources/TSpdf/pdfa/FreeSans.ttf
Normal file
Binary file not shown.
Binary file not shown.
BIN
TSpdf.tests/TSpdf.pdfa.tests/resources/TSpdf/pdfa/Puritan2.otf
Normal file
BIN
TSpdf.tests/TSpdf.pdfa.tests/resources/TSpdf/pdfa/Puritan2.otf
Normal file
Binary file not shown.
BIN
TSpdf.tests/TSpdf.pdfa.tests/resources/TSpdf/pdfa/Symbols1.ttf
Normal file
BIN
TSpdf.tests/TSpdf.pdfa.tests/resources/TSpdf/pdfa/Symbols1.ttf
Normal file
Binary file not shown.
BIN
TSpdf.tests/TSpdf.pdfa.tests/resources/TSpdf/pdfa/TSpdf.png
Normal file
BIN
TSpdf.tests/TSpdf.pdfa.tests/resources/TSpdf/pdfa/TSpdf.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user