You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Jon Wu <jo...@wuservices.com> on 2015/08/27 02:56:38 UTC

Black background rendering an ARGB BufferedImage after upgrading to recent 2.0.0

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);

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

Re: Black background rendering an ARGB BufferedImage after upgrading to recent 2.0.0

Posted by John Hewson <jo...@jahewson.com>.
> On 26 Aug 2015, at 17:56, Jon Wu <jo...@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


Re: Black background rendering an ARGB BufferedImage after upgrading to recent 2.0.0

Posted by Brzrk One <br...@gmail.com>.
"Every PDF is unique..."

Tilman, that's a keeper, bound to be a classic!
:)
Pat


On Fri, Aug 28, 2015 at 3:25 AM, Tilman Hausherr <TH...@t-online.de>
wrote:

> 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 <THausherr@t-online.de
>> <ma...@t-online.de>> 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
>>         <tel: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
>>     <ma...@pdfbox.apache.org>
>>     For additional commands, e-mail: users-help@pdfbox.apache.org
>>     <ma...@pdfbox.apache.org>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>
>

Re: Black background rendering an ARGB BufferedImage after upgrading to recent 2.0.0

Posted by Tilman Hausherr <TH...@t-online.de>.
Hi Jon,

https://issues.apache.org/jira/browse/PDFBOX-2949
created. I'm somewhat undecided about what to do. Lets see what John 
Hewson thinks.

Tilman

Am 28.08.2015 um 19:30 schrieb Jon Wu:
> Sorry about that, here's the files:
> https://drive.google.com/folderview?id=0B0sKf6PlTlwgfjhxdDRTSVd1NFZiQXVzbzZ5bDBZc3hzZDNoeWhnTUp6ZS0zbElZMi1QUk0&usp=sharing
>
> On Fri, Aug 28, 2015 at 12:25 AM, Tilman Hausherr <TH...@t-online.de>
> wrote:
>
>> 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 <THausherr@t-online.de
>>> <ma...@t-online.de>> 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
>>>          <tel: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
>>>      <ma...@pdfbox.apache.org>
>>>      For additional commands, e-mail: users-help@pdfbox.apache.org
>>>      <ma...@pdfbox.apache.org>
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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


Re: Black background rendering an ARGB BufferedImage after upgrading to recent 2.0.0

Posted by Jon Wu <jo...@wuservices.com>.
Sorry about that, here's the files:
https://drive.google.com/folderview?id=0B0sKf6PlTlwgfjhxdDRTSVd1NFZiQXVzbzZ5bDBZc3hzZDNoeWhnTUp6ZS0zbElZMi1QUk0&usp=sharing

On Fri, Aug 28, 2015 at 12:25 AM, Tilman Hausherr <TH...@t-online.de>
wrote:

> 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 <THausherr@t-online.de
>> <ma...@t-online.de>> 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
>>         <tel: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
>>     <ma...@pdfbox.apache.org>
>>     For additional commands, e-mail: users-help@pdfbox.apache.org
>>     <ma...@pdfbox.apache.org>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>
>

Re: Black background rendering an ARGB BufferedImage after upgrading to recent 2.0.0

Posted by Tilman Hausherr <TH...@t-online.de>.
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 
> <THausherr@t-online.de <ma...@t-online.de>> 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
>         <tel: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
>     <ma...@pdfbox.apache.org>
>     For additional commands, e-mail: users-help@pdfbox.apache.org
>     <ma...@pdfbox.apache.org>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Black background rendering an ARGB BufferedImage after upgrading to recent 2.0.0

Posted by Jon Wu <jo...@wuservices.com>.
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.

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 <TH...@t-online.de>
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
>
>

Re: Black background rendering an ARGB BufferedImage after upgrading to recent 2.0.0

Posted by Tilman Hausherr <TH...@t-online.de>.
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