2012-09-27 55 views

回答

3

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

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

1

不确定Ghost4j ,我是用PDFBox ImageToPDF

实际的代码可以找到here,你也可以根据你的要求来调整它。

+0

感谢您的信息,但我真正需要的是创建一个使用ghost4j。做你有任何想法PDF? –

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)); 
     } 

    }  

} 
相关问题