Thanks for the reply Paulo,

If transparency in Graphics2d should work or mostly like you say then I can figure out what can be done.

Here is a simple code snippet of the general idea;

I want the background to be transparent like it is. The image is just an test image, it can easily be a gif. I've checked but the imageIO doesn't muck up the real image (only if you want to edit :P).

public class Test {

public static void main(String args[]) {

try {

Document document = new Document();

PdfWriter writer = PdfWriter.getInstance(document, intermediateStream);

document.open();

PdfContentByte contentByte = writer.getDirectContent();

DefaultFontMapper mapper = new DefaultFontMapper();

PdfTemplate template = contentByte.createTemplate(240, 170);

Graphics2D g2d = template.createGraphics(240, 170, mapper, true, 1.0);

//test PNG image

//http://images.linux.com/babytux.png

FileInputStream fileInputStream = new FileInputStream("C:/babytux.png");

BufferedImage image = ImageIO.read(fileInputStream);

//if skipped background on GIF and PNG are black

if (image != null && (image.getType() == BufferedImage.TYPE_BYTE_INDEXED || image.getType() == BufferedImage.TYPE_CUSTOM)) {

BufferedImage bufferedImage= new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);

Graphics2D g = bufferedImage.createGraphics();

g.setColor(g.getColor());

g.fillRect(0,0,image.getWidth(),image.getHeight());

g.drawImage(image, 0, 0, null);

g.dispose();

image = bufferedImage;

}

g2d.drawImage(image, 0, 0, 100, 200, null);

g2d.dispose();

contentByte.addTemplate(template, 0, 0);

document.close();

} catch ( Exception e ) {

e.printStackTrace();

}

}

}

Is there something I can try?

Greetings flattened Peter

------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to