3

我需要使用 Ghost4j 创建一个包含多个图像的 PDF 文件?真的有可能吗?我在他们的网站上没有找到任何相关文档...欢迎任何有价值的建议。

4

3 回答 3

3

Ghostscript 将 PostScript 和 PDF 文件作为输入处理,而不是图像文件格式。也就是说,PostScript 是一种编程语言,因此可以在 PostScript 中编写导入工具。作为标准,Ghostscript 附带导入 GIF、JPEG、BMP 和 PCX 文件格式的代码 (ghostpdl/gs/lib/view___.ps)

但是,我不知道 Ghost4j 暴露了什么(此外,我不是 Java 程序员)所以我不能告诉你如何做到这一点。

于 2012-09-27T11:34:51.157 回答
1

不确定 Ghost4j,我使用PDFBox ImageToPDF

实际代码可以在这里找到,您也可以根据自己的要求进行调整。

于 2012-09-27T10:30:41.450 回答
0

这是使用 Ghost4j 将 pdf 转换为图像的工作示例:

import org.ghost4j.document.DocumentException;
import org.ghost4j.document.PDFDocument;
import org.ghost4j.renderer.RendererException;
import org.ghost4j.renderer.SimpleRenderer;
import java.awt.Image;
import java.awt.image.RenderedImage;
import java.io.File;
import java.util.List;
import javax.imageio.ImageIO;
import java.io.IOException;

public class PdfToIm_G4J {

    public void convertPdfToIm( String pdfFilePath, String imExtension ) throws 
                                     IOException,DocumentException,RendererException

        // load the pdf
        document.load( new File( pdfFilePath ) );     

        // create renderer
        SimpleRenderer renderer = new SimpleRenderer();

        // set resolution (in DPI)
        renderer.setResolution( dpi );

        // render the images
        List<Image> images = renderer.render( document );

        // write the images to file
        for (int iPage = 0; iPage < images.size(); iPage++) {
            ImageIO.write( (RenderedImage) images.get( iPage ), imExtension, 
                            new File( "" + iPage + "." + imExtension ) );
        }

    }    

}
于 2014-10-23T23:30:49.587 回答