You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Bhavesh Kharwa (JIRA)" <ji...@apache.org> on 2019/05/14 12:15:00 UTC

[jira] [Created] (PDFBOX-4547) PDFRendtion : Infinite loop

Bhavesh Kharwa created PDFBOX-4547:
--------------------------------------

             Summary: PDFRendtion : Infinite loop
                 Key: PDFBOX-4547
                 URL: https://issues.apache.org/jira/browse/PDFBOX-4547
             Project: PDFBox
          Issue Type: Bug
    Affects Versions: 2.0.15
            Reporter: Bhavesh Kharwa


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: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org