title: Changing the zoom level in all link destinations in PDFs
body: <p>A code that changes zoom level using <code>iText</code> in <code>Java</code> is given in at <a href="http://developers.itextpdf.com/examples/actions-and-annotations/changing-zoom-factor-link-destination" rel="nofollow noreferrer">iText home page</a>. I would like to convert it to <code>C#</code>. After countless hours, I have finally rewritten the code only to find out that it didn't change any link. It means I must have made errors. </p>
  
  <p>EDIT:</p>
  
  <p>As requested, please have a look at a <a href="http://rgho.st/84HQPbzPg" rel="nofollow noreferrer">simple PDF example</a>.</p>
  
  <p>My code is as follows:</p>
  
  <pre><code>using (var reader = new PdfReader(input))
  {
      using (var stamper = new PdfStamper(reader, ms))
      {
          for (int i = 1; i &lt;= reader.NumberOfPages; i++)
          {
              // Get a page of a PDF page
              PdfDictionary page = reader.GetPageN(i);
  
              // Get all the annotations of page i
              PdfArray annotsArray = page.GetAsArray(PdfName.ANNOTS);
  
              // If page does not have annotations
              if (annotsArray == null)
              {
                  continue;
              }
  
              // For each annotation
              for (int j = 0; j &lt; annotsArray.Size; j++)
              {
                  // for current annotation
                  PdfDictionary annotation = annotsArray.GetAsDict(j);
  
                  // test if it is LINK
                  PdfDictionary annotationAction = annotation.GetAsDict(PdfName.A);
                  if ( annotationAction == null || PdfName.LINK.Equals(annotationAction.Get(PdfName.S)) )
                  {
                      PdfArray d = annotation.GetAsArray(PdfName.DEST);
                      if (d != null &amp;&amp; d.Length == 5 &amp;&amp; PdfName.XYZ.Equals(d.GetAsName(1)))
                      {
                          d[4] = new PdfNumber(150);
                      }
                  }
  
              }
          }
      }
  }
  </code></pre>
  
  <p>Original code in Java is much shorter:</p>
  
  <pre><code>public void manipulatePdf(String src, String dest) throws IOException, DocumentException {
          PdfReader reader = new PdfReader(src);
          PdfDictionary page = reader.getPageN(11);
          PdfArray annots = page.getAsArray(PdfName.ANNOTS); 
          for (int i = 0; i &lt; 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 &amp;&amp; d.size() == 5 &amp;&amp; PdfName.XYZ.equals(d.getAsName(1)))
                      d.set(4, new PdfNumber(0));
              }
          }
          PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
          stamper.close();
      }
  </code></pre>
  
  <p><strong>UPDATED EDIT 2</strong></p>
  
  <p>Thanks to @mkl I've came up with solution.</p>
  
  <pre><code>for (int i = 1; i &lt;= reader.NumberOfPages; i++)
  {
      PdfDictionary page = reader.GetPageN(i);
  
      PdfArray annotsArray = page.GetAsArray(PdfName.ANNOTS);
  
      if (annotsArray == null)
      {
          continue;
      }
  
      for (int j = 0; j &lt; annotsArray.Size; j++)
      {
          PdfDictionary annotation = annotsArray.GetAsDict(j);
  
          PdfDictionary annotationAction = annotation.GetAsDict(PdfName.A);
          if (PdfName.GOTO.Equals(annotationAction.Get(PdfName.S)))
          {
              PdfArray d = annotationAction.GetAsArray(PdfName.D);
              if (d != null)
              {
                  Console.WriteLine(d[4]);
                  d[4] = new PdfNumber(1.20);
              }
  
          }
  
      }
  }    
  </code></pre>