Btw you (and the person who wrote the stackoverflow question) are drawing an image onto an image. Why would you think that this produces transparancy?

You need to find a way to have it transparent - either because the PNG file has transparent areas (can't remember if this is supported), or by setting the alpha yourself.

Tilman

Am 28.09.2016 um 15:00 schrieb Ján Kaššovic:
Hi all,

I'm trying to insert PNG image with transparent background to PDF using
PDFBox. From what I've read it seems like this should be working, but it is
not. Please, can you help me to achieve this?
It does not necessarily has to be PNG, I am happy to use any common image
type that supports transparency. I am using PDFBox 2.0.0 with

my method is here















* private static void insertImage(PDDocument document, File imageFile,
PDRectangle rectangle) throws IOException {        BufferedImage tmpImage =
ImageIO.read(imageFile);        BufferedImage bufferedImage = new
BufferedImage(tmpImage.getWidth(), tmpImage.getHeight(),
BufferedImage.TYPE_INT_ARGB);
bufferedImage.createGraphics().drawRenderedImage(tmpImage, null);
PDImageXObject image = LosslessFactory.createFromImage(document,
bufferedImage);        PDPage page = document.getPage(0);        try
(PDPageContentStream contentStream = new PDPageContentStream(document,
page, AppendMode.APPEND, true)) {            float x =
rectangle.getLowerLeftX();            float y =
rectangle.getLowerLeftY();            float width =
rectangle.getWidth();            float height =
rectangle.getHeight();            contentStream.drawImage(image, x, y,
width, height);        }    }*

or here http://pastebin.com/6uwpT2Se

The image I use is here https://postimg.org/image/53de24lhh/

It believe it is related to the Stackoverflow question
http://stackoverflow.com/questions/23697046/draw-transparent-png-in-pdfbox

Thanks in advance, hope I did use this mailinglist mechanism correctly ;)

Jan



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to