Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating RTF file with a GIF image programmatically

Status
Not open for further replies.

Rajesh Karunakaran

Programmer
Sep 29, 2016
549
MU
Dear all,

I have a RTF file as a template where I have place holder directives like @@_name, @@_age etc.
I have a form with OLE Control.
Now, I am updating the RTF by changing all directives with values from a cursor record and then displaying the RTF content in the OLE control. Works fine.

Now, I want to add an image in the RTF template before displaying that in the OLE Control.
Any idea how we can do that?

Rajesh
 
Rajesh,

Are you asking how to code the image within the RTF? That is, you want to know what codes to insert into the RTF to tell it what image to print?

Or are you asking how you can extract the image from the RTF and place it in your report?

There is some information about how images are encoded in RTF here:
Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,

I think, I have not explain it well.

The RTF is a consent form. The general text is common. There are dynamic portions (say like Name, Age, Mobile etc) as well. I have placed elements (to work similar to fields in report forms) like @@_name, @@_age in the RTF wherever they are to appear. These will be replaced by the actual name, age etc which are coming from a cursor record. This is kind of merging feature. Till here it's working and very much fine.

Now, in the RTF, I need to have a signature also at the bottom. The signature is there already in the PC harddisk as a GIF image. I know the place in the RTF where the signature has to come. But, how can I predefine this in the RTF?

This means, each time the file will be prepared from the RTF template for a different person and hence the corresponding signature has to be inserted at it's predefined place. For text entries, I can use @@_name, @@_age etc and replace with actual texts. But, for images, how do I define a place holder?

Rajesh
 
Well,

Mikes pointer to the RTF encoding of images is what you need. You see it's not that easy as inserting a text. It's also more complex than an HTML img tag.

So you have to dig into this. A simple way to see what the RTF code for an image looks like is to use Wordpad or Word to add an image and then look at the rtf file in notepad to see the RTF code. That canbecome a template for other images.

Chriss
 
Hello,

mabe you can use word automation to insert an image ?
(Record a macro and have a look on it)

Regards
tom
 
Rajesh,

Chris advised you to create a Word document containing an image, and then view the resulting RTF in a text editor to view the image. That's what I just did. Here is an extract of the resulting file:

rtf_h9z1vo.jpg


As you can see, the image is stored as a bitmap rather than a filename. Obviously, it would be very difficult to interpret this data and to write a program to insert it into your RTF. Even if you knew the internal format of your GIF, you would have to allow for the fact that it probably contains meta data and other information apart from the actual image.

Rather than trying to embed the image into the RTF, can you set up your report in such a way that the signature is displayed in a different control from the rest of the form? If you can position the controls correctly, it should be possible to make it obvious that the signature belongs to the form, even though it is held separately.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Again, I am no expert on this, but I did find this link which will probably go some way...

Not in VFP directly


Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Mike,

The link is a fantastic documentation.

Chriss,

Yes, that's exactly what I was doing to figure out how the RTF specifies an image. It's not that easy. There are so many tags and the image itself is not a mere filename but character series (hex it seems).

I think, it's not worth spending time to write code to do all these. So, let me try to figure out some other way to get the final text will all dynamic values filled and a signature attached.

Rajesh

EDIT: Mike, I saw your post with that image of RTF content only after posting this!
 
Mike, Chriss, tom, Griff,

Griff, Thank you for the link.

However, let me try if I can figure out some simple and short methods. Moreover, I need to get the final output in a PDF format. So, If I can manage to put everything in a report form finally, then I can use FoxyPreviewer for PDF generation.

Let me try that.

Rajesh
 
Rajesh,

Given that you want to end up with a PDF, an entirely different option might be to use Word Automation to create the document. You could insert the consent form into the document either using your existing RTF or simply as ordinary text (including the name, age and other variables). You could then insert the signature as a GIF directly into the document.

Given that GIFs support transparency, it should be possible to position the signature in such a way that it appears as part of the form. Once it has been converted to a PDF, it should look completely natural.

This approach might need quite a bit of coding, so you would probably only want to try it if you can't insert the image into the RTF as per your original question. But it might be worth keeping in mind.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Okay, so the image is embedded as hex string.
If you link to a file you only get a symbol displayed. So no (obvious) chance to embed an image with just the file name.

Rajesh said:
Rather than trying to embed the image into the RTF, can you set up your report in such a way that the signature is displayed in a different control from the rest of the form? I

I don't think so, You need the GIF somewhere in the region of the RTF, don't you? I don't think you can put an report ole object for the GIF at the correct place so it prints in the area of the RTF.

So I think you have to create the hexstring to embed an image. You can generate it from a file with
Code:
Transform(CreateBinary(FileToStr('image.gif')))

The problem will be finding out about all the other detail information of the image specified with the RTF tags.

The problem with meta data you won't like to embed in the binary image and finally in the PDF can easily be cared for, if you just convert the image to a new one, that won't keep meta data. You may need to do anyway, because as far as I have read into the topic RTF embedded images must be in uncompressed WMF format.

GdiplusX should be able to do the convert, or imagemagick, didn't you introduce it in your project anyway?

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top