pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tilman Hausherr <THaush...@t-online.de>
Subject Re: Black background rendering an ARGB BufferedImage after upgrading to recent 2.0.0
Date Thu, 27 Aug 2015 06:45:28 GMT
Am 27.08.2015 um 02:56 schrieb Jon Wu:
> I'm getting a solid black background trying to convert a PDF to an ARGB
> BufferedImage after updating from 2.0.0-20150209.214830-1071 to
> 2.0.0-20150826.181706-1650. Is there any recent change that could be
> causing that?
>
> --- Working OK on 20150209 ---
>
> On 20150209, I had this and it worked fine - producing a transparent image
> once I converted to PNG using code like this:
>
>      BufferedImage result = new BufferedImage(width, height,
> BufferedImage.TYPE_INT_ARGB);
>      Graphics2D graphics = result.createGraphics();
>      new PageDrawer(new PDFRenderer(document), page).drawPage(graphics,
> mediaBox);

That isn't the way you're supposed to use PDFBox.

>
> --- Updating to latest broke things ---
>
> When updating to the current snapshot, I simply changed the last line to
> use the new API:
>
>      new PDFRenderer(document).renderPageToGraphics(0, graphics);
>
> Unfortunately, with this change + the newer version, I get a black
> background on my BufferedImage instead of a transparent one.
>
> I get the same issue when I do the following:
>
>      new PDFRenderer(document).renderImageWithDPI(0, resolution,
> ImageType.ARGB);
>
> I'd normally think there's something wrong with my code, but this is the
> only change I've made. Is there something wrong with the rendering in the
> latest PDFBox?

The best would be that you upload your PDF somewhere so we can have a 
look at it.

The current code starts with a default bufferedimage of the type you 
pass. Non ARGB images are assigned a white background, the other images 
are kept as is.

>
> --- Workaround ---
>
> With renderPageToGraphics, if I call graphics.setBackground(new Color(0, 0,
> 0, 0)); before rendering the page, I avoid this issue. However, it seems
> like this shouldn't be necessary.

So you're setting a black transparent background.

>
> -- Cropping when rendering? ---
>
> As a side note, I sort of miss being able to conveniently crop the PDF
> before rendering with a rectangle, but maybe I should just be doing that in
> Graphics2D land.

Tilman

>
> Thanks,
> Jon
>


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


Mime
View raw message