C# - Set inherit zoom action for all the bookmarks

2019-09-15 08:25发布

问题:

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.

回答1:

You are using iText code in iTextSharp.

Replace:

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

With:

d[4] = new PdfNumber(0);