首页 > 解决方案 > 如何使用 PDFBox PDInlineImage

问题描述

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

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();

标签: javapdfbox

解决方案


推荐阅读