gpt4 book ai didi

java - 在java中将所有PDF页面转换为单个图像

转载 作者:行者123 更新时间:2023-11-30 09:15:52 25 4
gpt4 key购买 nike

在 java 中将所有 PDF 页面转换为单个图像
我有一个 700KB 的 pdf 文件,我想将其转换为缩小尺寸的单个图像。我在下面尝试过。我正在使用 PDFBox

PDDocument document = PDDocument.loadNonSeq(file,null);

List<PDPage> pages = document.getDocumentCatalog().getAllPages();
int i =0;
for ( PDPage page : pages ) {
BufferedImage image = page.convertToImage();
BufferedImage imageBW = new BufferedImage(image.getWidth(),
image.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
Graphics g = imageBW.getGraphics();
g.drawImage(image, 0, 0, null);
g.dispose();
java.io.File file1 = new
java.io.File(("D:\\FTPUploads\\GuestSupply_"+i+".jpg"));

ImageIO.write(imageBW, "jpg", file1);
i++;
}

But there difference found is only 10 KB and here it created into 2 images (pdf having 2 pages) i need it in single image. Could you please help me out on this.

最佳答案

ImageMagick是一个用于创建、编辑、合成或转换位图图像的软件套件。它具有连接图像的选项。ImageMagick 的功能通常通过命令行或 Im4java 使用。是 ImageMagick 命令行的纯 Java 接口(interface)。它在 Apache 2.0 许可下分发。

因此,首先使用 PDFBox 将每个 PDF 页面转换为单独的图像,然后使用 ImageMagick 组合所有图像。

引用: http://www.imagemagick.org/Usage/layers/

关于java - 在java中将所有PDF页面转换为单个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19679219/

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