Sign in to follow this  
Followers 0
WalmartCart

AutoIT - Word Document Image Import/Insert as a Binary String

8 posts in this topic

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!

Share this post


Link to post
Share on other sites



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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 :bike:

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 by WalmartCart

Share this post


Link to post
Share on other sites

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Yup, but we cannot paste the data from the clipboard to word in background. Because we cannot specify where to paste.

Share this post


Link to post
Share on other sites

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0