如何使用PDFBox PDInlineImage

时间:2018-10-26 08:43:47

标签: java pdfbox

我想使用PDInlineImage将图像添加到现有的PDF文档中,但是不显示结果图像,我的代码如下:

PDPageContentStream contentStream = new PDPageContentStream(document, document.getPage(0), PDPageContentStream.AppendMode.APPEND, true, true);
    byte[] bytes = FileUtils.readFileToByteArray(new File("C:\\Users\\Administrator\\Desktop\\1.png"));

COSDictionary cosDictionary = new COSDictionary();

PDInlineImage inlineImage = new PDInlineImage(cosDictionary,bytes,document.getPage(0).getResources());
inlineImage.setStencil(true);
inlineImage.setWidth(100);
inlineImage.setHeight(100);
inlineImage.setInterpolate(true);
contentStream.drawImage(inlineImage, 300,90);
contentStream.close();

0 个答案:

没有答案