You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Andreas Lehmkühler (JIRA)" <ji...@apache.org> on 2019/03/24 13:33:00 UTC

[jira] [Resolved] (PDFBOX-4490) .getNumberofPages() returns incorrect value

     [ https://issues.apache.org/jira/browse/PDFBOX-4490?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andreas Lehmkühler resolved PDFBOX-4490.
----------------------------------------
    Resolution: Fixed

> .getNumberofPages() returns incorrect value
> -------------------------------------------
>
>                 Key: PDFBOX-4490
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4490
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Parsing
>    Affects Versions: 2.0.14
>         Environment: Operating System: Ubuntu 18.04
> Framework: Grails 2.5.6
>            Reporter: Spencer
>            Assignee: Andreas Lehmkühler
>            Priority: Trivial
>             Fix For: 2.0.15, 3.0.0 PDFBox
>
>         Attachments: NeS1078.pdf
>
>
> Uses the following method to return total page numbers:
> {code:java}
> static int pageCount(byte[] document) { withDocument(document) { PDDocument pdf -> pdf.getNumberOfPages() } }
> static Object withDocument(byte[] document, Closure clos) {
>     PDDocument doc
>     try {
>         // Read the PDF file via PdfBox
>         ByteArrayInputStream bais = new ByteArrayInputStream(document)
>         doc = PDDocument.load(bais, MemoryUsageSetting.setupTempFileOnly())
>         // Clone the Closure as a security measureee
>         Closure clone = clos.clone()
>         // Execute the custom processing on the PDDocument
>         clone(doc)
>     } finally {
>         doc?.close()
>     }
> }
> {code}
> When using the attached PDF, it returns a total of two pages.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

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