Skip to main content
Skip table of contents

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.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.