Skip to content

Commit

Permalink
Update autoported files
Browse files Browse the repository at this point in the history
08c9751af64006347662b2d00e2b0fa74fdf4f72
  • Loading branch information
iText-CI committed Dec 9, 2023
1 parent bcb61de commit 902c335
Show file tree
Hide file tree
Showing 33 changed files with 1,147 additions and 0 deletions.
542 changes: 542 additions & 0 deletions itext.tests/itext.pdfua.tests/itext/pdfua/PdfUACanvasTest.cs

Large diffs are not rendered by default.

108 changes: 108 additions & 0 deletions itext.tests/itext.pdfua.tests/itext/pdfua/PdfUALayoutTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2023 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://itextpdf.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 iText.IO.Font;
using iText.Kernel.Colors;
using iText.Kernel.Font;
using iText.Kernel.Geom;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Canvas;
using iText.Kernel.Utils;
using iText.Layout;
using iText.Layout.Borders;
using iText.Layout.Element;
using iText.Test;
using iText.Test.Pdfa;

namespace iText.Pdfua {
[NUnit.Framework.Category("IntegrationTest")]
public class PdfUALayoutTest : ExtendedITextTest {
private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/itext/pdfua/PdfUALayoutTest/";

private static readonly String SOURCE_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/itext/pdfua/PdfUALayoutTest/";

private static readonly String FONT = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/itext/pdfua/font/FreeSans.ttf";

[NUnit.Framework.OneTimeSetUp]
public static void Before() {
CreateOrClearDestinationFolder(DESTINATION_FOLDER);
}

[NUnit.Framework.Test]
public virtual void SimpleParagraphTest() {
String outPdf = DESTINATION_FOLDER + "simpleParagraphTest.pdf";
String cmpPdf = SOURCE_FOLDER + "cmp_simpleParagraphTest.pdf";
PdfUATestPdfDocument pdfDoc = new PdfUATestPdfDocument(new PdfWriter(outPdf, PdfUATestPdfDocument.CreateWriterProperties
()));
PdfFont font = PdfFontFactory.CreateFont(FONT, PdfEncodings.WINANSI, PdfFontFactory.EmbeddingStrategy.FORCE_EMBEDDED
);
Document doc = new Document(pdfDoc);
doc.Add(new Paragraph("Simple layout PDF/UA-1 test").SetFont(font));
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, DESTINATION_FOLDER, "diff_"
));
NUnit.Framework.Assert.IsNull(new UAVeraPdfValidator().Validate(outPdf));
}

// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf/ua validation on Android)
[NUnit.Framework.Test]
public virtual void SimpleBorderTest() {
String outPdf = DESTINATION_FOLDER + "simpleBorderTest.pdf";
String cmpPdf = SOURCE_FOLDER + "cmp_simpleBorderTest.pdf";
using (PdfDocument pdfDocument = new PdfUATestPdfDocument(new PdfWriter(outPdf, PdfUATestPdfDocument.CreateWriterProperties
()))) {
PdfPage page = pdfDocument.AddNewPage();
PdfCanvas canvas = new PdfCanvas(page);
canvas.OpenTag(new CanvasTag(PdfName.Artifact));
new DottedBorder(DeviceRgb.GREEN, 5).Draw(canvas, new Rectangle(350, 700, 100, 100));
canvas.CloseTag();
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, DESTINATION_FOLDER, "diff"
));
NUnit.Framework.Assert.IsNull(new UAVeraPdfValidator().Validate(outPdf));
}

// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf/ua validation on Android)
[NUnit.Framework.Test]
public virtual void SimpleTableTest() {
String outPdf = DESTINATION_FOLDER + "simpleTableTest.pdf";
String cmpPdf = SOURCE_FOLDER + "cmp_simpleTableTest.pdf";
PdfDocument pdfDoc = new PdfUATestPdfDocument(new PdfWriter(outPdf, PdfUATestPdfDocument.CreateWriterProperties
()));
Document doc = new Document(pdfDoc);
PdfFont font = PdfFontFactory.CreateFont(FONT, PdfEncodings.WINANSI, PdfFontFactory.EmbeddingStrategy.FORCE_EMBEDDED
);
Table table = new Table(new float[] { 50, 50 }).AddCell(new Cell().Add(new Paragraph("cell 1, 1").SetFont(
font))).AddCell(new Cell().Add(new Paragraph("cell 1, 2").SetFont(font)));
doc.Add(table);
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, DESTINATION_FOLDER, "diff_"
));
NUnit.Framework.Assert.IsNull(new UAVeraPdfValidator().Validate(outPdf));
}
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf/ua validation on Android)
}
}
155 changes: 155 additions & 0 deletions itext.tests/itext.pdfua.tests/itext/pdfua/PdfUATest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2023 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://itextpdf.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 iText.IO.Font;
using iText.IO.Image;
using iText.Kernel.Font;
using iText.Kernel.Geom;
using iText.Kernel.Pdf;
using iText.Kernel.Utils;
using iText.Layout;
using iText.Layout.Element;
using iText.Pdfua.Exceptions;
using iText.Test;
using iText.Test.Pdfa;

