1

I'm using pdxbox on google app engine, I use modifed version to be compatible with app engine (https://stackoverflow.com/a/12342272/2459131).

But I'm not able to add image in pdf. Because : javax.imageio.ImageIO is a restricted class

I need to make this work :

BufferedImage awtImage = ImageIO.read(new File(image));

I found two link that can help but I don't know how to use it : https://github.com/pascalleclercq/appengine-awt/releases/tag/appengine-awt-1.0.0

http://mvnrepository.com/artifact/fr.opensagres.xdocreport.appengine-awt/appengine-awt/1.0.0 --> import in my project but com.google.code.appengine.awt.image.BufferedImage cannot be use in pdfbox's method

Edit :

PDDocument document = new PDDocument();

PDPage tmp = (PDPage) PDDocument.load("WEB-INF/pdfs/TemplateFactureEmpty3.pdf").getDocumentCatalog().getAllPages().get(0);
document.addPage(tmp);
PDPageContentStream content = new PDPageContentStream(document, tmp, true, true);

// choice 1 , pb : call ImageIO restricted
InputStream in = new FileInputStream(new File("WEB-INF/CokeLogo1.png"));
PDJpeg ximage = new PDJpeg(document, in);

// choise 2 , pb : BufferedImage and ImageIO restricted
BufferedImage awtImage = ImageIO.read(new File("WEB-INF/CokeLogo1.png") );
PDXObjectImage ximage = new PDPixelMap(document, awtImage);

float scale = 1f; // alter this value to set the image size
content.drawXObject(ximage, 56, 800, ximage.getWidth() * scale,ximage.getHeight() * scale);

Thanks, Francois

Community
  • 1
  • 1
Kingstone59
  • 183
  • 3
  • 14

0 Answers0