c# - 使用 iText 7 和 C# 在可访问的 pdf 中将标题添加为 H1

标签 c# itext7 accessible

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);
}

使用 Adob​​e Reader 检查标签以验证是否应用了正确的标签。

enter image description here

关于c# - 使用 iText 7 和 C# 在可访问的 pdf 中将标题添加为 H1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50675472/

相关文章:

C#:我应该抛出 ArgumentException 还是 DirectoryNotFoundException?

c# - 数据表导入行

java - 迁移到 iText 7 - 将通用对象添加到 PDF

iframe - 如何使添加到iframe中的youtube视频可访问?

instance - 无法在 LAN 上访问 openstack 实例

c# - 查找两个 json 对象之间的差异

c# - 将未映射的类与 NHibernate 命名查询一起使用

java - 如何以使用itext7动态生成的表的形式生成LinkedHashMap

java - 如何将 iText5 代码片段正确翻译为 iText7?

security - laravel-4 中分类文件的受控访问