Return-Path: X-Original-To: apmail-pdfbox-users-archive@www.apache.org Delivered-To: apmail-pdfbox-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EAEE710AA1 for ; Fri, 28 Aug 2015 07:24:18 +0000 (UTC) Received: (qmail 86768 invoked by uid 500); 28 Aug 2015 07:24:18 -0000 Delivered-To: apmail-pdfbox-users-archive@pdfbox.apache.org Received: (qmail 86745 invoked by uid 500); 28 Aug 2015 07:24:18 -0000 Mailing-List: contact users-help@pdfbox.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@pdfbox.apache.org Delivered-To: mailing list users@pdfbox.apache.org Received: (qmail 86732 invoked by uid 99); 28 Aug 2015 07:24:18 -0000 Received: from Unknown (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Aug 2015 07:24:18 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id BB3F0EF04C for ; Fri, 28 Aug 2015 07:24:17 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.553 X-Spam-Level: ** X-Spam-Status: No, score=2.553 tagged_above=-999 required=6.31 tests=[HTML_MESSAGE=3, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-1.427] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id jFWhmwrqLiKs for ; Fri, 28 Aug 2015 07:24:16 +0000 (UTC) Received: from mailout03.t-online.de (mailout03.t-online.de [194.25.134.81]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with ESMTPS id 2B15650702 for ; Fri, 28 Aug 2015 07:24:16 +0000 (UTC) Received: from fwd02.aul.t-online.de (fwd02.aul.t-online.de [172.20.26.148]) by mailout03.t-online.de (Postfix) with SMTP id 1728A65AB8 for ; Fri, 28 Aug 2015 09:24:09 +0200 (CEST) Received: from [192.168.2.102] (r1c3Q2ZTrhJTR48HNKWiDtHhLETs3YOEuMUjIUocxuOVj7uZ0qBMS2waJfZ8LG0gn9@[217.231.147.97]) by fwd02.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-SHA encrypted) esmtp id 1ZVE17-3TTC1A0; Fri, 28 Aug 2015 09:24:05 +0200 Subject: Re: Black background rendering an ARGB BufferedImage after upgrading to recent 2.0.0 To: users@pdfbox.apache.org References: <55DEB208.4050703@t-online.de> From: Tilman Hausherr Message-ID: <55E00CD1.4080705@t-online.de> Date: Fri, 28 Aug 2015 09:25:05 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------010806030002070104000605" X-ID: r1c3Q2ZTrhJTR48HNKWiDtHhLETs3YOEuMUjIUocxuOVj7uZ0qBMS2waJfZ8LG0gn9 X-TOI-MSGID: 1be3161e-d64b-4ba9-a133-feeea6d19999 --------------010806030002070104000605 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Am 28.08.2015 um 07:57 schrieb Jon Wu: > Thanks for the guidance on not creating a PageDrawer. It was already > in our codebase like that and I was adapting without checking examples > until now. Since it was wrong, nevermind what I had before except to > say that I was generating a transparent BufferedImage with it in 1.x > and 2.0.0 from Feb. > > Are both of these correct way to use PDFBox? With either of these on > the latest SNAPSHOT, I'm getting a black background. > > 1. new PDFRenderer(document).renderPageToGraphics(0, graphics); > 2. new PDFRenderer(document).renderImageWithDPI(0, resolution, > ImageType.ARGB); > > With #1, I was able to make it work by writing a transparent > background before renderPageToGraphics, but that is ugly of course. > There's nothing special about the PDF and it works fine with the > latest pdfbox-app.jar. Every PDF is unique... upload your PDF somewhere, binary attachments don't work on the mailing list. Tilman > > Tilman, yes setting a black transparent background doesn't really make > sense as a workaround, but given that I'm basically writing a couple > lines and I'm using ARGB, I don't know what else could be wrong. > > For reference, I attached the PNG I get with my general code on 1.x > and 2.0.0 from Feb (expected), and the black image converted to PNG > that I'm getting with 2.0.0 latest. The PDF to generate these is > attached too. > > > On Wed, Aug 26, 2015 at 11:45 PM, Tilman Hausherr > > wrote: > > 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 > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org > For additional commands, e-mail: users-help@pdfbox.apache.org --------------010806030002070104000605--