Skip to content

Commit 7a9ad3d

Browse files
Dmitry RadchukiText-CI
authored andcommitted
Add automatic link alternative description parsing
DEVSIX-7996 Autoported commit. Original commit hash: [7d77290d6]
1 parent 6da2691 commit 7a9ad3d

File tree

12 files changed

+84
-13
lines changed

12 files changed

+84
-13
lines changed

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

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,9 @@ public virtual void SimpleLinkTest() {
5858
converterProperties.SetFontProvider(fontProvider);
5959
HtmlConverter.ConvertToPdf(new FileStream(sourceHtml, FileMode.Open, FileAccess.Read), pdfDocument, converterProperties
6060
);
61-
/* TODO: DEVSIX-7996 - Links created from html2pdf are not ua-2 compliant
62-
* Two verapdf errors are generated here:
63-
* 1. clause="8.9.4.1", Link annotation neither has a Contents entry nor alternate description.
64-
* 2. clause="8.5.1", Real content that does not possess the semantics of text objects and does not have
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
6564
* an alternate textual representation is not enclosed within Figure or Formula structure elements.
6665
*/
6766
CompareAndCheckCompliance(destinationPdf, cmpPdf, false);
@@ -80,10 +79,31 @@ public virtual void BackwardLinkTest() {
8079
converterProperties.SetFontProvider(fontProvider);
8180
HtmlConverter.ConvertToPdf(new FileStream(sourceHtml, FileMode.Open, FileAccess.Read), pdfDocument, converterProperties
8281
);
83-
/* TODO: DEVSIX-7996 - Links created from html2pdf are not ua-2 compliant
84-
* Two verapdf errors are generated here:
85-
* 1. clause="8.9.4.1", Link annotation neither has a Contents entry nor alternate description.
86-
* 2. clause="8.5.1", Real content that does not possess the semantics of text objects and does not have
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);
88+
}
89+
90+
[NUnit.Framework.Test]
91+
public virtual void ImageLinkTest() {
92+
String sourceHtml = SOURCE_FOLDER + "imageLink.html";
93+
String cmpPdf = SOURCE_FOLDER + "cmp_imageLink.pdf";
94+
String destinationPdf = DESTINATION_FOLDER + "imageLink.pdf";
95+
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(destinationPdf, new WriterProperties().SetPdfVersion
96+
(PdfVersion.PDF_2_0)));
97+
CreateSimplePdfUA2Document(pdfDocument);
98+
ConverterProperties converterProperties = new ConverterProperties();
99+
FontProvider fontProvider = new DefaultFontProvider(false, true, false);
100+
converterProperties.SetFontProvider(fontProvider);
101+
converterProperties.SetBaseUri(SOURCE_FOLDER);
102+
HtmlConverter.ConvertToPdf(new FileStream(sourceHtml, FileMode.Open, FileAccess.Read), pdfDocument, converterProperties
103+
);
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
87107
* an alternate textual representation is not enclosed within Figure or Formula structure elements.
88108
*/
89109
CompareAndCheckCompliance(destinationPdf, cmpPdf, false);

itext.tests/itext.html2pdf.tests/resources/itext/html2pdf/HtmlConverterPdfUA2Test/backwardLink.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<div id="15=15">Target div</div>
99
<div style="height:1000px">Some content</div>
10-
<a href="#15=15">Long link text to bottom div. Long link text to bottom div. Long link text to bottom div.
10+
<a href="#15=15" title="alternative description">Long link text to bottom div. Long link text to bottom div. Long link text to bottom div.
1111
Long link text to bottom div. Long link text to bottom div. Long link text to bottom div.</a>
1212

1313
</body>
1010 Bytes
Loading
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
5+
</head>
6+
<body>
7+
8+
<a href="#15=15" title="alternative description"><img alt="blue96x96" src="blue96x96.png"></a>
9+
<div style="height:1000px">Some content</div>
10+
<div id="15=15">Target div</div>
11+
12+
</body>
13+
</html>

itext.tests/itext.html2pdf.tests/resources/itext/html2pdf/HtmlConverterPdfUA2Test/simpleLink.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</head>
66
<body>
77

8-
<a href="#15=15">Long link text to bottom div. Long link text to bottom div. Long link text to bottom div.
8+
<a href="#15=15" title="alternative description">Long link text to bottom div. Long link text to bottom div. Long link text to bottom div.
99
Long link text to bottom div. Long link text to bottom div. Long link text to bottom div.</a>
1010
<div style="height:1000px">Some content</div>
1111
<div id="15=15">Target div</div>

itext/itext.html2pdf/itext/html2pdf/attach/impl/tags/ABlockTagWorker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public override void ProcessEnd(IElementNode element, ProcessorContext context)
6969
}
7070
}
7171
((Div)GetElementResult()).GetAccessibilityProperties().SetRole(StandardRoles.LINK);
72-
LinkHelper.ApplyLinkAnnotation(GetElementResult(), url, context);
72+
LinkHelper.ApplyLinkAnnotation(GetElementResult(), url, context, element);
7373
}
7474
if (GetElementResult() != null) {
7575
String name = element.GetAttribute(AttributeConstants.NAME);

itext/itext.html2pdf/itext/html2pdf/attach/impl/tags/ATagWorker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public override void ProcessEnd(IElementNode element, ProcessorContext context)
9898
}
9999
GetAllElements()[i] = simulatedDiv;
100100
}
101-
LinkHelper.ApplyLinkAnnotation(GetAllElements()[i], url, context);
101+
LinkHelper.ApplyLinkAnnotation(GetAllElements()[i], url, context, element);
102102
}
103103
}
104104
if (!GetAllElements().IsEmpty()) {

0 commit comments

Comments
 (0)