[
https://issues.apache.org/jira/browse/PDFBOX-2949?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14720409#comment-14720409
]
Jon Wu commented on PDFBOX-2949:
--------------------------------
I'm pretty sure this is a fault. The PDF has no background and should result in
an image with a transparent background behind the text. Given that it comes out
with a black background, there's no way to keep it transparent.
When you try to write a PNG and get a black background, it often times means
you didn't properly set ARGB so I wonder if something like that could be going
on deeper in the code.
You can't remove the if above because the ARGB result won't be transparent
anymore. My current ugly workaround is to g.setBackground(new Color(0, 0, 0,
0)); before rendering. The color here doesn't matter, it's just that this
forces the background to be fully transparent even after rendering for some
reason.
> Rendering to ARGB brings black background
> -----------------------------------------
>
> Key: PDFBOX-2949
> URL: https://issues.apache.org/jira/browse/PDFBOX-2949
> Project: PDFBox
> Issue Type: Bug
> Affects Versions: 2.0.0
> Reporter: Tilman Hausherr
> Attachments: dora.pdf, doraargb.png, dorargb.png
>
>
> As reported by [~jon_wu] in the user mailing list... instead of the somewhat
> long thread, here's code I tried:
> {code}
> try (PDDocument document = PDDocument.load(new File(dir, "dora.pdf")))
> {
> PDFRenderer pdfRenderer = new PDFRenderer(document);
> BufferedImage bim = pdfRenderer.renderImageWithDPI(0, 300,
> ImageType.RGB);
> ImageIO.write(bim, "png", new File(dir, "dorargb.png"));
> bim = pdfRenderer.renderImageWithDPI(0, 300, ImageType.ARGB);
> ImageIO.write(bim, "png", new File(dir, "doraargb.png"));
> }
> {code}
> PDFRenderer has this:
> {code}
> Graphics2D g = image.createGraphics();
> if (imageType != ImageType.ARGB)
> {
> g.setBackground(Color.WHITE);
> }
> {code}
> We could just remove the line with the "if" and the braces. The question is,
> is the current behaviour a fault or a feature? Note that the ARGB image has a
> detail that is invisible in the RGB image.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]