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