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

Bhavesh Kharwa commented on PDFBOX-4547:
----------------------------------------

Hi,

today i have investigate more on this and found that the above code will no 
into infinite loop but it took 45 mins to rendered that image. I have tested 
with jdk version 1.8.0_163

 

After that I have installed jdk version 1.8.0_191 and process the same file. at 
that time it took 10 second to process.

 

> PDFRendtion : Infinite loop
> ---------------------------
>
>                 Key: PDFBOX-4547
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4547
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Rendering
>    Affects Versions: 2.0.15
>            Reporter: Bhavesh Kharwa
>            Priority: Critical
>
> while processing pdf file for generate rendtion, the following method 
> _processStreamOperators_ of *org.apache.pdfbox.contentstream.PDFStreamEngine* 
> class goes into infinite loop. I am using library pdfbox-2.0.15
> {code:java}
>  private void processStreamOperators(PDContentStream contentStream) throws 
> IOException
>     {
>         List<COSBase> arguments = new ArrayList<COSBase>();
>         PDFStreamParser parser = new PDFStreamParser(contentStream);
>         Object token = parser.parseNextToken();
>         while (token != null)
>         {
>             if (token instanceof COSObject)
>             {
>                 arguments.add(((COSObject) token).getObject());
>             }
>             else if (token instanceof Operator)
>             {
>                 processOperator((Operator) token, arguments);
>                 arguments = new ArrayList<COSBase>();
>             }
>             else
>             {
>                 arguments.add((COSBase) token);
>             }
>             token = parser.parseNextToken();
>         }
>     }
> {code}
> Generate rendition code for pdf as below:
> {code:java}
> try (final PDDocument pdf = PDDocument.load(imageBytes)) {
>               if (pdf != null && pdf.getNumberOfPages() > 0) {
>                       PDFRenderer renderer = new PDFRenderer(pdf);
>                       BufferedImage image = renderer.renderImage(0, 1);
>                       final BufferedImage scaledImage;
>                       if (image.getWidth() > rendition.getWidth()) {
>                               scaledImage = 
> Thumbnails.of(image).width(rendition.getWidth()).asBufferedImage();
>                       } else {
>                               scaledImage = image;
>                       }
>                       outputBytes = 
> ImageUtils.writeBufferedImageToBytes(scaledImage, mimeType);
>                               }
>                       }
> {code}



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

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to