title: Get the page number from document outline (bookmarks)
body: <p>I am using the itext7 library to manipulate some existing PDFs. For some reason, I am not able to get the page number from the outline. I guess I somehow should get it from the <a href="http://itextsupport.com/apidocs/itext7/latest/com/itextpdf/kernel/pdf/navigation/PdfDestination.html" rel="nofollow noreferrer">PdfDestination</a> but cannot find any matching methods in any of its subclasses.</p>
  
  <pre><code>PdfDocument pdfDoc =  new PdfDocument(new PdfReader("example.pdf"));
  var root = pdfDoc.GetOutlines(false);
  foreach (PdfOutline ol in root.GetAllChildren()) {
      Console.WriteLine(ol.GetTitle());
      PdfDestination d =  ol.GetDestination();
      // how to get the page number from the destination object
  }
  </code></pre>
  
  <p>In iText5 I used the <code>SimpleBookmark.GetBookmark(reader)</code> that returned a list of dictionaries containing a "Page" entry - but this functionality seems to have been removed in iText7. </p>
  
  <p><strong>Edit:</strong>
  I had a look at the Net implementation of <a href="http://itextsupport.com/apidocs/itext7/latest/com/itextpdf/kernel/pdf/navigation/PdfExplicitDestination.html#getDestinationPage-java.util.Map-" rel="nofollow noreferrer">PdfExplicitDestination.getDestinationPage()</a> on <a href="https://github.com/itext/itext7-dotnet/blob/develop/itext/itext.kernel/itext/kernel/pdf/navigation/PdfExplicitDestination.cs" rel="nofollow noreferrer">Github</a> (same for <a href="https://github.com/itext/itext7/blob/develop/kernel/src/main/java/com/itextpdf/kernel/pdf/navigation/PdfExplicitDestination.java" rel="nofollow noreferrer">java</a>.  I don't understand the purpose of the parameters to this method. If I pass in null it seems to work on pdfs that only use one level in the outline hierarchy using ToString(). By working I mean that it returns the zero-indexed page number as a string. For PDF the code it does not find the page number (neither for the first level).</p>
  
  <pre><code>PdfDocument pdfDoc =  new PdfDocument(new PdfReader("example.pdf"));
  var root = pdfDoc.GetOutlines();
  foreach (PdfOutline ol in root.GetAllChildren()) {
      Console.WriteLine(ol.GetTitle());
      var d = ol.GetDestination();
      if (d is PdfExplicitDestination) {
          string PageNoStr = d.GetDestinationPage(null).ToString();               
          // this is the content of the method (less the ToString()
          //string PageNoStr = ((PdfArray)d.GetPdfObject()).Get(0).ToString();
          int pageNo;
          if (Int32.TryParse(PageNoStr, out pageNo)) {
              Console.WriteLine("Page is " + pageNo);
          } else  {
              Console.WriteLine("Error page");
          }    
      }
  }
  </code></pre>
  
  <p>So I am still trying to figure this out. </p>