Skip to content

Commit

Permalink
[RELEASE] iText pdfHtml 5.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
iText-CI committed Apr 18, 2024
2 parents b0ccede + 57f0d23 commit 21ea8f9
Show file tree
Hide file tree
Showing 182 changed files with 3,821 additions and 95 deletions.
2 changes: 1 addition & 1 deletion doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ DOXYFILE_ENCODING = UTF-8
# title of most generated pages and in a few other places.
# The default value is: My Project.

PROJECT_NAME = "pdfHTML 5.0.3 API"
PROJECT_NAME = "pdfHTML 5.0.4 API"

# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
# could be handy for archiving the generated documentation or if some version
Expand Down
6 changes: 3 additions & 3 deletions itext.tests/itext.html2pdf.tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

[assembly: Guid("ae4e5743-0665-4705-9a33-07ea57cdd269")]

[assembly: AssemblyVersion("5.0.3.0")]
[assembly: AssemblyFileVersion("5.0.3.0")]
[assembly: AssemblyInformationalVersion("5.0.3")]
[assembly: AssemblyVersion("5.0.4.0")]
[assembly: AssemblyFileVersion("5.0.4.0")]
[assembly: AssemblyInformationalVersion("5.0.4")]

#if !NETSTANDARD2_0
[assembly: NUnit.Framework.Timeout(300000)]
Expand Down
8 changes: 4 additions & 4 deletions itext.tests/itext.html2pdf.tests/itext.html2pdf.tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\itextcore\itext\itext.io\itext.io.csproj" Condition="Exists('..\..\..\itextcore\itext\itext.io\itext.io.csproj')" />
<PackageReference Include="itext" Version="8.0.3" Condition="!Exists('..\..\..\itextcore\itext\itext.io\itext.io.csproj')" />
<PackageReference Include="itext" Version="8.0.4" Condition="!Exists('..\..\..\itextcore\itext\itext.io\itext.io.csproj')" />
<ProjectReference Include="..\..\..\itextcore\itext\itext.kernel\itext.kernel.csproj" Condition="Exists('..\..\..\itextcore\itext\itext.kernel\itext.kernel.csproj')" />
<ProjectReference Include="..\..\..\itextcore\itext\itext.layout\itext.layout.csproj" Condition="Exists('..\..\..\itextcore\itext\itext.layout\itext.layout.csproj')" />
<ProjectReference Include="..\..\..\itextcore\itext\itext.forms\itext.forms.csproj" Condition="Exists('..\..\..\itextcore\itext\itext.forms\itext.forms.csproj')" />
<ProjectReference Include="..\..\..\itextcore\itext\itext.pdfa\itext.pdfa.csproj" Condition="Exists('..\..\..\itextcore\itext\itext.pdfa\itext.pdfa.csproj')" />
<ProjectReference Include="..\..\..\itextcore\itext\itext.hyph\itext.hyph.csproj" Condition="Exists('..\..\..\itextcore\itext\itext.hyph\itext.hyph.csproj')" />
<PackageReference Include="itext.hyph" Version="8.0.3" Condition="!Exists('..\..\..\itextcore\itext\itext.hyph\itext.hyph.csproj')" />
<PackageReference Include="itext.hyph" Version="8.0.4" Condition="!Exists('..\..\..\itextcore\itext\itext.hyph\itext.hyph.csproj')" />
<ProjectReference Include="..\..\..\itextcore\itext\itext.pdftest\itext.pdftest.csproj" Condition="Exists('..\..\..\itextcore\itext\itext.pdftest\itext.pdftest.csproj')" />
<PackageReference Include="itext.pdftest" Version="8.0.3" Condition="!Exists('..\..\..\itextcore\itext\itext.pdftest\itext.pdftest.csproj')" />
<PackageReference Include="itext.pdftest" Version="8.0.4" Condition="!Exists('..\..\..\itextcore\itext\itext.pdftest\itext.pdftest.csproj')" />
<ProjectReference Include="..\..\..\itextcore\itext\itext.bouncy-castle-adapter\itext.bouncy-castle-adapter.csproj" Condition="Exists('..\..\..\itextcore\itext\itext.bouncy-castle-adapter\itext.bouncy-castle-adapter.csproj')" />
<PackageReference Include="itext.bouncy-castle-adapter" Version="8.0.3" Condition="!Exists('..\..\..\itextcore\itext\itext.bouncy-castle-adapter\itext.bouncy-castle-adapter.csproj')" />
<PackageReference Include="itext.bouncy-castle-adapter" Version="8.0.4" Condition="!Exists('..\..\..\itextcore\itext\itext.bouncy-castle-adapter\itext.bouncy-castle-adapter.csproj')" />
<ProjectReference Include="..\..\..\itextcore\itext\itext.styledxmlparser\itext.styledxmlparser.csproj" Condition="Exists('..\..\..\itextcore\itext\itext.styledxmlparser\itext.styledxmlparser.csproj')" />
<ProjectReference Include="..\..\..\itextcore\itext\itext.svg\itext.svg.csproj" Condition="Exists('..\..\..\itextcore\itext\itext.svg\itext.svg.csproj')" />
<ProjectReference Include="..\..\itext\itext.html2pdf\itext.html2pdf.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,7 @@ public virtual void SimpleLinkTest() {
converterProperties.SetFontProvider(fontProvider);
HtmlConverter.ConvertToPdf(new FileStream(sourceHtml, FileMode.Open, FileAccess.Read), pdfDocument, converterProperties
);
/* TODO: DEVSIX-5700 - Links created from html2pdf are not ua-2 compliant
* One verapdf error is generated here:
* 1. clause="8.5.1", Real content that does not possess the semantics of text objects and does not have
* an alternate textual representation is not enclosed within Figure or Formula structure elements.
*/
CompareAndCheckCompliance(destinationPdf, cmpPdf, false);
CompareAndCheckCompliance(destinationPdf, cmpPdf, true);
}

