pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Hewson <j...@jahewson.com>
Subject Re: Black background rendering an ARGB BufferedImage after upgrading to recent 2.0.0
Date Thu, 27 Aug 2015 20:37:52 GMT

> On 26 Aug 2015, at 17:56, Jon Wu <jon@wuservices.com> wrote:
> 
> 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);

Please look at our examples for how to render pages. You should not be creating your
own PageDrawer, ever.

— John

> --- 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?
> 
> --- 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.
> 
> -- 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.
> 
> 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