You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Volker Ullmann (Jira)" <ji...@apache.org> on 2021/02/03 08:18:00 UTC

[jira] [Comment Edited] (PDFBOX-5091) Performance issue when saving PDF to image after upgrading from PDFBox 2.0.20 to 2.0.21

    [ https://issues.apache.org/jira/browse/PDFBOX-5091?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17277796#comment-17277796 ] 

Volker Ullmann edited comment on PDFBOX-5091 at 2/3/21, 8:17 AM:
-----------------------------------------------------------------

Here is our code, a little bit simplified, it has not changed from 2.0.20 to 2.0.22:
{code:java}
final int maxImageWidth = 1280;
final MemoryUsageSetting memoryUsageSetting = 
    MemoryUsageSetting.setupMainMemoryOnly(); 
byte[] pdfContent = loadPdfContent(); // get the bytes of the PDF file 
try (PDDocument document = PDDocument.load(new ByteArrayInputStream(pdfContent), 
                                           memoryUsageSetting)) {
    PDPage firstPage = document.getPage(0); 
    PDFRenderer pdfRenderer = new PDFRenderer(document);
    pdfRenderer.setSubsamplingAllowed(true); 
    PDRectangle cropBox = firstPage.getCropBox();
    float scale = maxImageWidth / cropBox.getWidth();
    BufferedImage image = pdfRenderer.renderImage(0, scale);
    // ...
} catch (Exception ex) { 
    // ...
}
{code}
OS is Windows 10 and the JDK is
 java.runtime.version = 1.8.0_261-b12
 java.vm.name = Java HotSpot(TM) 64-Bit Server VM
 java.vm.vendor = Oracle Corporation


was (Author: vul):
Here is our code, a little bit simplified, it has not changed from 2.0.20 to 2.0.22:
{code:java}
final int maxImageWidth = 1280;
final MemoryUsageSetting memoryUsageSetting = MemoryUsageSetting.setupMainMemoryOnly(); byte[] pdfContent = loadPdfContent(); // get the bytes of the PDF file 
try (PDDocument document = 
         PDDocument.load(new ByteArrayInputStream(pdfContent), memoryUsageSetting)) {
    PDPage firstPage = document.getPage(0); 
    PDFRenderer pdfRenderer = new PDFRenderer(document);
    pdfRenderer.setSubsamplingAllowed(true); 
    PDRectangle cropBox = firstPage.getCropBox();
    float scale = maxImageWidth / cropBox.getWidth();
    BufferedImage image = pdfRenderer.renderImage(0, scale);
    // ...
} catch (Exception ex) { 
    // ...
}
{code}
OS is Windows 10 and the JDK is
java.runtime.version = 1.8.0_261-b12
java.vm.name = Java HotSpot(TM) 64-Bit Server VM
java.vm.vendor = Oracle Corporation

> Performance issue when saving PDF to image after upgrading from PDFBox 2.0.20 to 2.0.21
> ---------------------------------------------------------------------------------------
>
>                 Key: PDFBOX-5091
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-5091
>             Project: PDFBox
>          Issue Type: Bug
>         Environment: JDK 8 on Windows10
>            Reporter: Volker Ullmann
>            Priority: Minor
>         Attachments: single_page.pdf
>
>
> We use PDFBox to save the first page of a PDF as an image to provide a preview of the document. These PDFs can be relatively complex as they may contain ten thousands of objects, especially map data. The results are still fine, but when we upgraded from 2.0.20 to 2.0.21 we had a notable performance decrease. Saving the first page of the attached sample document now takes nearly 20 sec on my developer machine, compared to 4 sec with 2.0.20.
>  
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

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