Jump to content

create picture in an rtf file


Recommended Posts

is it possible to insert a picture in a file like a rich text document, but not .docx like instead rtf or what ever, because right now I use excel for all my data and picture storage, but that would require a user to have excel installed on his machine, so instead if I can create another file the user wouldnt need excel installed on his machine.

[u]My dream is to have a dream...[/u]

Link to comment
Share on other sites

Try this:

#include <ScreenCapture.au3>
#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>

_ScreenCapture_Capture(@ScriptDir & "Image4RTF.bmp", 0, 0, 400, 400)
Global Const $width = 642
Global Const $height = 540
Global Const $hGUI = GUICreate("GFX in RTF by UEZ", $width, $height)
Global $hRichEdit = _GUICtrlRichEdit_Create($hGUI, "", 8, 8, 625, $height - 16, BitOR($ES_MULTILINE, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL))
_GUICtrlRichEdit_SetBkColor($hRichEdit, 0xFBFDFB)
_GUICtrlRichEdit_SetParaAlignment($hRichEdit, "c")
_GUICtrlRichEdit_AppendText($hRichEdit, "{rtf1utf8{colortbl;red16green16blue16;}cf1 {fs24 {b This is a RTF Demo}}cf0 line line }")
$hFile = FileOpen(@ScriptDir & "Image4RTF.bmp", 16)
$bImage = FileRead($hFile)
FileClose($hFile)

$Image_bin = StringMid($bImage, 31)
$binRtf = '{rtf1{pictdibitmap ' & $Image_bin & '}}'
_GUICtrlRichEdit_AppendText($hRichEdit, $binRtf)
_GUICtrlRichEdit_AppendText($hRichEdit, @LF & @LF)
_GUICtrlRichEdit_AppendText($hRichEdit, "{rtf1utf8{colortbl;red0green128blue0;}cf1 {fs28 {i Coded by UEZ 2012}}cf0 line line }")
GUISetState(@SW_SHOW)


Do
Until GUIGetMsg() = -3

_GUICtrlRichEdit_StreamToFile($hRichEdit, @ScriptDir & "Test.rtf")
_GUICtrlRichEdit_Destroy($hRichEdit)
ShellExecute(@ScriptDir & "Test.rtf")

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

I don't know all the RTF syntax but try to open wordpad and position the image!

As you might see it is not easy to position the image. You have to use space, tab or alignments.

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

  • 1 month later...

Try this:

#include <ScreenCapture.au3>
#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>

_ScreenCapture_Capture(@ScriptDir & "Image4RTF.bmp", 0, 0, 400, 400)
Global Const $width = 642
Global Const $height = 540
Global Const $hGUI = GUICreate("GFX in RTF by UEZ", $width, $height)
Global $hRichEdit = _GUICtrlRichEdit_Create($hGUI, "", 8, 8, 625, $height - 16, BitOR($ES_MULTILINE, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL))
_GUICtrlRichEdit_SetBkColor($hRichEdit, 0xFBFDFB)
_GUICtrlRichEdit_SetParaAlignment($hRichEdit, "c")
_GUICtrlRichEdit_AppendText($hRichEdit, "{rtf1utf8{colortbl;red16green16blue16;}cf1 {fs24 {b This is a RTF Demo}}cf0 line line }")
$hFile = FileOpen(@ScriptDir & "Image4RTF.bmp", 16)
$bImage = FileRead($hFile)
FileClose($hFile)

$Image_bin = StringMid($bImage, 31)
$binRtf = '{rtf1{pictdibitmap ' & $Image_bin & '}}'
_GUICtrlRichEdit_AppendText($hRichEdit, $binRtf)
_GUICtrlRichEdit_AppendText($hRichEdit, @LF & @LF)
_GUICtrlRichEdit_AppendText($hRichEdit, "{rtf1utf8{colortbl;red0green128blue0;}cf1 {fs28 {i Coded by UEZ 2012}}cf0 line line }")
GUISetState(@SW_SHOW)


Do
Until GUIGetMsg() = -3

_GUICtrlRichEdit_StreamToFile($hRichEdit, @ScriptDir & "Test.rtf")
_GUICtrlRichEdit_Destroy($hRichEdit)
ShellExecute(@ScriptDir & "Test.rtf")

Br,

UEZ

Hi UEZ, could you please answer my two questions?

(1) I know that bitmap is the concatenation of the BITMAPINFO structure followed by the actual pixel data, but how do you know the binary data is from 31 in

$Image_bin = StringMid($bImage, 31) ?

(2) How can I insert a JPG picture in a RTF file? Here is the code, and it doesn't works.

#include <ScreenCapture.au3>
#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>
_ScreenCapture_Capture(@ScriptDir & "Image4RTF.jpg", 0, 0, 600, 600)
Global Const $width = 642
Global Const $height = 540
Global $hRichEdit
Global Const $hGUI = GUICreate("test", $width, $height)
Global $hRichEdit = _GUICtrlRichEdit_Create($hGUI, "", 8, 8, 625, $height - 16, BitOR($ES_MULTILINE, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL))
_GUICtrlRichEdit_SetParaAlignment($hRichEdit, "l")
_GUICtrlRichEdit_AppendText($hRichEdit, "Insert jpg to RTF"& @LF & @LF)
$hFile = FileOpen(@ScriptDir & "Image4RTF.jpg", 16)
$bImage = FileRead($hFile)
FileClose($hFile)

$binRtf = '{rtf1{pictjpegblip ' & $bImage & '}}'
_GUICtrlRichEdit_AppendText($hRichEdit, $binRtf)
_GUICtrlRichEdit_AppendText($hRichEdit, @LF & @LF)
_GUICtrlRichEdit_AppendText($hRichEdit, "{rtf1utf8{colortbl;red0green128blue0;}cf1 {fs28 {i Coded by younger007 2012}}cf0 line line }")

_GUICtrlRichEdit_StreamToFile($hRichEdit, @ScriptDir & "Test.rtf")
_GUICtrlRichEdit_Destroy($hRichEdit)
Link to comment
Share on other sites

You can only add bitmaps to the rtf document and the binary data must start at offset 31.

Here a nice documention: http://iubio.bio.indiana.edu/soft/util/rtf/RTF-Spec-1.2.rtf

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

You can only add bitmaps to the rtf document and the binary data must start at offset 31.

Here a nice documention: http://iubio.bio.indiana.edu/soft/util/rtf/RTF-Spec-1.2.rtf

Br,

UEZ

UEZ Thanks very much for your reply and the RTF spec.

Well, the .BMP file size is much bigger than .JPEG, especially when I need to insert dozens of pictures into a single RTF file. Do you have any other suggestions?

Link to comment
Share on other sites

It's not clear if you specifically need rtf file, but if you don't, a lateral thought occurred to me:

If you just want to send someone a mix of images and text, why not use an html doc, with the images and document zipped?

If you use winxzip or similar, you can make it into an executable archive that will unzip the folder and run a command - ie to open the html doc in browser.

William

Link to comment
Share on other sites

It's not clear if you specifically need rtf file, but if you don't, a lateral thought occurred to me: If you just want to send someone a mix of images and text, why not use an html doc, with the images and document zipped? If you use winxzip or similar, you can make it into an executable archive that will unzip the folder and run a command - ie to open the html doc in browser. William

Hi William thanks a lot for your great idea! ;)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...