Part 1.
I paste 2 images on a richtext edit control:
Then we use SaveDocument() to save as html and use that html as the body for an email we send out.
Any pasted images can be present in the rtf / html as embedded binary image, which is no good in the first place, as most email clients block that anyway, though I'm still thinking of exporting is as an image to disk and then use that.
What does work is the html which holds <img /> tags with a link to a temporary generated image file as a product of the SaveDocument() function.
Ie. <img src="file:///C:/Users/miguel.RSL/AppData/Local/Temp/RTC7AAE.tmp" width="613" height="303" title="RTC7AAE.tmp" alt="[image]" />
or
<img src="file:///C:/Users/miguel.RSL/AppData/Local/Temp/ExportedRtf/temp_Images/temp_5.png" width="157" height="115" style="position:relative;float:left;border:0pt none;z-index:1002;" title="temp_5.png" alt="[image]" /> </p>
<p lang="en-GB" style="text-indent:0pt;margin-top:0pt;margin-bottom:0pt;">
In code we do something like the following to read that temp file and then attach it to the email as a "hidden attachment". In the previous version of the richtext Text Edit control, this either worked or it didn't, depending on where the pasted image was copied from, but it never gave an error.
Now, I'm getting an error because there'll be a link to a non-existing temporary file in the html.
In the code we do something like this (and "Yes, there's a GOTO", I've always had the illusion of doing that :).
ls_text = rte_notedet.copyRTF(false) // not only selected, everything
if isnull(ls_text) then
ls_text = ''
end if
if Len( ls_text) > 0 then
ls_currentDir = GetCurrentDirectory() // later we restore to the active (at this moment) directory.
//v1, mjl, 05/11/19: don't use the signatures folder for the tempFile:
//ls_tempFileName = is_pathSignatures
ls_tempFileName = gnv_app.is_win_temp_dir + "ExportedRtf" // ExportedRtf will be created if it doesn't exist yet.
//T3, mjl, 25/02/16: If the user never made a signature with Outlook, this directory does not exist:
IF NOT DirectoryExists(ls_tempFileName) THEN
if NOT ln_file.of_CreateDirectory(ls_tempFileName) then
GOTO LABEL_EXIT
end if
end if
ls_tempFileName += ('\temp.html')
if FileExists(ls_tempFileName) then
FileDelete(ls_tempFileName)
end if
// For the SaveDocument(), according to the help of PB, ONLY for the type "FileTypeText!" you can use anything else than FileEncodingANSI! ...
// Nevertheless: The resulting file still seems to be utf8. So you cannot set anything else then Ansi when filetype is not , but might get
// something else as a result?
//T3, mjl, 25/02/16: check for write access:
try
if rte_notedet.SaveDocument( ls_tempFileName, FileTypeHTML!, EncodingAnsi!) = -1 then
Messagebox("Information", 'Could not write the temporary file: "' + ls_tempFileName + '", please contact Credica.')
gnv_app.of_debug("u_email.ue_sendmail - Could not write the temporary file")
end if
catch ( runtimeError rrte)
gnv_app.of_debug("u_email.ue_sendmail - Could not write the temporary file - rrte: " + rrte.getmessage() )
return -1
end try
li_fileNum = FileOpen(ls_tempFileName, TextMode!, Read!, Shared!, Append!, EncodingAnsi!) // it's ansi encoded by SaveDocument, but contains utf8! chars ....
ll_bytesRead = FileReadEx(li_FileNum, lb_blob)
FileClose(li_FileNum)
// V3, mjl, 16/12/20: has to be utf8:
//ls_fileContents = string(lb_blob, EncodingAnsi!)
ls_fileContents = string(lb_blob, encodingutf8!) // HAS to be utf8 encoded. utf16le doesn't work and ansi loses all special characters ...
//u3, 16/03/18: image-stuff also works also in pb12.6 (works in pb2017):
//u2, mjl, 19/06/17: add temp images as attachments:
long ll_pos1, ll_pos2
string ls_image, ls_temp
oleobject lole_attachProperty, lole_attachPropertyAccessor
lole_attach = ioutlook_mail.Attachments
ll_pos1 = pos(ls_filecontents, '<img src="file://')
do while ll_pos1 > 0
ll_pos2 = pos(ls_filecontents, '"', ll_pos1 + 17)
if ll_pos2 > 0 then
ls_image = mid(ls_filecontents, ll_pos1 + 17, ll_pos2 - ll_pos1 - 17)
// on pb12.6 we get an extra / after "file://" so if present we take it out:
if left(ls_image, 1) = "/" then
ls_image = mid(ls_image, 2)
end if
end if
// change the img tag to include CID without path
//cid:city.jpg
ls_temp = mid(ls_filecontents, ll_pos2 )
ls_filecontents = mid(ls_filecontents, 1, ll_pos1 + 9)
ls_filecontents += "cid:" + trim(mid(ls_image, lastPos(ls_image, "\") + 1) )
ls_filecontents += ls_temp
// attach the image
if not FileExists(ls_image) then
ls_error[1] = ls_image
gnv_app.inv_error.of_message("file_file_does_not_exist", ls_error[])
else
try
lole_attachProperty = lole_attach.add(ls_image)
//&&lole_attach.Save()
lole_attachPropertyAccessor = lole_attachProperty.PropertyAccessor
lole_attachPropertyAccessor.SetProperty(PR_ATTACH_MIME_TAG /*"http://schemas.microsoft.com/mapi/proptag/0x3712001F" */, "image/jpeg" )
// //Change From 0x370eE001E
lole_attachPropertyAccessor.SetProperty( PR_ATTACH_CONTENT_ID /*"http://schemas.microsoft.com/mapi/proptag/0x3712001F" */, mid(ls_image, lastPos(ls_image, "\") + 1) )
// //Changed from 0x3712001E
ioutlook_mail.PropertyAccessor.SetProperty( PR_HIDE_ATTACH /*"http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/8514000B" */, True)
catch (oleruntimeError oert3)
gnv_app.of_debug("u_email.ue_sendmail - oert3: " + oert3.getmessage() )
end try
end if
// search for more images:
ll_pos1 = pos(ls_filecontents, '<img src="file://', ll_pos2)
loop
// ONLY replace BETWEEN tags "> text <"
// v3, mjl, 11/10/20: convert any multiple consecutive spaces and TABS to a format that will be respected when sending email (has to be done before calling of_fixTabs() ):
// multiple spaces replacement:
ls_fileContents = inv_htmlparser.of_replaceText(ls_fileContents, " ", " ") // replace double spaces with non-breaking-space, but leave the second as a normal space in case the text has to 'break' to next line.
ls_fileContents = inv_htmlparser.of_replaceText(ls_fileContents, " ", " ") // has to be done twice in case of uneven amount of spaces.
// of_fixTabs replaces the TABs; with an "apple tag" so they'll be respected by e-mail clients:
ls_fileContents = inv_htmlparser.of_fixTabs(ls_fileContents)
ioutlook_mail.HTMLBody = ls_fileContents
ChangeDirectory(ls_currentDir) // restore the currentDir to point to the original active directory before call to of_Dirlist()
if ll_bytesRead < 1 then
ls_fileContents = ''
ioutlook_mail.HTMLBody = ls_attachholder + " "
else
ioutlook_mail.HTMLBody = ls_attachholder + ls_fileContents
end if
else
ioutlook_mail.HTMLBody = ls_attachholder + " "
end if
So this is where it goes wrong because the file does not exist:
Not there:
So my guess is that the SaveDocument() function FAILS to write to my ...\appdata\local\temp folder somehow.
The image pasted using winkey+shift+S, does exist:
<img src="file:///C:/Users/miguel.RSL/AppData/Local/Temp/ExportedRtf/temp_Images/temp_4.png" width="307" height="171" style="position:relative;float:left;border:0pt none;z-index:1002;" title="temp_4.png" alt="[image]" />
What calls my attention also, is that one image (the one that I do have), is written to a subfolder "temp_Images" of the Filepath that I used in SaveDocument(), and the other image - that I don't have - is (tried to be) saved in ...appdata\local\temp.
kind regards.
MiguelL
If you want I can show you what happens on teamviewer (I think I have your email somewhere) or I can make a small demo app which might be a better way of doing things. I don't want to abuse of your time.
Thank you.
You are using a different control than the TX 28.0. My "complaint" was that "my magical factor had to be changed for this newer 28 version". In pb 12.6 and pb 2017 R3, my multiplication factor was "5.66" and now it has to be (calculated or not), around using a factor of "6.55":
Now I've tried your code in pb12.6 and 2017 R3 and I have to substract 650. When I use the same code on 2019 R3, then I have to ADD around 3000. So there's a huge difference depending on which version of the TX control is being used (or maybe the powerbuilder version).
In 12.6 and 2017 it comes a lot closer to what you get with that third party product you use. (maybe also the presence of a vertical scrollbar could add a little bit to having to substract 650 units).
Anyway it's not really that important for us at the moment, but I will make a small sample app one of these days.
regards
I'm working with PB 2019 R3. When I change the TextControl version in the application object. I get the same results for X28 and X15.