WalmartCart Posted November 26, 2013 Share Posted November 26, 2013 Hi AutoIT folks, Say I have decoded an image into a binary string from a file and I want to import the image onto a .doc Word Document. $sNewString = _Base64Decode($sNewString) $sNewString = BinaryToString($sNewString) ;Now sNewString contains an image in binary format $file = FileOpen("BinaryFile.gif", 1) FileWrite($file, $sNewString) FileClose($file) ;Now I have a .gif file and I choose to use _WordDocAddPicture($oDoc, "BinaryFile.gif", 0, 1, $oRange) The above is what I have been doing: Convert the image into a Binary String Save the string as a .gif, so now the image is in gif format Import the .gif into the .doc file Is there a way to skip the second step? Like this: Convert the image into a Binary String Import the Binary String directly onto the word file (Instead of giving it a filepath, just import the whole string) This way, I would not have to create a image file every time when I want to convert an image from one file and import it onto a word file. Thanks a lot! Link to comment Share on other sites More sharing options...
water Posted November 26, 2013 Share Posted November 26, 2013 Where do you read the image from before you convert it to a binary string? Wouldn't it be possible to transfer using copy&paste? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
WalmartCart Posted November 27, 2013 Author Share Posted November 27, 2013 Hi Water, Where do you read the image from before you convert it to a binary string? Wouldn't it be possible to transfer using copy&paste? The images are read from ~20 .mht files. They are encoded in base64 format. Would "Copy & Paste" be a good idea here? For now, I might just store the ~30 images in $Data[][][] array in BinaryString format, and put them in the Word file by: Ffirst create .gif file and then add to word. Replace the content of the .gif image with next image string Create .gif file again Replace... .. .. This solution works fine at the moment, however, it looks even cooler if I can skip the step. If it cannot be done in this way, I would just stick to the method I just brought up. Thanks. Link to comment Share on other sites More sharing options...
water Posted November 27, 2013 Share Posted November 27, 2013 Never played with that myself. You can either use Copy & Paste or a file (GIF, JPG ...) to include an image in word. If you write the binary string to the clipboard and then manually paste it into word, do you get the correct image? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
WalmartCart Posted November 27, 2013 Author Share Posted November 27, 2013 (edited) Hi, I found this on the other site (http://www.tech-archive.net/Archive/Word/microsoft.public.word.drawing.graphics/2005-05/msg00334.html): No, Word has no way of interpreting graphics data coming in that way. Word needs to use a graphics filter to insert a picture into a document. The graphics filter is only available when inserting a picture from a file saved to disk, or when pasting from the clipboard. Now, I can try the clipboard method but I am not familiar with it yet.... How to copy the string to the clipboard or how to paste from the clipboard to the word at specific range. If you write the binary string to the clipboard and then manually paste it into word, do you get the correct image? I would go look them up now and test it. Would be better if you give me some hints Thanks. Add: Actually, copying onto clipboard is okay, but looks like there is no such a method to paste from clipboard to the range. Would have to use something like send(^v). I think I will just save as .gif and them addpicture from there. Wouldn't be that slow anyways.. Edited November 27, 2013 by WalmartCart Link to comment Share on other sites More sharing options...
water Posted November 27, 2013 Share Posted November 27, 2013 To write the string to the clipboard you could try function _ClipBoard_SetData. I've never used it myself though. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
WalmartCart Posted November 27, 2013 Author Share Posted November 27, 2013 Yup, but we cannot paste the data from the clipboard to word in background. Because we cannot specify where to paste. Link to comment Share on other sites More sharing options...
water Posted November 27, 2013 Share Posted November 27, 2013 Sure you can. If the data you have written to the clipboard can manually be pasted to word as a picture then it can be done by AutoIt in the background as well! My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now