pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andreas Lehmkühler" <andr...@lehmi.de>
Subject Re: Image is corrupted
Date Thu, 25 Oct 2012 11:02:26 GMT
Hi,


Matthias Brendel <brendel@krumedia.de> hat am 25. Oktober 2012 um 12:42
geschrieben:
> The following example demonstrates that the contentStream conflicts with
> the image. The more elementes are written to the content stream the more
> the image shows garbage.
This is a known issue

> Other people are having the same problem, please see
> http://stackoverflow.com/a/8598054/628696
It also mentions a possible solution for the issue. You have to create the
Image, a PDPixelMap in your case, before opening the contentstream. I know it is
just a workaround, but it works so far.

>    PDDocument document = new PDDocument();
> 
>    PDPage page = new PDPage(PDPage.PAGE_SIZE_A4);
>    document.addPage(page);
>    PDPageContentStream contentStream = new PDPageContentStream(document,
> page);
> 
>    for (int i = 0; i < 1000; ++i) { // the more elements the more the image
> damages
>            contentStream.drawLine(0, 0, 100, 0);
>    }
> 
>    BufferedImage bufferedImage = new BufferedImage(100, 100,
> BufferedImage.TYPE_INT_RGB);
>    PDXObjectImage xObjectImage =  new PDPixelMap(document, bufferedImage);
>    contentStream.drawImage(xObjectImage, 0, 0);
> 
>    contentStream.close();
>    document.save("Example.pdf");
>    document.close();


BR
Andreas Lehmkühler

Mime
View raw message