java - 如何使用 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();
解决方案
推荐阅读
- ruby - 从数组中创建散列,其中值是元素的索引
- android - Kotlin Activity 将书写顺序从左到右更改为从右到左(带有不同语言的电话)
- scala - 与输入字符串匹配的字符串列表
- pom.xml - 我在这个 POM 中的错误是什么以及在哪里?
- python - Pygame 无法加载 PNG 图像
- python - Python 的 time.time 函数在全球范围内的准确性如何?
- jquery - 下拉菜单立即打开
- java - 错误:在加入 2 个流或在 Kafka 中创建 KTable 时出现 librocksdbjni6770528225908825804.dll
- javascript - 将模态存储在变量中并在点击时显示
- jersey - @XmlTransient 不适用于 Json