在转换为TIF时,如何使用类PDPage上的方法convertToImage()来避免Dimension异常

时间:2013-06-14 06:55:42

标签: java exception pdfbox dimension

我有大约500个PDF文档,我需要将其转换为TIF文件。我正在使用Apache PDFBox 1.8.2 API中的PDDocument和PDPage。代码正在处理几乎所有PDF文档,除了大约20个我得到异常的地方:

  

jun 14,2013 8:08:09 AM   org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap getRGBImage   SEVERE:java.lang.IllegalArgumentException:Dimensions(width = 1000000   height = 1000000)java.lang.IllegalArgumentException太大了:   尺寸(宽度= 1000000高度= 1000000)太大了   java.awt.image.SampleModel。(未知来源)at   java.awt.image.ComponentSampleModel。(未知来源)at   java.awt.image.PixelInterleavedSampleModel。(未知来源)at   com.sun.media.imageioimpl.plugins.jpeg2000.J2KRenderedImageCodecLib.createSampleModel(J2KRenderedImageCodecLib.java:741)     在   com.sun.media.imageioimpl.plugins.jpeg2000.J2KRenderedImageCodecLib.createOriginalSampleModel(J2KRenderedImageCodecLib.java:729)     在   com.sun.media.imageioimpl.plugins.jpeg2000.J2KRenderedImageCodecLib。(J2KRenderedImageCodecLib.java:261)at at   com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReaderCodecLib.read(J2KImageReaderCodecLib.java:364)     在javax.imageio.ImageIO.read(未知来源)at   javax.imageio.ImageIO.read(未知来源)at   org.apache.pdfbox.filter.JPXFilter.decode(JPXFilter.java:53)at   org.apache.pdfbox.cos.COSStream.doDecode(COSStream.java:295)at   org.apache.pdfbox.cos.COSStream.doDecode(COSStream.java:237)at   org.apache.pdfbox.cos.COSStream.getUnfilteredStream(COSStream.java:172)     在   org.apache.pdfbox.pdmodel.common.PDStream.createInputStream(PDStream.java:231)     在   org.apache.pdfbox.pdmodel.common.PDStream.getByteArray(PDStream.java:509)     在   org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap.getRGBImage(PDPixelMap.java:185)     在   org.apache.pdfbox.util.operator.pagedrawer.Invoke.process(Invoke.java:83)     在   org.apache.pdfbox.util.PDFStreamEngine.processOperator(PDFStreamEngine.java:554)     在   org.apache.pdfbox.util.PDFStreamEngine.processSubStream(PDFStreamEngine.java:268)     在   org.apache.pdfbox.util.PDFStreamEngine.processSubStream(PDFStreamEngine.java:235)     在   org.apache.pdfbox.util.PDFStreamEngine.processStream(PDFStreamEngine.java:215)     在   org.apache.pdfbox.pdfviewer.PageDrawer.drawPage(PageDrawer.java:125)     at org.apache.pdfbox.pdmodel.PDPage.convertToImage(PDPage.java:781)     在org.apache.pdfbox.pdmodel.PDPage.convertToImage(PDPage.java:712)     在dk.atkins.sa.creator.CreateTIFF.pdf(CreateTIFF.java:142)at   dk.atkins.sa.creator.DocumentIndex.build(DocumentIndex.java:288)at at   dk.atkins.sa.creator.DocumentIndex.run(DocumentIndex.java:204)

     

jun 14,2013 8:08:09 AM   org.apache.pdfbox.util.operator.pagedrawer.Invoke进程警告:   getRGBImage返回NULL

我可以做些什么来避免这种异常?我应该使用替代PDF转换器吗?调用方法convertToImage()时抛出异常。

List<PDPage> pages = document.getDocumentCatalog().getAllPages();
for (int i = 0; i < pages.size(); i++) {
    FileOutputStream fos = null;
    ByteArrayOutputStream baos = null;
    ImageOutputStream ios = null;
    try {
        PDPage page = pages.get(i);
        BufferedImage thisImage = page.convertToImage();
        ...

抱怨:异常会在PDFBox API中抛出,并在PDFBox API中捕获,因此我没有机会突出显示任何问题。

0 个答案:

没有答案