我在谷歌应用引擎上使用pdxbox,我使用修改后的版本与应用引擎(https://stackoverflow.com/a/12342272/2459131)兼容。
但我无法在pdf中添加图片。因为:javax.imageio.ImageIO
是受限制的类
我需要做这项工作:
BufferedImage awtImage = ImageIO.read(new File(image));
我找到了两个可以提供帮助的链接,但我不知道如何使用它: 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
- >在我的项目中导入但com.google.code.appengine.awt.image.BufferedImage
不能在pdfbox的方法中使用
编辑:
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);
谢谢, 弗朗索瓦