Exception when converting tiff file to pdf file with iText

大城市里の小女人 提交于 2019-12-02 00:12:02

iText has a few fallbacks when dealing with invalid or corrupt Tiff files. By default, these fallbacks aren't used, you'll need to explicitly use one of the getinstance() methods with the recoverFromImageError flag set to true if you want iText to try and parse the invalid Tiff files (e.g. http://api.itextpdf.com/itext/com/itextpdf/text/Image.html#getInstance%28byte[],%20boolean%29 )

If this boolean is set to true iText will only throw an error if it exhausted all of its options. This should be a sign to inspect your TIFF file...

Another workaround could be to use TiffImage and bypassing the Image class altogether. TiffImage also uses the recoverFromImageError flag, but it also has an additional flag called "direct" which might also solve your issues. (http://api.itextpdf.com/itext/com/itextpdf/text/pdf/codec/TiffImage.html)

Since there is no code snippet available, I guess you were using below code to read the image.

Image tiffImg=TiffImage.getTiffImage(randomAccessFileOrArrayObj, pageNum);

If so change it to (Add true to try recovering the file)

Image tiffImg=TiffImage.getTiffImage(randomAccessFileOrArrayObj, true, pageNum);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!