代码改变世界

PDFBox-convertToImage-"type not implemented yet"

2008-05-20 00:54  晓风残月  阅读(5953)  评论(14编辑  收藏  举报

昨天刚在使用PDFBox解析PDF文档中简单介绍了PDFBox的.NET版本使用,今天CSDN就有问PDF转Image的问题。从PDFBox的文档中找到了如何执行此项操作:

使用 PDPage.convertToImage() 方法。

将其转成.NET版本确抛出了 "type not implemented yet" 的 java.lang.UnsupportedOperationException 异常。           

using org.pdfbox.pdmodel;
using org.pdfbox.util;
using org.pdfbox;
using java.awt.image;
 
            PDDocument doc = PDDocument.load(@"F:\temp\512.pdf");
            PDPage page = doc.getDocumentCatalog().getAllPages().get(0) as PDPage;
            BufferedImage thumb = page.convertToImage(); // HERE: throws java.lang.UnsupportedOperationException with "type not implemented yet".
            // ...
       

通过Reflector发现,原来 PDPage.converToImage 方法中使用了一个 BufferedImage 不支持的参数类型(int type)进行构造,不熟悉Java不知道参数意义,应该是 IKVM.GNU.Classpath.dll 没有全部实现 java 库。

没有搭建 java 环境也无法测试 java 版本是否可以运行,在 sourceforg.net 的 pdfbox 论坛留了言,希望后面能够有跟踪发现。

image

 

Update 05/21/2008

由于PDFBox0.7.3.NET使用的IKVM.GNU.ClassPath.dll还有很多未实现的功能(与JDK1.4相比),因此PDFBox很多功能在.NET环境也无法使用。但是根据danielwilsonhttps://sourceforge.net/forum/message.php?msg_id=4972299的回复,正在开发当中的0.7.4版本应该实现了与Image相关转换功能呢。因此只有把希望寄托在 IKVM 身上了,希望新版的IKVM-0.3.6.0.11(PDFBox0.7.3使用的是IKM-0.3.0)使用的GNU.ClassPath实现了更多JDK的兼容性支持。很遗憾的是,虽然成功编译PDFBox.NET ,但是IKVM还是会抛出“Not Implement”异常。

PDDocument doc = PDDocument.load(pdfPath); 
PDPage page = doc.getDocumentCatalog().getAllPages().get(0) as PDPage; 
BufferedImage bufferedImage = page.convertToImage();  
File output =new File(pdfPath + ".jpg"); 
ImageIO.write(bufferedImage, "JPEG", output); // HERE: throws java.lang.Error with "Not implemented".  

不熟悉Java,只能简单的使用ImageIO.write 来输出 BufferedImage,还有其他 ImageWriter  可以用,但是照样是到处“Not implemented”。