pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tilman Hausherr <THaush...@t-online.de>
Subject Re: About Link Annotations
Date Thu, 16 May 2019 15:33:49 GMT
Am 16.05.2019 um 11:40 schrieb Евгений Король:
> Hello. I try to get information from Link Annotation of pdf file. How
> do I know which page link links to? I tried get getCOSObject from
> annotation and parse it for Dest to get page. Perhaps this can be done
> easier?

This code segment from PDFDebugger may help:

     private void collectLinkLocations() throws IOException
     {
         for (PDAnnotation annotation : page.getAnnotations())
         {
             if (annotation instanceof PDAnnotationLink)
             {
                 PDAnnotationLink linkAnnotation = (PDAnnotationLink) 
annotation;
                 PDAction action = linkAnnotation.getAction();
                 if (action instanceof PDActionURI)
                 {
                     PDActionURI uriAction = (PDActionURI) action;
                     rectMap.put(annotation.getRectangle(), "URI: " + 
uriAction.getURI());
                     continue;
                 }
                 PDDestination destination;
                 if (action instanceof PDActionGoTo)
                 {
                     PDActionGoTo goToAction = (PDActionGoTo) action;
                     destination = goToAction.getDestination();
                 }
                 else
                 {
                     destination = linkAnnotation.getDestination();
                 }
                 if (destination instanceof PDNamedDestination)
                 {
                     destination = document.getDocumentCatalog().
findNamedDestinationPage((PDNamedDestination) destination);
                 }
                 if (destination instanceof PDPageDestination)
                 {
                     PDPageDestination pageDestination = 
(PDPageDestination) destination;
                     int pageNum = pageDestination.retrievePageNumber();
                     if (pageNum != -1)
                     {
                         rectMap.put(annotation.getRectangle(), "Page

destination: " + (pageNum + 1));
                     }
                 }
             }
         }
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Mime
View raw message