[英]Add titles as H1 in accessible pdf using iText 7 and C#
In iText5
, we can use chapter and section to add titles and bookmarks. 在
iText5
,我们可以使用章节和章节来添加标题和书签。
Then title will displayed as H1
tag in accessible PDF. 然后标题将显示为可访问PDF中的
H1
标记。
How I can do this in iText7
? 我怎么能在
iText7
做到这iText7
?
In iText7, you'd do it like this: 在iText7中,您可以这样做:
@Test
public void run() throws IOException {
File outputFile = getOutputFile();
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outputFile));
pdfDocument.setTagged();
Document layoutDocument = new Document(pdfDocument);
Paragraph para = new Paragraph("The Raven")
.setFontColor(new DeviceRgb(8, 73, 117))
.setFontSize(20f);
para.getAccessibilityProperties().setRole(StandardRoles.H1);
layoutDocument.add(para);
layoutDocument.add(new Paragraph("Once upon a midnight dreary\nWhile I pondered weak and weary\nOver many a quaint and curious volume\nOf forgotten lore"));
pdfDocument.close();
Desktop.getDesktop().open(outputFile);
}
Checking the tags with Adobe Reader verifies the correct tagging has been applied. 使用Adobe Reader检查标记可验证是否已应用正确的标记。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.