Linked images in RTF?

General TRichView support forum. Please post your questions here
Post Reply
whisper1980
Posts: 11
Joined: Sun May 25, 2025 6:41 pm

Linked images in RTF?

Post by whisper1980 »

Still evaluating the trial so I don't have the source yet to dig into it, but does the TRichViewEdit support the concept of linked images, where the image is not embedded in the RTF but instead can contain something like a link describing an external image in a database for which I can parse out from an event like OnImportPicture and pull the image from the database and display in the editor as if it was embedded? Then when saving the RTF back into the database, the images are not embedded in the RTF, just the original image link (or newly added image link from taking a photo for example, and somehow added as a linked image) is retained?

I did see OnImportPicture, which looks to be what I want to be able to pull the image out of the database, but not sure on the method used in TRichViewEdit to get that to be added into the RTF that would invoke OnImportPicture, and again to not save the retrieved image as part of the RTF, just retain the link. (I didn't see in the Help on how to add/insert a linked image). I also would like to see the RTF format so I can convert my existing RTF from the WPTools linked image format into TRichView linked image format, without having to go thru the RTF spec and try to figure it out :D

Eric
Sergey Tkachenko
Site Admin
Posts: 17844
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Linked images in RTF?

Post by Sergey Tkachenko »

1. As for RTF import:
External images are supported. These images are inserted when reading 'INCLUDEPICTURE' or 'IMPORT' RTF fields.
If the referred picture is local, it is loaded automatically. If it is on a remote location, you need to use OnImportPicture event (but, if you use RichViewActions, it's enough to assign TRVControlPanel.DownloadInterface).

Can you distinguish these pictures after loading? Yes, if rvoAssignImageFileNames is included in TRichView.Options.
In this case, the image file name is stored in rvespImageFileName property of the picture item.

2. As for saving.

For RTF, TRichView does not support saving external pictures (all pictures are stored inside RTF file). However, it can be implemented using OnSaveItemToFile event. The example can be found in TRichView demos, Demos'DelphiUnicode\Assorted\Graphics\SharedImages\

If you need information about external images in other formats supported by TRichView, let me know.
whisper1980
Posts: 11
Joined: Sun May 25, 2025 6:41 pm

Re: Linked images in RTF?

Post by whisper1980 »

Thanks, Sergey.

The loading of the image works great.

As for saving, I copied the code from that sample you pointed me to for SaveItemToFile and it looks like it would work, but unfortunately, FileName is blank after the call to RVData.GetItemExtraStrProperty. Therefore, I can't reload the image since the INCLUDEPICTURE name is now blank. FWIW, the images are Jpeg.

The original INCLUDEPICTURE field looks like this:

Code: Select all

{\field{\*\fldinst INCLUDEPICTURE "IMG_4704.jpg?home=0&id=157&w=4320&dw=1440" \\d }}
This is so I can parse off the ID for the database lookup as well as the display width, and the graphic gets loaded from a stream using RVGraphicHandler.LoadFromStream(vReportImage.Image)

Maybe because it comes from a stream it doesn't have a FileName?

Eric
whisper1980
Posts: 11
Joined: Sun May 25, 2025 6:41 pm

Re: Linked images in RTF?

Post by whisper1980 »

Whoops. I seem to have missed an option under Options: rvoAssignImageFileNames
Post Reply