PDF转成图片出现异常信息

主席 发布于 2011/12/28 13:31
阅读 1K+
收藏 0

我在网上找了一个例子

用的时候会出现如下信息

2011-12-28 13:27:31,218 INFO [org.apache.pdfbox.pdmodel.font.PDCIDFontType2Font] - Can't read the embedded font Times New Roman
2011-12-28 13:27:31,218 INFO [org.apache.pdfbox.pdmodel.font.PDCIDFontType2Font] - Using font Times New Roman instead
2011-12-28 13:27:31,234 INFO [org.apache.pdfbox.pdmodel.font.PDCIDFontType2Font] - Can't read the embedded font SimSun
2011-12-28 13:27:31,234 INFO [org.apache.pdfbox.pdmodel.font.PDCIDFontType2Font] - Using font SimSun instead

不过还能正常使用 下面是代码

 

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriter;
import javax.imageio.stream.ImageOutputStream;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
public class PdfToImg
{
  public static void main(String[] args) throws IOException {
         PDDocument doc = PDDocument.load("c:\\t1.pdf");
         int pageCount = doc.getPageCount();
         System.out.println(pageCount);
         List pages = doc.getDocumentCatalog().getAllPages();
         for(int i=0;i<pages.size();i++){
             PDPage page = (PDPage)pages.get(i);
             BufferedImage image = page.convertToImage();
             Iterator iter = ImageIO.getImageWritersBySuffix("jpg");
             ImageWriter writer = (ImageWriter)iter.next();
             File outFile = new File(System.getProperty("user.dir")+"\\pdfPicFile\\test"+i+".jpg");
             System.out.println(System.getProperty("user.dir")+i+".jpg");
             FileOutputStream out = new FileOutputStream(outFile);
             ImageOutputStream outImage = ImageIO.createImageOutputStream(out);
             writer.setOutput(outImage);
             writer.write(new IIOImage(image,null,null));
         }
         doc.close();
         System.out.println("over");
     }
}

加载中
0
蟋蟀哥哥
蟋蟀哥哥

报的错应该是说字体文件不能读取啊..

你有设置pdf的字体文件么

返回顶部
顶部