我需要使用Ghost4j创建一个包含多个图像的PDF文件?这真的可能吗?我没有在他们的site...Any中找到任何相关文档,欢迎提出有价值的建议。
发布于 2012-09-27 19:34:51
Ghostscript将PostScript和PDF文件作为输入处理,而不是图像文件格式。也就是说,PostScript是一种编程语言,因此可以用PostScript编写导入工具。作为标准Ghostscript附带的代码,可导入GIF、JPEG、BMP和PCX文件格式(ghostpdl/gs/lib/view_.ps)
但是,我不知道Ghost4j公开了什么(另外,我也不是一个Java程序员),所以我不能告诉你怎么做。
发布于 2012-09-27 18:30:41
我不确定Ghost4j,我是用PDFBox ImageToPDF完成的
实际的代码可以在here中找到,你也可以根据你的需要修改它。
发布于 2014-10-24 07:30:50
以下是使用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 ) );
}
}
}https://stackoverflow.com/questions/12619028
复制相似问题