Extract an image from a RTF file

B

Bryan.Fodness

I have a large amount of RTF files where the only thing in them is an
image. I would like to extract them an save them as a png.
Eventually, I would like to also grab some text that is on the image.
I think PIL has something for this.

Does anyone have any suggestion on how to start this?
 
T

Terry Reedy

I have a large amount of RTF files where the only thing in them is an
image. I would like to extract them an save them as a png.
Eventually, I would like to also grab some text that is on the image.
I think PIL has something for this.

Does anyone have any suggestion on how to start this?

Wikepedia Rich Text Format has several links, which lead to
http://pyrtf.sourceforge.net/
http://code.google.com/p/pyrtf-ng/
The former says rtf generation, including images.
The latter says rtf generation and parsing, but only claims to be a
rewrite of the former.
 
C

Curt Hash

Wikepedia Rich Text Format has several links, which lead to
http://pyrtf.sourceforge.net/
http://code.google.com/p/pyrtf-ng/
The former says rtf generation, including images.
The latter says rtf generation and parsing, but only claims to be a rewrite of the former.

I've written an RTF parser in Python before, but for the purpose of
filtering and discarding content rather than extracting it.

Take a look at the specification here:
http://www.microsoft.com/downloads/...8d-ff06-4207-b476-6b5396a18a2b&displaylang=en

You will find that images are specified by one or more RTF control
words followed by a long string of hex data. For this special purpose,
you will not need to write a parser for the entire specification. Just
search the file for the correct sequence of control words, extract the
hex data that follows, and save it to a file.

It helps if you open the RTF document in a text editor and locate the
specific control group that contains the image, as the format and
order of control words varies depending on the application that
created it. If all of your documents are created with the same
application, it will be much easier.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top