Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用iText 7和C在可访问的pdf中添加标题H1#_C#_Itext7_Accessible - Fatal编程技术网

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

C# 使用iText 7和C在可访问的pdf中添加标题H1#,c#,itext7,accessible,C#,Itext7,Accessible,在iText5中,我们可以使用章节添加标题和书签。 然后标题将在可访问的PDF中显示为H1标记。 如何在iText7中执行此操作 在iText7中,您可以这样做: @Test public void run() throws IOException { File outputFile = getOutputFile(); PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outputFile)); pdfD

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检查标记可验证是否应用了正确的标记