C#-为PDF文件中的所有书签设置继承缩放动作[英] C# - Set inherit zoom action for all the bookmarks in the PDF file

本文是小编为大家收集整理的关于C#-为PDF文件中的所有书签设置继承缩放动作的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

本文来自:IT宝库(https://www.itbaoku.cn)

我有一个带有3种类型的书签

的PDF文件
  • 第一本书 - 100%Zoom
  • 第二本书标记-200%Zoom
  • 第三本书标记-300%Zoom

我使用了以下代码,但在注释行中失败.

PdfArray annots = page.getAsArray(PdfName.ANNOTS); // fails
for (int i = 0; i < annots.size(); i++)
{
    PdfDictionary annotation = annots.getAsDict(i);
    if (PdfName.LINK.equals(annotation.getAsName(PdfName.SUBTYPE)))
    {
        PdfArray d = annotation.getAsArray(PdfName.DEST);
        if (d != null && d.size() == 5 && PdfName.XYZ.equals(d.getAsName(1)))
        {
            d.set(4, new PdfNumber(0)); //error-does not contain set method in pdfarray
        }
    }
}

我需要为PDF文件中的所有书签设置继承缩放操作.如何使用iTextSharp.

推荐答案

您在itextsharp中使用itext代码.

替换:

d.set(4, new PdfNumber(0));

with:

d[4] = new PdfNumber(0);

本文地址:https://www.itbaoku.cn/post/951460.html

问题描述

I have a PDF file with 3 types of bookmark

  • 1st book mark - 100% zoom
  • 2nd book mark - 200% zoom
  • 3rd book mark - 300% zoom

I have used following code but its fails in the annotation line.

PdfArray annots = page.getAsArray(PdfName.ANNOTS); // fails
for (int i = 0; i < annots.size(); i++)
{
    PdfDictionary annotation = annots.getAsDict(i);
    if (PdfName.LINK.equals(annotation.getAsName(PdfName.SUBTYPE)))
    {
        PdfArray d = annotation.getAsArray(PdfName.DEST);
        if (d != null && d.size() == 5 && PdfName.XYZ.equals(d.getAsName(1)))
        {
            d.set(4, new PdfNumber(0)); //error-does not contain set method in pdfarray
        }
    }
}

I need to set inherit zoom action for all the bookmarks in the PDF file. How can I set the inherit zoom action for PDF file using iTextSharp.

推荐答案

You are using iText code in iTextSharp.

Replace:

d.set(4, new PdfNumber(0));

With:

d[4] = new PdfNumber(0);