From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Pulling Images from MS Word & Resizing in Front Panel

I am attempting to pull images from a Microsoft Word document and use them within my Front Panel for a VI I am creating. Since there will be many images the idea is to just draw from the MS Word document and resize them within my front panel. However, I have never worked with 'pulling data' from a MS word document. Any ideas?

0 Kudos
Message 1 of 8
(3,317 Views)
What do you mean by pulling data? Cut and paste? Copying them out programmatically?

If you mean programmatically, there are undoubtedly ways to do it but that is really a MS Word question. Have you checked the Microsoft forums. Find a technique there and then we can figure out how to implement it in LabVIEW.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 8
(3,304 Views)

Hi Mike,

What I mean is copying the images out programmatically into a .JPEG file into a folder, which I would then draw the images from via LabVIEW. I have done as you suggested and looked at the MS forums, but the same problem I ran into is how to exactly implement their code, which is written in C#. The image file returned is a bitmap and my program requires .JPEG files.

I have attached the links for your reference in hopes that you may know of a way to execute this.



Manipulating Word Images Programmatically:
http://www.c-sharpcorner.com/uploadfile/codingexpert/how-to-manipulate-word-images-programmatically/

MS Forum Solution 1:
http://stackoverflow.com/questions/12287908/save-pictures-from-word-to-folder-c-sharp

MS Forum Solution 2:
http://stackoverflow.com/questions/7937487/extract-image-from-word-file

0 Kudos
Message 3 of 8
(3,297 Views)

Well, this sounded interesting, so I also went looking, and found a remarkably simple method that actually works (I tested it).  Here are the unbelievably-simple steps to take:

  1. Make a copy of your Word document, changing the extension to .zip.  [I used an OpenG function to do this].
  2. Use the OpenG function "ZLIB Extract All Files to Dir" to create a Directory folder and extract files and images.  The created Directory folder will have the same name as the Zip file (without the extension, of course).
  3. The images will be placed in the sub-folder "word\media", with filenames "image1", "image2", etc.  My test involved a .jpg image in a test Word document, and the extracted file was "image1.jpg".  Close inspection of the file with a binary editor suggests that it is, indeed, a .jpg file.

Here is a snippet:

Extract Images from Word.png

Bob Schor

Message 4 of 8
(3,281 Views)

Hi Bob,

Thank you for your snippet! I was curious as to whether or not you know of a solution that does not require a Third-Party library to do this? In my test run the VI skipped some of the images within the Doc File and did not create the folder as indicated.

0 Kudos
Message 5 of 8
(3,275 Views)

@AllanIL wrote:

Hi Bob,

Thank you for your snippet! I was curious as to whether or not you know of a solution that does not require a Third-Party library to do this? In my test run the VI skipped some of the images within the Doc File and did not create the folder as indicated.


Well, OpenG has been around for at least a decade, and is one of the first things I download and install from the NI Tools Network (VIPM, the VI Package Manager, is now bundled and installed by default with LabVIEW).  It's pretty easy to write your own function to change the file extension from .docx (or .doc) to .zip.  I'm so used to using OpenG, and knew about their Zip functions, that I forgot (or didn't realize) that LabVIEW also has an Unzip tool.  See if that works for you -- you may need to do some of the work yourself.

 

Bob Schor

 

P.S. -- when you say "In my test run the VI skipped some of the images within the Doc File and did not create the folder as indicated", were you using the OpenG function?  If so, can you attach a sample Word file (no incriminating images, please) that demonstrates this problem?

0 Kudos
Message 6 of 8
(3,260 Views)

OK, I'll admit I'm too lazy to fiddle with the "change file extensions" VIs (I'm not a whiz with Regular Expressions), so I left the OpenG file name manipulation routines in, but did substitute LabVIEW's Zip reader.  I created a directory based on the path and name of the Word/Zip file (by stripping off the extension, seeing if a directory already existed, otherwise creating it), then calling LabVIEW UnZip function, which returns an array of the unzipped files.  Note that the images will show up in the word\media sub-folder, as before.

 

Here's the new Snippet (the old OpenG version is in the Diagram-Disabled case).

Extract Images from Word.png

Bob Schor

Message 7 of 8
(3,257 Views)

Look ma, no OpenG

 

Example_VI_BD.png

 

So a couple of changes.  I don't think making a copy is necessary, just perform the extraction on the .docx file where it is, and I used the native Get File Extension, which returns the file name and extension separately.  Using this to perform an operation like convert file extension should be easy.  Also how cool is it that this format exists?  Totally makes stuff like a lot easier.

 

But I too am a huge fan of OpenG and highly suggest you install it.  The license is BSD and open for use in commercial applications without cost.

Message 8 of 8
(3,251 Views)