[NUnit.Framework.Test]
Expand All @@ -79,12 +74,7 @@ public virtual void BackwardLinkTest() {
converterProperties.SetFontProvider(fontProvider);
HtmlConverter.ConvertToPdf(new FileStream(sourceHtml, FileMode.Open, FileAccess.Read), pdfDocument, converterProperties
);
/* TODO: DEVSIX-5700 - Links created from html2pdf are not ua-2 compliant
* One verapdf error is generated here:
* 1. clause="8.5.1", Real content that does not possess the semantics of text objects and does not have
* an alternate textual representation is not enclosed within Figure or Formula structure elements.
*/
CompareAndCheckCompliance(destinationPdf, cmpPdf, false);
CompareAndCheckCompliance(destinationPdf, cmpPdf, true);
}

[NUnit.Framework.Test]
Expand All @@ -101,11 +91,13 @@ public virtual void ImageLinkTest() {
converterProperties.SetBaseUri(SOURCE_FOLDER);
HtmlConverter.ConvertToPdf(new FileStream(sourceHtml, FileMode.Open, FileAccess.Read), pdfDocument, converterProperties
);
/* TODO: DEVSIX-5700 - Links created from html2pdf are not ua-2 compliant
* One verapdf error is generated here:
* 1. clause="8.5.1", Real content that does not possess the semantics of text objects and does not have
* an alternate textual representation is not enclosed within Figure or Formula structure elements.
*/
// The VeraPDF check fails probably to its internal bug. It checks that /ActualText != null, but the
// pdf/ua-2 documentation states the following:
// 8.5.1 General
// Real content that does not possess the semantics of text objects and does not have an alternate
// textual representation shall be enclosed within Figure structure elements in accordance with
// ISO 32000-2:2020, 14.8.4.8.5
// So probably VeraPDF should've checked for /Alt instead of /ActualText
CompareAndCheckCompliance(destinationPdf, cmpPdf, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ You should have received a copy of the GNU Affero General Public License
using System;
using System.Collections.Generic;
using System.IO;
using iText.Commons.Datastructures;
using iText.Html2pdf;
using iText.Html2pdf.Attach;
using iText.Html2pdf.Attach.Impl.Tags;
using iText.Html2pdf.Css;
using iText.Html2pdf.Html;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Action;
using iText.Kernel.Utils;
using iText.StyledXmlParser.Node;
using iText.StyledXmlParser.Node.Impl.Jsoup.Node;
Expand All @@ -51,7 +53,7 @@ public static void BeforeClass() {
public virtual void DefaultDestinationPrefixTest() {
IDictionary<String, int?> priorityMappings = new Dictionary<String, int?>();
priorityMappings.Put("p", 1);
OutlineHandler outlineHandler = new OutlineHandler().PutAllTagPriorityMappings(priorityMappings);
OutlineHandler outlineHandler = new OutlineHandler().PutAllMarksPriorityMappings(priorityMappings);
ProcessorContext context = new ProcessorContext(new ConverterProperties().SetOutlineHandler(outlineHandler
));
context.Reset(new PdfDocument(new PdfWriter(new MemoryStream())));
Expand All @@ -73,7 +75,7 @@ public virtual void DefaultDestinationPrefixTest() {
public virtual void CustomDestinationPrefixTest() {
IDictionary<String, int?> priorityMappings = new Dictionary<String, int?>();
priorityMappings.Put("p", 1);
OutlineHandler outlineHandler = new OutlineHandler().PutAllTagPriorityMappings(priorityMappings);
OutlineHandler outlineHandler = new OutlineHandler().PutAllMarksPriorityMappings(priorityMappings);
outlineHandler.SetDestinationNamePrefix("prefix-");
NUnit.Framework.Assert.AreEqual("prefix-", outlineHandler.GetDestinationNamePrefix());
ProcessorContext context = new ProcessorContext(new ConverterProperties().SetOutlineHandler(outlineHandler
Expand Down Expand Up @@ -131,5 +133,70 @@ public virtual void CapitalHeadingLevelTest() {
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFile, cmpFile, DESTINATION_FOLDER, "diff_capitalHeadingLevelOne"
));
}

[NUnit.Framework.Test]
public virtual void ClassBasedOutlineTest() {
String inFile = SOURCE_FOLDER + "htmlForClassBasedOutline.html";
String outFile = DESTINATION_FOLDER + "pdfWithClassBasedOutline.pdf";
String cmpFile = SOURCE_FOLDER + "cmp_pdfWithClassBasedOutline.pdf";
IDictionary<String, int?> priorityMappings = new Dictionary<String, int?>();
priorityMappings.Put("heading1", 1);
priorityMappings.Put("heading2", 2);
OutlineHandler handler = OutlineHandler.CreateHandler(new ClassOutlineMarkExtractor()).PutAllMarksPriorityMappings
(priorityMappings);
HtmlConverter.ConvertToPdf(new FileInfo(inFile), new FileInfo(outFile), new ConverterProperties().SetOutlineHandler
(handler));
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFile, cmpFile, DESTINATION_FOLDER, "diff_ClassBasedOutline"
));
}

[NUnit.Framework.Test]
public virtual void OverrideOutlineHandlerTest() {
String inFile = SOURCE_FOLDER + "htmlForChangedOutlineHandler.html";
String outFile = DESTINATION_FOLDER + "changedOutlineHandlerDoc.pdf";
String cmpFile = SOURCE_FOLDER + "cmp_changedOutlineHandlerDoc.pdf";
OutlineHandler handler = new OutlineHandlerTest.ChangedOutlineHandler();
HtmlConverter.ConvertToPdf(new FileInfo(inFile), new FileInfo(outFile), new ConverterProperties().SetOutlineHandler
(handler));
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFile, cmpFile, DESTINATION_FOLDER, "diff_ChangedOutlineHandler"
));
}

public class ChangedOutlineHandler : OutlineHandler {
protected internal override OutlineHandler AddOutlineAndDestToDocument(ITagWorker tagWorker, IElementNode
element, ProcessorContext context) {
String markName = markExtractor.GetMark(element);
if (null != tagWorker && HasMarkPriorityMapping(markName) && context.GetPdfDocument() != null && "customMark"
.Equals(element.GetAttribute("class"))) {
int level = (int)GetMarkPriorityMapping(markName);
if (null == currentOutline) {
currentOutline = context.GetPdfDocument().GetOutlines(false);
}
PdfOutline parent = currentOutline;
while (!levelsInProcess.IsEmpty() && level <= levelsInProcess.JGetFirst()) {
parent = parent.GetParent();
levelsInProcess.JRemoveFirst();
}
PdfOutline outline = parent.AddOutline(GenerateOutlineName(element));
String destination = GenerateUniqueDestinationName(element);
PdfAction action = PdfAction.CreateGoTo(destination);
outline.AddAction(action);
destinationsInProcess.AddFirst(new Tuple2<String, PdfDictionary>(destination, action.GetPdfObject()));
levelsInProcess.AddFirst(level);
currentOutline = outline;
}
return this;
}

public ChangedOutlineHandler() {
markExtractor = new TagOutlineMarkExtractor();
PutMarkPriorityMapping(TagConstants.H1, 1);
PutMarkPriorityMapping(TagConstants.H2, 2);
PutMarkPriorityMapping(TagConstants.H3, 3);
PutMarkPriorityMapping(TagConstants.H4, 4);
PutMarkPriorityMapping(TagConstants.H5, 5);
PutMarkPriorityMapping(TagConstants.H6, 6);
}
}
}
}
108 changes: 108 additions & 0 deletions itext.tests/itext.html2pdf.tests/itext/html2pdf/css/DirectionTest.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-2024 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.Html2pdf;
using iText.IO.Util;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Canvas.Parser;
using iText.Test;
using iText.Test.Attributes;

