在iText5
中,我们可以使用章节来添加标题和书签。
然后标题将在可访问的 PDF 中显示为 H1
标签。
我如何在 iText7
中做到这一点?
最佳答案
在 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);
}
使用 Adobe Reader 检查标签以验证是否应用了正确的标签。
关于c# - 使用 iText 7 和 C# 在可访问的 pdf 中将标题添加为 H1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50675472/