使用JPedal取代PDFBox
????? 之前都是使用PDFBOX0.8版本来实现PDF转为Image,0.8版本的PDFBox转为Image还有N多问题,比如部分扫描PDF无法转换、缺少字体等等问题。而且我们是修改PDFBox源代码来解决上述问题,但是还是不能解决全部问题。
???? JPedal是一个商业的处理PDF软件,但是JPedal有一个裁切版,裁切版JPedal使用LGPL协议进行开源,可免费使用。如下摘抄官方说明:
/** instance of PdfDecoder to convert PDF into image */ PdfDecoder decode_pdf = new PdfDecoder(true); /** set mappings for non-embedded fonts to use */ PdfDecoder.setFontReplacements(decode_pdf);/** open the PDF file - can also be a URL or a byte array */decode_pdf.openPdfFileFromInputStream(in, false);// decode_pdf.openPdfFile("C:/myPDF.pdf", "password"); //encrypted// file// decode_pdf.openPdfArray(bytes); //bytes is byte[] array with PDF// decode_pdf.openPdfFileFromURL("http://www.mysite.com/myPDF.pdf",false);/** get page 1 as an image */// page range if you want to extract all pages with a loop// int start = 1, end = decode_pdf.getPageCount();int pageCount = decode_pdf.getPageCount();if (curPage > pageCount || curPage <= 0)curPage = pageCount;BufferedImage img = null;img = decode_pdf.getPageAsImage(curPage );pageCnt=String.valueOf(pageCount);FileOutputStream out;out = new FileOutputStream(file);JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);encoder.encode(img);out.close();
?
?
1 楼 melin 2011-12-12 我现在最新版本的jpedal,转换为png的时候,中文不能显示。你是怎么处理的?