iText pdf library
Website search

How to avoid an exception when importing a TIFF file?

When I try to convert a specific tiff file to PDF, the following exception occurs:

java.lang.RuntimeException: Scanline must begin with EOL code word.

I can open the tiff file in any image viewer, so it's valid.

Posted on StackOverflow on Apr 22, 2015 by hecatcat

Comment by Bruno: this statement is not always true: I can open the tiff file in any image viewer, so it's valid. A TIFF file can be invalid and open in an image viewer anyway because the image viewer tolerates errors. iText can also tolerate errors, as explained in the answer provided by Michaël Demey (from iText).

iText has a few fall backs 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 getInstance(byte[] imgb, boolean recoverFromImageError)]. If the boolean parameter is set to true, iText will only throw an error if it exhausted all of its options.

Another workaround could be to use the TiffImage class, bypassing the Image class altogether. The TiffImage class also uses the recoverFromImageError flag, but it also has an additional flag called direct which might also solve your issues.

Click this link if you want to see how to answer this question in iText 7.



Ready to use iText?

Try our iText 7 Library and add-ons FREE for 30 days. Test your proof of concept, and see if our solution is right for you.

Get my FREE trial
Contact

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now