【问题标题】:Is it possible to create PDF file of Images using Ghost4j?是否可以使用 Ghost4j 创建图像的 PDF 文件?
【发布时间】:2012-09-19 02:24:11
【问题描述】:

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

【问题讨论】:

    标签: java image pdf pdf-generation ghostscript


    【解决方案1】:

    这是一个使用 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 ) );
            }
    
        }    
    
    }
    

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        【解决方案3】:

        不确定 Ghost4j,我是使用 PDFBox ImageToPDF 完成的

        实际代码可以在here找到,你也可以根据自己的需要修改。

        【讨论】:

        • 感谢您的信息,但我真正需要的是使用 ghost4j 创建一个 pdf。您对此有什么想法吗?
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多