namespace iText.Pdfua {
[NUnit.Framework.Category("IntegrationTest")]
public class PdfUATest : ExtendedITextTest {
private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/itext/pdfua/PdfUATest/";

private static readonly String SOURCE_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/itext/pdfua/PdfUATest/";

private static readonly String DOG = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/itext/pdfua/img/DOG.bmp";

private static readonly String FONT = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/itext/pdfua/font/FreeSans.ttf";

private static readonly String FOX = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/itext/pdfua/img/FOX.bmp";

[NUnit.Framework.OneTimeSetUp]
public static void Before() {
CreateOrClearDestinationFolder(DESTINATION_FOLDER);
}

[NUnit.Framework.Test]
public virtual void CheckPoint01_007_suspectsHasEntryTrue() {
PdfUATestPdfDocument pdfDoc = new PdfUATestPdfDocument(new PdfWriter(new MemoryStream(), PdfUATestPdfDocument
.CreateWriterProperties()));
PdfDictionary markInfo = (PdfDictionary)pdfDoc.GetCatalog().GetPdfObject().Get(PdfName.MarkInfo);
NUnit.Framework.Assert.IsNotNull(markInfo);
markInfo.Put(PdfName.Suspects, new PdfBoolean(true));
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfUAConformanceException), () => pdfDoc.Close());
NUnit.Framework.Assert.AreEqual(PdfUAExceptionMessageConstants.SUSPECTS_ENTRY_IN_MARK_INFO_DICTIONARY_SHALL_NOT_HAVE_A_VALUE_OF_TRUE
, e.Message);
}

[NUnit.Framework.Test]
public virtual void CheckPoint01_007_suspectsHasEntryFalse() {
PdfUATestPdfDocument pdfDoc = new PdfUATestPdfDocument(new PdfWriter(new MemoryStream(), PdfUATestPdfDocument
.CreateWriterProperties()));
PdfDictionary markInfo = (PdfDictionary)pdfDoc.GetCatalog().GetPdfObject().Get(PdfName.MarkInfo);
markInfo.Put(PdfName.Suspects, new PdfBoolean(false));
NUnit.Framework.Assert.DoesNotThrow(() => pdfDoc.Close());
}

[NUnit.Framework.Test]
public virtual void CheckPoint01_007_suspectsHasNoEntry() {
// suspects entry is optional so it is ok to not have it according to the spec
PdfUATestPdfDocument pdfDoc = new PdfUATestPdfDocument(new PdfWriter(new MemoryStream(), PdfUATestPdfDocument
.CreateWriterProperties()));
NUnit.Framework.Assert.DoesNotThrow(() => pdfDoc.Close());
}

[NUnit.Framework.Test]
public virtual void EmptyPageDocument() {
String outPdf = DESTINATION_FOLDER + "emptyPageDocument.pdf";
using (PdfDocument pdfDocument = new PdfUATestPdfDocument(new PdfWriter(outPdf, PdfUATestPdfDocument.CreateWriterProperties
()))) {
pdfDocument.AddNewPage();
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, SOURCE_FOLDER + "cmp_emptyPageDocument.pdf"
, DESTINATION_FOLDER, "diff_"));
NUnit.Framework.Assert.IsNull(new UAVeraPdfValidator().Validate(outPdf));
}

// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf/ua validation on Android)
[NUnit.Framework.Test]
public virtual void ManualPdfUaCreation() {
String outPdf = DESTINATION_FOLDER + "manualPdfUaCreation.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outPdf, new WriterProperties().AddUAXmpMetadata().SetPdfVersion
(PdfVersion.PDF_1_7)));
Document document = new Document(pdfDoc, PageSize.A4.Rotate());
//TAGGED PDF
//Make document tagged
pdfDoc.SetTagged();
//PDF/UA
//Set document metadata
pdfDoc.GetCatalog().SetViewerPreferences(new PdfViewerPreferences().SetDisplayDocTitle(true));
pdfDoc.GetCatalog().SetLang(new PdfString("en-US"));
PdfDocumentInfo info = pdfDoc.GetDocumentInfo();
info.SetTitle("English pangram");
Paragraph p = new Paragraph();
//PDF/UA
//Embed font
PdfFont font = PdfFontFactory.CreateFont(FONT, PdfEncodings.WINANSI, PdfFontFactory.EmbeddingStrategy.PREFER_EMBEDDED
);
p.SetFont(font);
p.Add("The quick brown ");
iText.Layout.Element.Image img = new Image(ImageDataFactory.Create(FOX));
//PDF/UA
//Set alt text
img.GetAccessibilityProperties().SetAlternateDescription("Fox");
p.Add(img);
p.Add(" jumps over the lazy ");
img = new iText.Layout.Element.Image(ImageDataFactory.Create(DOG));
//PDF/UA
//Set alt text
img.GetAccessibilityProperties().SetAlternateDescription("Dog");
p.Add(img);
document.Add(p);
p = new Paragraph("\n\n\n\n\n\n\n\n\n\n\n\n").SetFont(font).SetFontSize(20);
document.Add(p);
List list = new List().SetFont(font).SetFontSize(20);
list.Add(new ListItem("quick"));
list.Add(new ListItem("brown"));
list.Add(new ListItem("fox"));
list.Add(new ListItem("jumps"));
list.Add(new ListItem("over"));
list.Add(new ListItem("the"));
list.Add(new ListItem("lazy"));
list.Add(new ListItem("dog"));
document.Add(list);
document.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, SOURCE_FOLDER + "cmp_manualPdfUaCreation.pdf"
, DESTINATION_FOLDER, "diff_"));
NUnit.Framework.Assert.IsNull(new UAVeraPdfValidator().Validate(outPdf));
}
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf/ua validation on Android)
}
}
81 changes: 81 additions & 0 deletions itext.tests/itext.pdfua.tests/itext/pdfua/PdfUATestPdfDocument.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2023 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://itextpdf.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 iText.Kernel.Pdf;
using iText.Kernel.Utils;
using iText.Pdfua.Checkers;

namespace iText.Pdfua {
/// <summary>PdfDocument extension for testing purposes.</summary>
public class PdfUATestPdfDocument : PdfDocument {
private readonly IConformanceLevel conformanceLevel = PdfUAConformanceLevel.PDFUA_1;

public PdfUATestPdfDocument(PdfReader reader)
: this(reader, new DocumentProperties()) {
}

public PdfUATestPdfDocument(PdfReader reader, DocumentProperties properties)
: base(reader, properties) {
SetupUAConfiguration();
}

public PdfUATestPdfDocument(PdfWriter writer)
: this(writer, new DocumentProperties()) {
}

public PdfUATestPdfDocument(PdfWriter writer, DocumentProperties properties)
: base(writer, properties) {
SetupUAConfiguration();
}

public PdfUATestPdfDocument(PdfReader reader, PdfWriter writer)
: base(reader, writer) {
SetupUAConfiguration();
}

public static WriterProperties CreateWriterProperties() {
return new WriterProperties().AddUAXmpMetadata();
}

public PdfUATestPdfDocument(PdfReader reader, PdfWriter writer, StampingProperties properties)
: base(reader, writer, properties) {
}

/// <summary>{inheritDoc}</summary>
public override IConformanceLevel GetConformanceLevel() {
return conformanceLevel;
}

private void SetupUAConfiguration() {
//basic configuration
this.SetTagged();
this.GetCatalog().SetViewerPreferences(new PdfViewerPreferences().SetDisplayDocTitle(true));
this.GetCatalog().SetLang(new PdfString("en-US"));
PdfDocumentInfo info = this.GetDocumentInfo();
info.SetTitle("English pangram");
//validation
ValidationContainer validationContainer = new ValidationContainer();
validationContainer.AddChecker(new PdfUA1Checker(this));
this.GetDiContainer().Register(typeof(ValidationContainer), validationContainer);
}
}
}
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.
Loading

0 comments on commit 902c335

Please sign in to comment.