Skip to content

Commit 21ea8f9

Browse files
committed
[RELEASE] iText pdfHtml 5.0.4
2 parents b0ccede + 57f0d23 commit 21ea8f9

File tree

182 files changed

+3821
-95
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

182 files changed

+3821
-95
lines changed

doxyfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ DOXYFILE_ENCODING = UTF-8
3232
# title of most generated pages and in a few other places.
3333
# The default value is: My Project.
3434

35-
PROJECT_NAME = "pdfHTML 5.0.3 API"
35+
PROJECT_NAME = "pdfHTML 5.0.4 API"
3636

3737
# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
3838
# could be handy for archiving the generated documentation or if some version

itext.tests/itext.html2pdf.tests/Properties/AssemblyInfo.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515

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

18-
[assembly: AssemblyVersion("5.0.3.0")]
19-
[assembly: AssemblyFileVersion("5.0.3.0")]
20-
[assembly: AssemblyInformationalVersion("5.0.3")]
18+
[assembly: AssemblyVersion("5.0.4.0")]
19+
[assembly: AssemblyFileVersion("5.0.4.0")]
20+
[assembly: AssemblyInformationalVersion("5.0.4")]
2121

2222
#if !NETSTANDARD2_0
2323
[assembly: NUnit.Framework.Timeout(300000)]

itext.tests/itext.html2pdf.tests/itext.html2pdf.tests.csproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@
4444
</ItemGroup>
4545
<ItemGroup>
4646
<ProjectReference Include="..\..\..\itextcore\itext\itext.io\itext.io.csproj" Condition="Exists('..\..\..\itextcore\itext\itext.io\itext.io.csproj')" />
47-
<PackageReference Include="itext" Version="8.0.3" Condition="!Exists('..\..\..\itextcore\itext\itext.io\itext.io.csproj')" />
47+
<PackageReference Include="itext" Version="8.0.4" Condition="!Exists('..\..\..\itextcore\itext\itext.io\itext.io.csproj')" />
4848
<ProjectReference Include="..\..\..\itextcore\itext\itext.kernel\itext.kernel.csproj" Condition="Exists('..\..\..\itextcore\itext\itext.kernel\itext.kernel.csproj')" />
4949
<ProjectReference Include="..\..\..\itextcore\itext\itext.layout\itext.layout.csproj" Condition="Exists('..\..\..\itextcore\itext\itext.layout\itext.layout.csproj')" />
5050
<ProjectReference Include="..\..\..\itextcore\itext\itext.forms\itext.forms.csproj" Condition="Exists('..\..\..\itextcore\itext\itext.forms\itext.forms.csproj')" />
5151
<ProjectReference Include="..\..\..\itextcore\itext\itext.pdfa\itext.pdfa.csproj" Condition="Exists('..\..\..\itextcore\itext\itext.pdfa\itext.pdfa.csproj')" />
5252
<ProjectReference Include="..\..\..\itextcore\itext\itext.hyph\itext.hyph.csproj" Condition="Exists('..\..\..\itextcore\itext\itext.hyph\itext.hyph.csproj')" />
53-
<PackageReference Include="itext.hyph" Version="8.0.3" Condition="!Exists('..\..\..\itextcore\itext\itext.hyph\itext.hyph.csproj')" />
53+
<PackageReference Include="itext.hyph" Version="8.0.4" Condition="!Exists('..\..\..\itextcore\itext\itext.hyph\itext.hyph.csproj')" />
5454
<ProjectReference Include="..\..\..\itextcore\itext\itext.pdftest\itext.pdftest.csproj" Condition="Exists('..\..\..\itextcore\itext\itext.pdftest\itext.pdftest.csproj')" />
55-
<PackageReference Include="itext.pdftest" Version="8.0.3" Condition="!Exists('..\..\..\itextcore\itext\itext.pdftest\itext.pdftest.csproj')" />
55+
<PackageReference Include="itext.pdftest" Version="8.0.4" Condition="!Exists('..\..\..\itextcore\itext\itext.pdftest\itext.pdftest.csproj')" />
5656
<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')" />
57-
<PackageReference Include="itext.bouncy-castle-adapter" Version="8.0.3" Condition="!Exists('..\..\..\itextcore\itext\itext.bouncy-castle-adapter\itext.bouncy-castle-adapter.csproj')" />
57+
<PackageReference Include="itext.bouncy-castle-adapter" Version="8.0.4" Condition="!Exists('..\..\..\itextcore\itext\itext.bouncy-castle-adapter\itext.bouncy-castle-adapter.csproj')" />
5858
<ProjectReference Include="..\..\..\itextcore\itext\itext.styledxmlparser\itext.styledxmlparser.csproj" Condition="Exists('..\..\..\itextcore\itext\itext.styledxmlparser\itext.styledxmlparser.csproj')" />
5959
<ProjectReference Include="..\..\..\itextcore\itext\itext.svg\itext.svg.csproj" Condition="Exists('..\..\..\itextcore\itext\itext.svg\itext.svg.csproj')" />
6060
<ProjectReference Include="..\..\itext\itext.html2pdf\itext.html2pdf.csproj" />

