12

I have a mht file that contains images and some text. When I open it with notepad++, I see xml and then illegible text which I think are images. Can somebody tell me how can I extract images and text from an mht file using a java program? Thanks.

SomeDude
  • 13,876
  • 5
  • 21
  • 44
  • look at the file format, write a decoder based on that, profit! The content of an MHTML file is encoded as if it were an HTML e-mail message, using the MIME type multipart/related. The first part of the file is normally encoded HTML; subsequent parts are additional resources identified by their original URLs and encoded in base64. http://en.wikipedia.org/wiki/MHTML so basically if you know how to work with that sort of encoding in email you should be able to apply the same to these files. – Paul Collingwood Dec 09 '13 at 17:31
  • Possible duplicate of [Extracting Content from MHT Document](http://stackoverflow.com/questions/1268486/extracting-content-from-mht-document) – Tobias Kienzler Nov 30 '16 at 12:05

2 Answers2

5

It's a bit old, but Open it in Internet Explorer, and save as HTML also do the job

Update:

If you open the .mht file in IE, then save it, with the "Save as type" set to "Webpage, complete (.htm;.html)", then it will create the 'filename.htm' file, as well as a 'filename_files' directory. In that directory will be a lot of .tmp files. For output from the MS "Problem Steps Recorder", these will include among them a bunch of files with '(1)' in the name (as in there might be a 'mhtD3B8.tmp' file as well as a 'mhtD3B8(1).tmp' file). The '(1)' files are the images, in .jpg format, simply with a .tmp extension. Search for all the files with '(1)' in the name from that folder, and copy them to a different directory.

Once in the new directory, open a cmd window pointed there. To change all the extensions at once, type "rename *.tmp *.jpg" (without the quotes) and press Enter. Voila - all the image files are extracted.

As for accessing the text - since the file is now saved as a .htm file, you should be able to open that file in Notepad++ and parse/read it properly there.

Hope this helps!

Evuos
  • 3
  • 2
Calimero100582
  • 832
  • 1
  • 7
  • 13
  • i am finding that all the files without the `1` in their name, eg `mhtD3B8.tmp`, are 0kb, when i open them in code editor, there is no contents. – user1063287 Dec 31 '19 at 08:37
4

There's an open-source perl tool called unmht which should do the job:

The first HTML file in the archive is taken to be the primary web page, the other contained files for "page requisites" such as images or frames. The primary web page is written to the output directory (the current directory by default), the requisites to a subdirectory named after the primary HTML file name without extension, with "_files" appended. Link URLs in all HTML files referring to requisites are rewritten to point to the saved files.

zb226
  • 9,586
  • 6
  • 49
  • 79