第一次发帖,多多包涵...
我有两个问题。首先,我想知道如何使用 BufferedImage 将图像添加到 PDFBox 2.0 文档。此处已提出问题:Add BufferedImage to PDFBox document
PDFBox 已经从整体上排除了 PDJpeg 类和 xobject 部分。
第二,如果有人已经问过这个问题并且已经回答了,但是这个答案被弃用了;更新/连接这两个问题的最佳方式是什么? (我没有任何积分,所以我无法发表评论)。
最佳答案
PDFBox has since excluded the PDJpeg class and the xobject section as a whole.
在版本 2 的开发过程中确实进行了大量的重构(以及重新重构和重新重构等),并且这种重构通常不仅仅是包更改。很多时候某些功能现在在哪里并不明显。
但是像向文档添加BufferedImage
这样的基本功能可以指望不会丢失。
现在有 JPEGFactory它提供了从 BufferedImage
创建图像 XObjects 的方法,特别是:
/**
* Creates a new JPEG Image XObject from a Buffered Image.
* @param document the document where the image will be created
* @param image the buffered image to embed
* @return a new Image XObject
* @throws IOException if the JPEG data cannot be written
*/
public static PDImageXObject createFromImage(PDDocument document, BufferedImage image)
/**
* Creates a new JPEG Image XObject from a Buffered Image and a given quality.
* The image will be created at 72 DPI.
* @param document the document where the image will be created
* @param image the buffered image to embed
* @param quality the desired JPEG compression quality
* @return a new Image XObject
* @throws IOException if the JPEG data cannot be written
*/
public static PDImageXObject createFromImage(PDDocument document, BufferedImage image, float quality)
/**
* Creates a new JPEG Image XObject from a Buffered Image, a given quality and DPI.
* @param document the document where the image will be created
* @param image the buffered image to embed
* @param quality the desired JPEG compression quality
* @param dpi the desired DPI (resolution) of the JPEG
* @return a new Image XObject
* @throws IOException if the JPEG data cannot be written
*/
public static PDImageXObject createFromImage(PDDocument document, BufferedImage image, float quality, int dpi)
关于java - 将 BufferedImage 添加到 PDFBox 2.0 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36367622/