【问题标题】:Add titles as H1 in accessible pdf using iText 7 and C#使用 iText 7 和 C# 在可访问的 pdf 中将标题添加为 H1
【发布时间】:2018-06-04 07:34:42
【问题描述】:

iText5中,我们可以使用章节和章节来添加标题和书签。
然后标题将在可访问的 PDF 中显示为H1 标签。
我如何在iText7 中做到这一点?

【问题讨论】:

    标签: c# itext7 accessible


    【解决方案1】:

    在 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 检查标签,确认已应用正确的标签。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-12
      • 1970-01-01
      • 2017-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-26
      • 2023-03-12
      相关资源
      最近更新 更多