Page 1 of 1

Idea need for loading/saving/removing images in a RTF

Posted: Thu Jul 26, 2018 9:42 am
by kundm
Hi,

we are using a RichView for editing emails. Those Emails contain a footer with different pictures.
Currently we have stored about 2 million emails. Those footers are really big in sum. Because the often contain the same pictures.
My idea is to extract the images and store them not duplicated in a separated blob database table.

My problems to solve:
1) How to find and extract the images and replace them in RTF with a placeholder.
2) When a rtf is loaded to richview, how to restore those extracted images.

Should i to an parse the RTF?
Is there a more elegant way?
Does the Richview have some helpful function?

Re: Idea need for loading/saving/removing images in a RTF

Posted: Thu Jul 26, 2018 3:31 pm
by Sergey Tkachenko
Possible solutions:

1) You can implement some kind of fields typed directly in text, for example replace text inside {}. After loading the file, you can process codes like {image1} and replace them to actual images. For example, see Mailmerge-Text4 demo

2) RTF files may contain reference to image file instead of the actual image (INCLUDEPICTURE field). When TRichView reads INCLUDEPICTURE field, it calls OnImportPicture event, where you can provide your image. If this event is not processed, TRichView tries to read this picture from file.
TRichView does not have an option to save pictures as references to files in RTF, but you can implement it using OnSaveItemToFile event.
See the demo <TRichView Dir>\TRichView\Demos\DelphiUnicode\Assorted\Graphics\SharedImages\

3) You can change saving format to RVF, exclude rvfoSavePicturesBody from RVFOptions property, and use OnRVFPictureNeeded to provide the image. An example is in the same demo.

Re: Idea need for loading/saving/removing images in a RTF

Posted: Fri Aug 03, 2018 6:51 am
by kundm
I will try these solutions, thank you.