Search code examples
javatiff

Is possible to read a tif file like a txt, delete some header rows, and save it back to a tif file?


i'm trying to delete the first 3 rows of a tif file content generated by a scanner, because i cant open correctly.

example of rows to delete:

------=_Part_23XX49_-1XXXX3073.1XXXXX20715
ID: documento<br>
MimeType: image/tiff

I have no problem about change the content, but when i save the new file, i cant open correctly again.

System.out.println(new InputStreamReader(in).getEncoding());

this method tell me that the encoding of source file is "Cp1252", so i've put an argument in the JVM (-Dfile.encoding=Cp1252), but nothing appear to change.

This is what i do:

StringBuilder fileContent = new StringBuilder();

// working with content and save result content in fileContent variable 

// save the file again
FileWriter fstreamWrite = new FileWriter(f.getAbsolutePath());
out = new BufferedWriter(fstreamWrite);
out.write(fileContent.toString());

Is possible that something is going wrong with Encoding?

if i do the operation with notepad++, i obtain a correct tiff that i can open without problem.


Solution

  • I found the TIFF Java library that maybe gonna be useful for your requirements.

    Please take a look at the readme how to read and how to write a tiff file.

    Hope this can help you