gpt4 book ai didi

java - pdfBox 将 pdf 转换为透明图像

转载 作者:行者123 更新时间:2023-11-30 03:36:00 24 4
gpt4 key购买 nike

到目前为止效果很好,但是如何为生成的图像添加透明度?

for (img <- 0 until f.length) {
val inputPdf = PDDocument.load(f(img).getPath).getDocumentCatalog.getAllPages.get(0).asInstanceOf[PDPage]

val outputfile = new File(f(img).getName + ".png")
ImageIO.write(inputPdf.convertToImage(), "png", outputfile)
}

最诚挚的问候托斯顿

最佳答案

尝试使用convertToImage(type, resolution)TYPE_INT_ARGB .

您可以查看convertToImage的代码:http://codenav.org/code.html?project=/org/apache/pdfbox/pdfbox/1.8.4&path=/Source%20Packages/org.apache.pdfbox.pdmodel/PDPage.java (1.8.4) 或 https://svn.apache.org/repos/asf/pdfbox/tags/1.8.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java (1.8.8-当前)

public BufferedImage convertToImage() throws IOException
{
//note we are doing twice as many pixels because
//the default size is not really good resolution,
//so create an image that is twice the size
//and let the client scale it down.
return convertToImage(8, 2 * DEFAULT_USER_SPACE_UNIT_DPI);
}

您可能想使用:

convertToImage(BufferedImage.TYPE_INT_ARGB, 2 * DEFAULT_USER_SPACE_UNIT_DPI);

注意:PDF 支持透明对象。然而,正如 @mkl 所说,它与 pdf 引用不兼容。

关于java - pdfBox 将 pdf 转换为透明图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27863718/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com