Can anyone assist me with programmatically adding image to and RTF. I have read through RTF spec and when it comes to the pict and image sections it all turns into Greek. Ideally, I would simply point to a graphic file and call it a day. My environment is ASP, IIS 5/6. I have had great success formatting documents, inserting DB info but I need to add a logo to the header and can’t get past it. Any help would be greatly appreciated.
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Programmatically Add Image to RTF (2000)
Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Programmatically Add Image to RTF (2000)
- This topic has 7 replies, 3 voices, and was last updated 21 years ago.
AuthorTopicWSverticalanswer
AskWoody LoungerJune 3, 2004 at 9:17 pm #405753Viewing 0 reply threadsAuthorReplies-
WSjscher2000
AskWoody Lounger -
WSverticalanswer
AskWoody Lounger -
WSAndrew77
AskWoody LoungerJune 4, 2004 at 3:38 am #836257From “RTF: Pocket Guide,” published by (who else) O’Reilly & Associates:
[indent]
Embedding Images
In an ideal world, RTF would allow you to insert a picture into a document by simply dropping a hex-encoded GIF, JPEG, or PNG file into your RTF code. But RTF doesn’t do things that way. The RTF specification, on the subject of pictures, explains a {pict…} construct that contains picture data (typically as a long series of hexadecimal digits). But the picture data encoded in the {pict…} construct is in a binary format that can’t be converted to easily from a conventional image format (i.e., GIF, JPEG, or PNG).
If you want to insert images in an RTF file, you have three options.The first option is to give up and do without the image. In many cases, the image isn’t necessary (as with a company logo on an invoice document).
The second option is to produce the binary encoding of the image by copying it out of an RTF file generated by a word processor. So if you want to insert a logo in an invoice that you’re autogenerating as RTF, you could start AbiWord (for example), start a new blank file, insert a picture from disk, save the file as .rtf, and then open the .rtf file in a text editor. For example, inserting a 2 x 2 blue dot in AbiWord produces an RTF file that ends like this:
pardplainltrpars15{*shppict {pictpngblippicw2pich2picwgoal28pichgoal28 bliptag10000{*blipuid 00000000000000000000000000002710} 89504e470d0a1a0a0000000d4948445200000002000000020403000000809810 1700000030504c54450000008000000080008080000000808000800080808080 80c0c0c0ff000000ff00ffff000000ffff00ff00ffffffffff7b1fb1c4000000 0c49444154789c6338c3700600033401997bc924ce0000000049454e44ae4260 82}}{f4fs24lang1033{*listtag0}}}
This image could be copied into other documents by copying the {pict…} group and inserting it directly into another document as needed. (Note that it must be copied from {pict up to the next matching }, not just the next }. Otherwise, you end up stopping prematurely, at the end of the third line above.)
The third way to insert images in an RTF file is to use this quite nonstandard code to have the word processor insert an arbitrary external image file into the document:{fieldfldedit{*fldinst { INCLUDEPICTURE d "PicturePath" * MERGEFORMATINET }}{fldrslt { }}}
In the PicturePath, path separators must either be a forward slash, like so:
{fieldfldedit{*fldinst { INCLUDEPICTURE d "C:/stuff/Group_x/images/alaska_map.gif" * MERGEFORMATINET }}{fldrslt { }}}
or must be a double-backslash, escaped (either as ‘5c’5c or as ), like so:
{fieldfldedit{*fldinst { INCLUDEPICTURE d "C:'5c'5cstuff'5c'5cGroup_x'5c'5cimages'5c'5calaska_map.gif" * MERGEFORMATINET }}{fldrslt { }}}
or:
{fieldfldedit{*fldinst { INCLUDEPICTURE d "C:stuffGroup_ximagesalaska_map.gif" * MERGEFORMATINET }}{fldrslt { }}}
At time of this writing, this whole image-via-field construct seems to be particular to MSWord versions, beginning with Word 2000. Other word processors either just ignore the construct (as AbiWord, Wordpad, and others do), or they throw an error (like MSWord Viewer 97, which replaces the image with the text “Error! Unknown switch argument”).
You can control exact positioning of an image on the page by simply making it the content of an exact-positioned paragraph, as discussed at the end of the “Basic RTF Syntax” section. For example, this image’s top-left corner starts 2,160 twips across and 3,600 twips down from the page’s top-left corner:{pard pvpgphpg posx2160 posy3600 field...} or {pict...} par}
[/indent]
Sounds like Option 2 might work for you.
BTW, I highly recommend that book if you regulary work in RTF. (Hey, it’s only $12.95)
HTH!
-
WSverticalanswer
AskWoody Lounger -
WSverticalanswer
AskWoody Lounger
-
-
WSAndrew77
AskWoody LoungerJune 4, 2004 at 3:38 am #836258From “RTF: Pocket Guide,” published by (who else) O’Reilly & Associates:
[indent]
Embedding Images
In an ideal world, RTF would allow you to insert a picture into a document by simply dropping a hex-encoded GIF, JPEG, or PNG file into your RTF code. But RTF doesn’t do things that way. The RTF specification, on the subject of pictures, explains a {pict…} construct that contains picture data (typically as a long series of hexadecimal digits). But the picture data encoded in the {pict…} construct is in a binary format that can’t be converted to easily from a conventional image format (i.e., GIF, JPEG, or PNG).
If you want to insert images in an RTF file, you have three options.The first option is to give up and do without the image. In many cases, the image isn’t necessary (as with a company logo on an invoice document).
The second option is to produce the binary encoding of the image by copying it out of an RTF file generated by a word processor. So if you want to insert a logo in an invoice that you’re autogenerating as RTF, you could start AbiWord (for example), start a new blank file, insert a picture from disk, save the file as .rtf, and then open the .rtf file in a text editor. For example, inserting a 2 x 2 blue dot in AbiWord produces an RTF file that ends like this:
pardplainltrpars15{*shppict {pictpngblippicw2pich2picwgoal28pichgoal28 bliptag10000{*blipuid 00000000000000000000000000002710} 89504e470d0a1a0a0000000d4948445200000002000000020403000000809810 1700000030504c54450000008000000080008080000000808000800080808080 80c0c0c0ff000000ff00ffff000000ffff00ff00ffffffffff7b1fb1c4000000 0c49444154789c6338c3700600033401997bc924ce0000000049454e44ae4260 82}}{f4fs24lang1033{*listtag0}}}
This image could be copied into other documents by copying the {pict…} group and inserting it directly into another document as needed. (Note that it must be copied from {pict up to the next matching }, not just the next }. Otherwise, you end up stopping prematurely, at the end of the third line above.)
The third way to insert images in an RTF file is to use this quite nonstandard code to have the word processor insert an arbitrary external image file into the document:{fieldfldedit{*fldinst { INCLUDEPICTURE d "PicturePath" * MERGEFORMATINET }}{fldrslt { }}}
In the PicturePath, path separators must either be a forward slash, like so:
{fieldfldedit{*fldinst { INCLUDEPICTURE d "C:/stuff/Group_x/images/alaska_map.gif" * MERGEFORMATINET }}{fldrslt { }}}
or must be a double-backslash, escaped (either as ‘5c’5c or as ), like so:
{fieldfldedit{*fldinst { INCLUDEPICTURE d "C:'5c'5cstuff'5c'5cGroup_x'5c'5cimages'5c'5calaska_map.gif" * MERGEFORMATINET }}{fldrslt { }}}
or:
{fieldfldedit{*fldinst { INCLUDEPICTURE d "C:stuffGroup_ximagesalaska_map.gif" * MERGEFORMATINET }}{fldrslt { }}}
At time of this writing, this whole image-via-field construct seems to be particular to MSWord versions, beginning with Word 2000. Other word processors either just ignore the construct (as AbiWord, Wordpad, and others do), or they throw an error (like MSWord Viewer 97, which replaces the image with the text “Error! Unknown switch argument”).
You can control exact positioning of an image on the page by simply making it the content of an exact-positioned paragraph, as discussed at the end of the “Basic RTF Syntax” section. For example, this image’s top-left corner starts 2,160 twips across and 3,600 twips down from the page’s top-left corner:{pard pvpgphpg posx2160 posy3600 field...} or {pict...} par}
[/indent]
Sounds like Option 2 might work for you.
BTW, I highly recommend that book if you regulary work in RTF. (Hey, it’s only $12.95)
HTH!
-
-
WSverticalanswer
AskWoody Lounger
-
Viewing 0 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Is AI Becoming Too Easy to Trust? Where Should We Draw the Line? (Awaiting moderation)
by
Samuel Miz
1 hour, 5 minutes ago -
Is Microsoft Copilot becoming a security risk for sensitive enterprise data? (Awaiting moderation)
by
Samuel Miz
1 hour, 11 minutes ago -
How to get Microsoft Defender to honor Group Policy Setting
by
Ralph
3 hours, 34 minutes ago -
Apple : Paragon’s iOS Mercenary Spyware Finds Journalists Target
by
Alex5723
4 hours, 13 minutes ago -
Music : The Rose Room – It’s Been A Long, Long Time album
by
Alex5723
5 hours, 19 minutes ago -
Disengage Bitlocker
by
CWBillow
6 hours, 43 minutes ago -
Mac Mini M2 Service Program for No Power Issue
by
Alex5723
7 hours, 18 minutes ago -
New Win 11 Pro Geekom Setup questions
by
Deo
9 hours, 3 minutes ago -
Windows 11 Insider Preview build 26200.5651 released to DEV
by
joep517
14 hours, 34 minutes ago -
Windows 11 Insider Preview build 26120.4441 (24H2) released to BETA
by
joep517
14 hours, 35 minutes ago -
iOS 26,, MacOS 26 : Create your own AI chatbot
by
Alex5723
18 hours, 30 minutes ago -
New PC transfer program recommendations?
by
DaveBoston
52 minutes ago -
Windows 11 Insider Preview Build 22631.5545 (23H2) released to Release Preview
by
joep517
22 hours, 35 minutes ago -
Windows 10 Build 19045.6029 (22H2) to Release Preview Channel
by
joep517
22 hours, 36 minutes ago -
Best tools for upgrading a Windows 10 to an 11
by
Susan Bradley
10 hours, 55 minutes ago -
The end of Windows 10 is approaching, consider Linux and LibreOffice
by
Alex5723
8 hours, 17 minutes ago -
Extended Windows Built-in Disk Cleanup Utility
by
bbearren
30 minutes ago -
Win 11 24H2 June 2025 Update breaks WIFI
by
dportenlanger
1 day, 17 hours ago -
Update from WinPro 10 v. 1511 on T460p?
by
CatoRenasci
15 hours, 29 minutes ago -
System Restore and Updates Paused
by
veteran
1 day, 20 hours ago -
Windows 10/11 clock app
by
Kathy Stevens
1 day, 7 hours ago -
Turn off right-click draw
by
Charles Billow
1 day, 23 hours ago -
Introducing ChromeOS M137 to The Stable Channel
by
Alex5723
2 days, 2 hours ago -
Brian Wilson (The Beach Boys) R.I.P
by
Alex5723
20 hours, 44 minutes ago -
Master patch listing for June 10, 2025
by
Susan Bradley
2 days, 4 hours ago -
Suggestions for New All in One Printer and a Photo Printer Windows 10
by
Win7and10
1 day, 7 hours ago -
Purchasing New Printer. Uninstall old Printer Software First?
by
Win7and10
2 days, 10 hours ago -
KB5060842 Issue (Minor)
by
AC641
22 hours, 34 minutes ago -
EchoLeak : Zero Click M365 Copilot leak sensitive information
by
Alex5723
2 days, 17 hours ago -
24H2 may not be offered June updates
by
Susan Bradley
1 day, 10 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.