itext.tests/itext.html2pdf.tests/itext/html2pdf/HtmlConverterPdfUA2Test.cs

+9-17
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,7 @@ public virtual void SimpleLinkTest() {
5858
converterProperties.SetFontProvider(fontProvider);
5959
HtmlConverter.ConvertToPdf(new FileStream(sourceHtml, FileMode.Open, FileAccess.Read), pdfDocument, converterProperties
6060
);
61-
/* TODO: DEVSIX-5700 - Links created from html2pdf are not ua-2 compliant
62-
* One verapdf error is generated here:
63-
* 1. clause="8.5.1", Real content that does not possess the semantics of text objects and does not have
64-
* an alternate textual representation is not enclosed within Figure or Formula structure elements.
65-
*/
66-
CompareAndCheckCompliance(destinationPdf, cmpPdf, false);
61+
CompareAndCheckCompliance(destinationPdf, cmpPdf, true);
6762
}
6863

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

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

itext.tests/itext.html2pdf.tests/itext/html2pdf/attach/impl/OutlineHandlerTest.cs

+69-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ You should have received a copy of the GNU Affero General Public License
2323
using System;
2424
using System.Collections.Generic;
2525
using System.IO;
26+
using iText.Commons.Datastructures;
2627
using iText.Html2pdf;
2728
using iText.Html2pdf.Attach;
2829
using iText.Html2pdf.Attach.Impl.Tags;
2930
using iText.Html2pdf.Css;
3031
using iText.Html2pdf.Html;
3132
using iText.Kernel.Pdf;
33+
using iText.Kernel.Pdf.Action;
3234
using iText.Kernel.Utils;
3335
using iText.StyledXmlParser.Node;
3436
using iText.StyledXmlParser.Node.Impl.Jsoup.Node;
@@ -51,7 +53,7 @@ public static void BeforeClass() {
5153
public virtual void DefaultDestinationPrefixTest() {
5254
IDictionary<String, int?> priorityMappings = new Dictionary<String, int?>();
5355
priorityMappings.Put("p", 1);
54-
OutlineHandler outlineHandler = new OutlineHandler().PutAllTagPriorityMappings(priorityMappings);
56+
OutlineHandler outlineHandler = new OutlineHandler().PutAllMarksPriorityMappings(priorityMappings);
5557
ProcessorContext context = new ProcessorContext(new ConverterProperties().SetOutlineHandler(outlineHandler
5658
));
5759
context.Reset(new PdfDocument(new PdfWriter(new MemoryStream())));
@@ -73,7 +75,7 @@ public virtual void DefaultDestinationPrefixTest() {
7375
public virtual void CustomDestinationPrefixTest() {
7476
IDictionary<String, int?> priorityMappings = new Dictionary<String, int?>();
7577
priorityMappings.Put("p", 1);
76-
OutlineHandler outlineHandler = new OutlineHandler().PutAllTagPriorityMappings(priorityMappings);
78+
OutlineHandler outlineHandler = new OutlineHandler().PutAllMarksPriorityMappings(priorityMappings);
7779
outlineHandler.SetDestinationNamePrefix("prefix-");
7880
NUnit.Framework.Assert.AreEqual("prefix-", outlineHandler.GetDestinationNamePrefix());
7981
ProcessorContext context = new ProcessorContext(new ConverterProperties().SetOutlineHandler(outlineHandler
@@ -131,5 +133,70 @@ public virtual void CapitalHeadingLevelTest() {
131133
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFile, cmpFile, DESTINATION_FOLDER, "diff_capitalHeadingLevelOne"
132134
));
133135
}
136+
137+
[NUnit.Framework.Test]
138+
public virtual void ClassBasedOutlineTest() {
139+
String inFile = SOURCE_FOLDER + "htmlForClassBasedOutline.html";
140+
String outFile = DESTINATION_FOLDER + "pdfWithClassBasedOutline.pdf";
141+
String cmpFile = SOURCE_FOLDER + "cmp_pdfWithClassBasedOutline.pdf";
142+
IDictionary<String, int?> priorityMappings = new Dictionary<String, int?>();
143+
priorityMappings.Put("heading1", 1);
144+
priorityMappings.Put("heading2", 2);
145+
OutlineHandler handler = OutlineHandler.CreateHandler(new ClassOutlineMarkExtractor()).PutAllMarksPriorityMappings
146+
(priorityMappings);
147+
HtmlConverter.ConvertToPdf(new FileInfo(inFile), new FileInfo(outFile), new ConverterProperties().SetOutlineHandler
148+
(handler));
149+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFile, cmpFile, DESTINATION_FOLDER, "diff_ClassBasedOutline"
150+
));
151+
}
152+
153+
[NUnit.Framework.Test]
154+
public virtual void OverrideOutlineHandlerTest() {
155+
String inFile = SOURCE_FOLDER + "htmlForChangedOutlineHandler.html";
156+
String outFile = DESTINATION_FOLDER + "changedOutlineHandlerDoc.pdf";
157+
String cmpFile = SOURCE_FOLDER + "cmp_changedOutlineHandlerDoc.pdf";
158+
OutlineHandler handler = new OutlineHandlerTest.ChangedOutlineHandler();
159+
HtmlConverter.ConvertToPdf(new FileInfo(inFile), new FileInfo(outFile), new ConverterProperties().SetOutlineHandler
160+
(handler));
161+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFile, cmpFile, DESTINATION_FOLDER, "diff_ChangedOutlineHandler"
162+
));
163+
}
164+
165+
public class ChangedOutlineHandler : OutlineHandler {
166+
protected internal override OutlineHandler AddOutlineAndDestToDocument(ITagWorker tagWorker, IElementNode
167+
element, ProcessorContext context) {
168+
String markName = markExtractor.GetMark(element);
169+
if (null != tagWorker && HasMarkPriorityMapping(markName) && context.GetPdfDocument() != null && "customMark"
170+
.Equals(element.GetAttribute("class"))) {
171+
int level = (int)GetMarkPriorityMapping(markName);
172+
if (null == currentOutline) {
173+
currentOutline = context.GetPdfDocument().GetOutlines(false);
174+
}
175+
PdfOutline parent = currentOutline;
176+
while (!levelsInProcess.IsEmpty() && level <= levelsInProcess.JGetFirst()) {
177+
parent = parent.GetParent();
178+
levelsInProcess.JRemoveFirst();
179+
}
180+
PdfOutline outline = parent.AddOutline(GenerateOutlineName(element));
181+
String destination = GenerateUniqueDestinationName(element);
182+
PdfAction action = PdfAction.CreateGoTo(destination);
183+
outline.AddAction(action);
184+
destinationsInProcess.AddFirst(new Tuple2<String, PdfDictionary>(destination, action.GetPdfObject()));
185+
levelsInProcess.AddFirst(level);
186+
currentOutline = outline;
187+
}
188+
return this;
189+
}
190+
191+
public ChangedOutlineHandler() {
192+
markExtractor = new TagOutlineMarkExtractor();
193+
PutMarkPriorityMapping(TagConstants.H1, 1);
194+
PutMarkPriorityMapping(TagConstants.H2, 2);
195+
PutMarkPriorityMapping(TagConstants.H3, 3);
196+
PutMarkPriorityMapping(TagConstants.H4, 4);
197+
PutMarkPriorityMapping(TagConstants.H5, 5);
198+
PutMarkPriorityMapping(TagConstants.H6, 6);
199+
}
200+
}
134201
}
135202
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2024 Apryse Group NV
4+
Authors: Apryse Software.
5+
6+
This program is offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
using System;
24+
using System.IO;
25+
using iText.Html2pdf;
26+
using iText.IO.Util;
27+
using iText.Kernel.Pdf;
28+
using iText.Kernel.Pdf.Canvas.Parser;
29+
using iText.Test;
30+
using iText.Test.Attributes;
31+
32+
namespace iText.Html2pdf.Css {
33+
[NUnit.Framework.Category("IntegrationTest")]
34+
public class DirectionTest : ExtendedHtmlConversionITextTest {
35+
private static readonly String SOURCE_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
36+
.CurrentContext.TestDirectory) + "/resources/itext/html2pdf/css/DirectionTest/";
37+
38+
private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
39+
+ "/test/itext/html2pdf/css/DirectionTest/";
40+
41+
[NUnit.Framework.OneTimeSetUp]
42+
public static void BeforeClass() {
43+
CreateDestinationFolder(DESTINATION_FOLDER);
44+
}
45+
46+
[NUnit.Framework.Test]
47+
[LogMessage(iText.IO.Logs.IoLogMessageConstant.TYPOGRAPHY_NOT_FOUND, Count = 2, LogLevel = LogLevelConstants
48+
.WARN)]
49+
public virtual void SimpleLtrDocTest() {
50+
NUnit.Framework.Assert.IsTrue(GetTextFromDocument(ConvertToHtmlDocument("SimpleLtrDoc"), 1).Contains("123456789."
51+
));
52+
}
53+
54+
[NUnit.Framework.Test]
55+
public virtual void SimpleLtrElementDocTest() {
56+
NUnit.Framework.Assert.IsTrue(GetTextFromDocument(ConvertToHtmlDocument("SimpleLtrElementDoc"), 1).Contains
57+
("123456789."));
58+
}
59+
60+
//TODO DEVSIX-1920: RTL ignored. Change test after fix
61+
[NUnit.Framework.Test]
62+
public virtual void SimpleRtlElementDocTest() {
63+
NUnit.Framework.Assert.IsFalse(GetTextFromDocument(ConvertToHtmlDocument("SimpleRtlElementDoc"), 1).Contains
64+
(".Right to left text"));
65+
}
66+
67+
//TODO DEVSIX-2437 : Change test after fix
68+
[NUnit.Framework.Test]
69+
[LogMessage(iText.IO.Logs.IoLogMessageConstant.TYPOGRAPHY_NOT_FOUND, Count = 4, LogLevel = LogLevelConstants
70+
.WARN)]
71+
public virtual void LtrInRtlDocTest() {
72+
NUnit.Framework.Assert.IsFalse(GetTextFromDocument(ConvertToHtmlDocument("LtrInRtlDoc"), 1).Contains("!Right to left text"
73+
));
74+
}
75+
76+
//TODO DEVSIX-2437 : Change test after fix
77+
[NUnit.Framework.Test]
78+
[LogMessage(iText.IO.Logs.IoLogMessageConstant.TYPOGRAPHY_NOT_FOUND, Count = 4, LogLevel = LogLevelConstants
79+
.WARN)]
80+
public virtual void RtlInLtrDocTest() {
81+
NUnit.Framework.Assert.IsFalse(GetTextFromDocument(ConvertToHtmlDocument("RtlInLtrDoc"), 1).Contains("!Right to left text"
82+
));
83+
}
84+
85+
//TODO DEVSIX-3069: Change test after fix
86+
[NUnit.Framework.Test]
87+
[LogMessage(iText.IO.Logs.IoLogMessageConstant.TYPOGRAPHY_NOT_FOUND, Count = 34, LogLevel = LogLevelConstants
88+
.WARN)]
89+
[LogMessage(iText.IO.Logs.IoLogMessageConstant.TABLE_WIDTH_IS_MORE_THAN_EXPECTED_DUE_TO_MIN_WIDTH, Count =
90+
1, LogLevel = LogLevelConstants.WARN)]
91+
public virtual void BigTableTest() {
92+
ConvertToPdfAndCompare("TooLargeTable", SOURCE_FOLDER, DESTINATION_FOLDER);
93+
}
94+
95+
private PdfDocument ConvertToHtmlDocument(String fileName) {
96+
String sourceHtml = SOURCE_FOLDER + fileName + ".html";
97+
String destPdf = DESTINATION_FOLDER + fileName + ".pdf";
98+
HtmlConverter.ConvertToPdf(new FileInfo(sourceHtml), new FileInfo(destPdf));
99+
System.Console.Out.WriteLine("html: " + UrlUtil.GetNormalizedFileUriString(sourceHtml) + "\n" + "Out pdf: "
100+
+ UrlUtil.GetNormalizedFileUriString(destPdf));
101+
return new PdfDocument(new PdfReader(destPdf));
102+
}
103+
104+
private String GetTextFromDocument(PdfDocument document, int pageNum) {
105+
return PdfTextExtractor.GetTextFromPage(document.GetPage(pageNum));
106+
}
107+
}
108+
}

0 commit comments

Comments
 (0)