0

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.

mail2vguna
  • 25
  • 2
  • 9
  • possible duplicate of [Set inherit Zoom(action property) to bookmark in the pdf file](http://stackoverflow.com/questions/24217657/set-inherit-zoomaction-property-to-bookmark-in-the-pdf-file) – Jongware Nov 17 '14 at 13:55

1 Answers1

0

You are using iText code in iTextSharp.

Replace:

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

With:

d[4] = new PdfNumber(0);
Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
  • Sorry this is my question.If anything wrong ignore it.i am getting null handle in this line PdfArray annots = page.getAsArray(PdfName.ANNOTS); // fails.can you provide code to set inherit zoom for pdf file.Thanks. – mail2vguna Jun 05 '14 at 14:40
  • You are mixing two completely different concepts: **bookmarks** (as in elements of the "outline tree") and **link annotations** (as in the clickable areas on a page). You need to make up your mind: are you talking about bookmarks or about annotations? It is perfectly normal that you `page.getAsArray(PdfName.ANNOTS);` returns `null` if there are no annotations on the page. However, this is *completely* irrelevant in a question about bookmarks and zoom factors. You won't get any answer by anyone unless you ask us what you really want to know. – Bruno Lowagie Jun 05 '14 at 15:07
  • I need to set the inherit zoom action for all the bookmarks in the pdf file. This is my question. Thanks. – mail2vguna Jun 05 '14 at 15:49
  • If that is what you want, then why are you talking about annotations. Please update your question. If you had asked the correct question from the start, then you'd have received an answer today. Now I'm already 1 hour late, so you'll have to wait until tomorrow... – Bruno Lowagie Jun 05 '14 at 15:51
  • Hi any my regarding my question? set the inherit zoom action for all the bookmarks in the pdf file? Thanks. – mail2vguna Jun 14 '14 at 05:43
  • Post another question using the correct terminology and a code sample that doesn't put us on the wrong foot. Your question was wrong and therefore you shouldn't expect a correct answer! – Bruno Lowagie Jun 14 '14 at 06:57