namespace iText.Html2pdf.Css {
[NUnit.Framework.Category("IntegrationTest")]
public class DirectionTest : ExtendedHtmlConversionITextTest {
private static readonly String SOURCE_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/itext/html2pdf/css/DirectionTest/";

private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/itext/html2pdf/css/DirectionTest/";

[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
CreateDestinationFolder(DESTINATION_FOLDER);
}

[NUnit.Framework.Test]
[LogMessage(iText.IO.Logs.IoLogMessageConstant.TYPOGRAPHY_NOT_FOUND, Count = 2, LogLevel = LogLevelConstants
.WARN)]
public virtual void SimpleLtrDocTest() {
NUnit.Framework.Assert.IsTrue(GetTextFromDocument(ConvertToHtmlDocument("SimpleLtrDoc"), 1).Contains("123456789."
));
}

[NUnit.Framework.Test]
public virtual void SimpleLtrElementDocTest() {
NUnit.Framework.Assert.IsTrue(GetTextFromDocument(ConvertToHtmlDocument("SimpleLtrElementDoc"), 1).Contains
("123456789."));
}

//TODO DEVSIX-1920: RTL ignored. Change test after fix
[NUnit.Framework.Test]
public virtual void SimpleRtlElementDocTest() {
NUnit.Framework.Assert.IsFalse(GetTextFromDocument(ConvertToHtmlDocument("SimpleRtlElementDoc"), 1).Contains
(".Right to left text"));
}

//TODO DEVSIX-2437 : Change test after fix
[NUnit.Framework.Test]
[LogMessage(iText.IO.Logs.IoLogMessageConstant.TYPOGRAPHY_NOT_FOUND, Count = 4, LogLevel = LogLevelConstants
.WARN)]
public virtual void LtrInRtlDocTest() {
NUnit.Framework.Assert.IsFalse(GetTextFromDocument(ConvertToHtmlDocument("LtrInRtlDoc"), 1).Contains("!Right to left text"
));
}

//TODO DEVSIX-2437 : Change test after fix
[NUnit.Framework.Test]
[LogMessage(iText.IO.Logs.IoLogMessageConstant.TYPOGRAPHY_NOT_FOUND, Count = 4, LogLevel = LogLevelConstants
.WARN)]
public virtual void RtlInLtrDocTest() {
NUnit.Framework.Assert.IsFalse(GetTextFromDocument(ConvertToHtmlDocument("RtlInLtrDoc"), 1).Contains("!Right to left text"
));
}

//TODO DEVSIX-3069: Change test after fix
[NUnit.Framework.Test]
[LogMessage(iText.IO.Logs.IoLogMessageConstant.TYPOGRAPHY_NOT_FOUND, Count = 34, LogLevel = LogLevelConstants
.WARN)]
[LogMessage(iText.IO.Logs.IoLogMessageConstant.TABLE_WIDTH_IS_MORE_THAN_EXPECTED_DUE_TO_MIN_WIDTH, Count =
1, LogLevel = LogLevelConstants.WARN)]
public virtual void BigTableTest() {
ConvertToPdfAndCompare("TooLargeTable", SOURCE_FOLDER, DESTINATION_FOLDER);
}

private PdfDocument ConvertToHtmlDocument(String fileName) {
String sourceHtml = SOURCE_FOLDER + fileName + ".html";
String destPdf = DESTINATION_FOLDER + fileName + ".pdf";
HtmlConverter.ConvertToPdf(new FileInfo(sourceHtml), new FileInfo(destPdf));
System.Console.Out.WriteLine("html: " + UrlUtil.GetNormalizedFileUriString(sourceHtml) + "\n" + "Out pdf: "
+ UrlUtil.GetNormalizedFileUriString(destPdf));
return new PdfDocument(new PdfReader(destPdf));
}

private String GetTextFromDocument(PdfDocument document, int pageNum) {
return PdfTextExtractor.GetTextFromPage(document.GetPage(pageNum));
}
}
}
Loading

0 comments on commit 21ea8f9

Please sign in to comment.