Click here to Skip to main content
15,902,939 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,do you know how to extract images from RTF in VB.net? I search some websites and could not find a answer. Hope you could help me. Thanks.
Posted

If you want to do it totally yourself then you will need to read the RTF specification, particularly pictures and parse the contents;

Here is the spec for 1.5; http://www.biblioscape.com/rtf15_spec.htm#Heading49[^]

(Here is a link to the V1.9.1 spec at MS: http://www.microsoft.com/downloads/details.aspx?familyid=dd422b8d-ff06-4207-b476-6b5396a18a2b&displaylang=en&tm[^])

As you will see in the spec, picture are under the \pict control tag, and the tag and all the data are enclosed withinn { } brackets, so it is simple to then pick out the data required. From this you can parse out the sub tags to read the type of image and then reconstruct it by reading the bytes.

Sample rtf file data for a picture element;
{\pict\wmetafile8\picw9604\pich7064\picwgoal5445\pichgoal4005 <br />
010009000003c039020000009739020000000400000003010800050000000b0200000000050000<br />
000c020b016b01030000001e0004........data continues........ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff<br />
ffffffffffffffffffffffffffff000000040000002701ffff030000000000<br />
}
 
Share this answer
 
v2
Comments
shujsj2010 23-Jul-10 2:37am    
Thanks
The simplest way of doing just this is by using rtf property of the richtextbox as below.
RichTextBox1.rtf

for you to save properly, use
RichTextBox1.rtf.Replace("\","\\").
When you use this to save the content of the RichTextBox control, you can now pass it to the Rtf property to display the image
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900