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: More questions about page iteration
Date Mon, 15 May 2017 16:13:20 GMT
Am 15.05.2017 um 15:20 schrieb David Patterson:
> I've now got my code working to iterate through a PDDocument and process it
> page by page.
>
> Next hurdle: Is there a way to get the page number as printed? I've got
> page numbers like "TOC-1", "TOC-2", "Page 1", ...
>
> How much work is it to get the "TOC-1"?
>
> Thanks.
>
> Dave Patterson
>

     /**
      * Convenience method to get the page label if available.
      *
      * @param document
      * @param pageIndex 0-based page number.
      * @return a page label or null if not available.
      */
     public static String getPageLabel(PDDocument document, int pageIndex)
     {
         PDPageLabels pageLabels;
         try
         {
             pageLabels = document.getDocumentCatalog().getPageLabels();
         }
         catch (IOException ex)
         {
             return ex.getMessage();
         }
         if (pageLabels != null)
         {
             String[] labels = pageLabels.getLabelsByPageIndices();
             if (labels[pageIndex] != null)
             {
                 return labels[pageIndex];
             }
         }
         return null;
     }


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


Mime
View raw message