Use Powershell to replace text with image in Word document
I have a powershell script that uses a Word document as a template to create signatures that I am pushing out to my organization.
The document is populated with text formatted the way I want the signature to look, that I then do a FindText and ReplaceText on. This works fine for replacing text with text, but I can't figure out how to properly replace some of the holder text with
an image and a link. I found a few posts about adding images to word documents, but none that seem to work properly in this scenario.
Any insight would be greatly appreciated, thanks!
Dear BOFH,
You are correct that method I outlined is not for inserting an image into a signature block (which would be in Outlook, not Word). The links you post do certainly deal with outlook signatures, well done... Except that the question was about how to
use a Powershell script to replace text in a Word document with an image. Sure it was framed in the context of creating signatures, but the poster expressed that they already had a method of generating and replacing text, and just needed to know, as
I did, how to do the thing they actually asked.
Please BOFH... Please forgive my audacity in hoping to find a reference (any reference) to how to replace Word text with images via Powershell in a thread titled "Use Powershell to replace text with image in Word document".
This is certainly a scripting question, and even something as simple as "You will need to call the .NET methods for the Word find/replace functionality. Please ask in the Word forums for the correct method to use.
If you need help on calling .NET methods look HTTP ://here"support you offered combined with the contempt you offer in response to my actual substantive help to the actual question asked.
BOFH, you are not better than us, just more arrogant.
Can you please start your own question as this one has been closed. Please see scripting guidelines.
We cannot guarantee you satisfaction as this is a user supported forum. The is no SLA for community support. Perhaps if you posted a better worded question as a new topic someone might be able to help you resolve your issue.
The topic you are posting on is closed and answered.
¯\_(ツ)_/¯
Similar Messages
-
Search .docx and replace text with image
I've got a directory containing a series of images. The images will always be the same name and I need to insert them into placeholders in a Word document which will be a template. I thought of using the image names as placeholders, opening the document
and searching for the image name, replacing it by inserting the image, and doing so for each image in the directory.
$file is the name of the image in the directory and it loops through them okay.
foreach($file in Get-ChildItem $savepath -Filter *.jpg)
# search word doc and replace selected text with image ($file)
Also inserting the image seems simple enough from a TechNet article I found, but I've got no idea how to open the Word document and do a search and replace. I found a few articles related to the subject but I couldn't get them to work when I tried to adapt
them.
Any help is appreciated. Thanks in advance.This 'might' be possible, but I'm having a hard time finding good references to the com object capabilities for inserting an image into a word document. Creating new, converting format, that sort of thing is straightforward.
I'd do a search on "powershell word comobject" and variations of insert image update edit, etc. Or maybe someone else with more experience/knowledge has a magic bullet for you. Once you get some info on doing it with powershell, expand
your search by omitting the powershell keyword, there's gotta be some solid documentation for the comobject somwhere, but it will probably be a bit complex.
You can also:
$word = new-object -comobject word.application
$doc = $word.documents.add("<path to word document>"
and get-member to your heart's content, but finding references and/or documentation might be easier.
Good luck!
Edit: This could help, but really doesn't give much insight into placement of the image, only helps getting the image into the doc: http://gallery.technet.microsoft.com/office/44ffc6c8-131f-42f1-b24b-ff92230b2e0a
If you do find something useful, post it here, I'm sure others could benefit!
SubEdit: Should have thought of this already...
http://msdn.microsoft.com/en-us/library/ff837519(v=office.14).aspx -
Hi,
I'm using a script found here, to replace @equ001.pdf@ with the corresponding image, same for eq002 etc.
This script works more or less ok for me.
Sometimes, it removes some image names without replacing the image, sometimes it was leaving some "@" here and there.
Sometimes, it's giving me an error on the "place image" code, saying it cannot find the image, giving it's path ending with the grep expression $2 and doesn't work at all.
Sometimes it does part of the job, stops, gives the same error as above, and continues to work when I click ok.
Today, it didn't worked on a document. I copied the text to work on into a new InDesign document an there, it worked (but in two times).
Is there any other way of doing this ?
if(app.documents.length != 0){
var myFolder = Folder.selectDialog ('Choose a folder with images');
if(myFolder != null){
// reset the Find/Change dialog
app.findGrepPreferences = app.changeGrepPreferences = null;
// formulate a grep search string
app.findGrepPreferences.findWhat = '@.+?@';
// find all occurrence, last one first
f = app.activeDocument.findGrep (true);
for (i = 0; i < f.length; i++){
// construct file name
name = f[i].contents.replace (/@/g, '');
// place the image
var placedObjects = f[i].insertionPoints[0].place (File (myFolder.fsName + '/' + name));
// delete all @??@ codes
app.activeDocument.changeGrep();
else{
alert('Please open a document and try again.');You should process the found instances back to front:
for (i = f.length-1; i >= 0; i--)
Peter -
So, I'm a little new to PowerShell and I came across a PowerShell which allow me to copy the content od a spreadsheet, into the new message in Outlook 2007. I have search and search on a way to do the same with a Word Document. I would like to
create a PowerShell Script that copies the content of a Word Document and paste that content in an email message.
I am basing my script on this
#Create and get my Word Obj
$w1 = New-Object -comobject Word.Application
$w1.Visible = $True
$UserWord = $w1.Workbooks.Open("C:\Users\hhhh\Documents\Powershell\test.docx")
#create outlook Object
$Outlook = New-Object -comObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.SentOnBehalfOfName = "[email protected]"
$Mail.Recipients.Add("[email protected]")
#Add the text part I want to display first
$Mail.Subject = "Test email"
$Mail.Body = "My Comment on the Excel Spreadsheet"
#Then Copy the Word using parameters to format it
$Mail.Getinspector.WordEditor.Range().PasteExcelTable($true,$false,$false)
#Then it becomes possible to insert text before
$wdDoc = $Mail.Getinspector.WordEditor
$wdRange = $wdDoc.Range()
$Mail.Display()
Any Help would be great!My requirements are the Word documents are a template of sorts. The document will be changes prior to its email with some changes. The other twist is that the customer might more that one recipients, and each recipient will have to have a separate
email, with the same content of the word document.
For example: Say I'm doing maintenance. The Word doc might descript that maintenance, in a set format. Once save the script is run to generate 3 to 10 email with separate recipients with the body of the email containing what was in the Word document. -
Parsing and replacing text items in a word document?
Hi,
I was wondering if someone could point me in a
good direction as to how I would store word documents
in the database as BLOBs but then be able to open
them in plsql and replace tags with values and
save it as a new document???
Thanks in advance!There are examples in the interMedia User's Guide on loading documents into OrdDoc type objects. Once you do that, you should have a relational interface to the object. Depending on the specific features that the Word plug-in supports, you may be able to edit the document in place via PL/SQL.
I'm more familiar with the OrdImage object, which provides most of the basic image manipulation routines for most image formats. I assume that the OrdDoc object provides a basic document manipulation API as well.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
Replace text with image using Applescript in InDesign CS5
Hi to everyone, i'm looking for some suggestions to resolve my problem.
I've to replace some strings with jpeg images stored on my pc
Here is the code to replace two strings with the new ones.
tell application "Adobe InDesign CS5"
set myDocument to active document
set myPage to page 1 of myDocument
set stringsToReplace to {"111", "222"}
repeat with iterator from 1 to (count stringsToReplace)
set find text preferences to nothing
set change text preferences to nothing
set myFoundItems to nothing
set element to item iterator of stringsToReplace
if element is "111" then
set find what of find text preferences to "111"
set change to of change text preferences to "ONE"
set myFoundItems to change text
display dialog ("Found : " & (count myFoundItems) & " occurences of " & element)
else if element is "222" then
set find what of find text preferences to "222"
set change to of change text preferences to "TWO"
set myFoundItems to change text
display dialog ("Found : " & (count myFoundItems) & " occurences of " & element)
end if
end repeat
set find text preferences to nothing
set change text preferences to nothing
end tell
Can you hel me?
Thanks in advance.Hello, I have a couple of questions for you… How come you have strings in text frames… Would you not be better off using labels for this…? ( thats how I would do this ). Off the top of my head I think you will need to remove any text content from the frame to be able to change it's content type… only then will you be able to place a graphic… How are you associating your strings with the required image files… Do you have this in some extenal file Excel or FMP.
-
Can we replace OTR text with Images?
Hi All,
I just wanted to know can we replace OTR text with Images?
or
Can we define an image as an OTR text? so that it can be placed in the page where OTR text is used.
regards...
RaviHi Ravi,
it is possible to replace an OTR Text with an image.
You first have to define the Link in the OTR Text where your image is located. This can be everywhere in the Internet or better on a secured intranet server which everyone can reach easily without permission problems. Maybe in the DMZ.
You can even link it into the MIME Repository of your SAP System as well.
Then you have to put that OTR Text into a
<htmlb:textview> Tag and ensure that the switch
" encode = "TRUE" is enabled.
Well thats all.
Keep in mind that the a different language, set in the Internet Explorer or other viewing instances, disables the link if it not "translated" into that language.
This can also be an advantage if you got multilingual fixed pictures with drawn text in it.
I suggest you put all your links ( with a Value Field and at least a name field) into a seperate table into the repository for easy maintaining.
Greetings,
Dominik
Edited by: Dominik Lemke on Dec 19, 2007 12:02 PM -
Lion replaces text with 'block A' characters in safari
about 1/4 of the sites i vist now (including my own--in safari) have a 'block A' character where there is html text.
does anyone know how to fix this?
thanks.There are two articles on MacFixit about this.
Fonts are implicated in both.
http://reviews.cnet.com/8301-13727_7-20087102-263/webkit-sandboxing-conflict-cau ses-safari-block-a-font-problem/
http://reviews.cnet.com/8301-13727_7-20085570-263/safari-in-os-x-lion-replacing- text-with-block-a-characters/
Clearing caches and booting to Safe Mode has helped the majority of people experiencing this problem; however, for a few people the problem returns after a while, indicating that either Safari itself or the system's font configuration may be actively corrupting the font cache.
.... (example)
- If this happens, then unfortunately the approach would be to systematically disable system fonts using Font Book until the problem goes away, and then remove the specific fonts that are contributing to the problem. -
Applescript replace text with clipboard
Sorry if this has been asked before, I have been searching for hours and cannot find anything.
what I would like to do is copy text from a safari webpage , swap to the textedit program and replace text with the copied contents.
for eg.
from safari I have copied the user link, I then want it to swap over to textedit, find the keyword "userlink" and replace it with the copied content from safari
userlink
email
number
HHopefully I have explained it correctly, and thanks in advance for any helpHi,
Like this:
set x to the clipboard as «class RTF »
tell application "TextEdit"
set first word of front document whose it = "userlink" to x
end tell
If you want plain text, remove as
as «class RTF » -
Applescript to replace a picture in a Word document
I am trying to create an Applescript to control Microsoft Word to replace a selected image in a document with a new image from a file. The extracted problematic code is below.
-- prior code sets up variables and seems to be working fine.
set {start of content:t_start, end of content:t_end} to text object of selection
set float to shapes of active document whose end of content of its anchor ≥ t_start and end of content of its anchor ≤ t_end
if float is not {} then --replacing a floating image as opposed to an inline image
repeat with pic in float
set a to anchor of pic
set t to top of pic
set l to left position of pic
end repeat -- repeat is not logically necessary but Word seems happier
tell active document
set np to make new picture at a with properties {file name:tfile2, save with document:true}
set relative vertical position of np to rvp
set top of np to t
set left position of np to l
end tell
delete pic
else
-- rest of code handles when no selection exists or the selected image is inline and is working fine.
Everything is working fine - the existing picture is deleted and the new one is inserted and moved to the correct position but always on the FIRST page. The anchor put into a contains the location of the old picture's anchor (which might have a start of content set to 2000 say) but when the new picture is created at a, the new picture is always created with an anchor with a start of content of 0 - regardless of the value in the original anchor.
What I need is either to create the new picture with an anchor that is on the old page OR move the anchor to the old page after creation - neither of which I have managed to achieve so far.
Any help or suggestions greatly appreciated.The solution to this problem is to make the new picture using this command
set np to make new picture at a with properties {file name:tfile2, save with document:true, anchor:a}
Silly me. I though that making the picture at "a" would set the anchor to "a". -
How do I copy and paste text from a converted Word document?
I just converted a pdf file into word. I want to copy and paste the informatiuon into another document. How do I do that?
Hi Sara. Tanks for responding. If I cannot figure this out (I was up
until 2am last night), I want to cancel my subscription.
Here are two files you can check on/help me with. When I try again, it
comes up 'an error has occurred when trying to access the service.'
Please advise.
Pat Tomassi
In a message dated 11/1/2014 12:55:23 A.M. Eastern Daylight Time,
[email protected] writes:
How do I copy and paste text from a converted Word document?
created by Sara.Forsberg (https://forums.adobe.com/people/Sara.Forsberg)
in Adobe Acrobat.com Services - View the full discussion
(https://forums.adobe.com/message/6888908#6888908) -
Converting tiff images to word documents
does mac offer any programs like microsoft office document imaging which enables you to scan docs as tifs and convert them to word?
Microsoft would have to offer a TIFF importer within Microsoft Word for its documents. If your issue is loading Word documents within TextEdit, yes, that editor does not support images. You are better off if you don't want to use Microsoft Word itself, to use NeoOffice or iWork's Pages if you want to incorporate images in Word documents.
P.S. Mac is the name of the operating system, and the computers that run the operating system by Apple Inc. So questioning "Does Mac..." doesn't make any more sense than asking "Does Experion..." -
How do I stop the spinning wheel that replaced the cursor in a Word document?
How do I stop the spinning wheel that replaced the cursor in a Word document?
Something is causing Word to lock up. Restart the laptop and/or reinstall Office/Word to fix the instability. Maybe even a bad plugin or document could be causing this if it's only happening when you open a particular doc.
-
Dynamic text box, HTML Text with Image
Hello Everyone,
I am using Flash version 8. I have used the text tool and
created a dynamic text box and have attached the UIScrollBar
component to it. This text box is configured to allow the use of
html text to be inputted to it. I have code that reads a file which
contains a list of text files that I then read and place them into
the text box. The user can use the scroll bar to scroll through all
the text.
I have created an image that is a picture of the tab portion
of a file folder. On the tab I have place some text. This was all
done in Photoshop. This tab image is used to separate the different
stories in the text box. The image is save as a jpeg file
Everything you have just read works with out any problems.
Now for the problem!
This image is only 20 pixels tall and the text is not very
readable. As we all know the HTML tags are very limited in Flash 8.
Ideally I would like to put the text and image in to the text
box as I would normally do. Then place text on top of the image and
have it all scroll properly with in the text box.
I have taken the tab image and converted it in to a graph
symbol and then put the text on top of the image. This looks good;
however I don’t know how (or if it is even possible) to place
the graphic symbol in to the text box at the correct place within
the text.
Does anyone have ideas on what may work? Remember that the
image I am working with is only 20 pixels tall which is why the
text quality on the image is so poor.
Thank you all for any help you may provide,
SteveYes Tim I am using the <img> tag and I know that I
can’t place text over the image. I have set the height and
width to be the exact size of the image. However When you go to the
webpage it will open the movie to the maximum size based on the
resolution of your display; however I do maintain the aspect ratio
of the movie. For testing I did set a fix size to the size of the
movie. Sometimes the fix size (1000x750) looks better and sometimes
a larger size (example 1280x1024). I believe that the main problem
is the fact the size of the image is 670 pixels wide by 25 pixels
high and of the 25 pixels the text is only 18 pixels tall. In
Photoshop this makes it about a 1.75 point font. As you can see the
real problem is that I don’t have enough pixels to make up
the text. This is why I am looking for an alterative way to create
the text.
I tried importing the image into flash as a graphic symbol
and then using the text tool to create the text. The results looked
real sharp, the text was nice and crisp (just what I wanted). The
problem is that I could not find a way to place the graphic symbol
into the dynamic text area like id did using the <img> tag.
This symbol needs to scroll as you scroll the text in the text
area.
This is why I am asking for help. I am looking for some ideas
that may work.
Thank you,
Steve -
Are there plans to add the option of replacing the bullets in a bulleted list with images, as you can do in Word? Our current workaround is to insert the image as a background image through the CSS with appropriate spacing, but this isn't very accurate.
Hello Michael,
Since the rendering of bullets is up to the browser, we don't have much control over that other than what the browser can provide. According to CSS, I believe the correct style to use would be "list-style-image," but it is not well-supported, and the ICE browser in OHJ does not currently support it.
I am not sure what MS Word does, but when you save a Word file as HTML, it does all sorts of strange things to the HTML. For example, a quick test showed that saving a list (with custom bullets) as HTML created a series of P elements with things like <span style='font-family:Symbol'>^<span
style='font:7.0pt "Times New Roman"'> </span></span>
You could do things like that, too, but it isn't good HTML.
-Ben
Oracle Help team
Maybe you are looking for
-
hi, i am able to get the preview for the below program..But i am not getting the spool list..and want to check whether the following mail has been successfully sent to the receiver in sost transaction..kindly resolve this problem...i am also getting
-
XBMC/mplayer and KDE Desktop effects
Hi, i have setup a arch based HTPC with XBMC on top of KDE, but there is one thing i were not able to resolve: The XBMC GUI and playing a video on it gets laggy as soon as i DISABLE the kde desktop effects. My system is i3/sandy bridge based with int
-
I was using my ipod [not on the native machine that originally formatted it] and all of a sudden exclamation marks began appearinng next to my songs indicating they can't be found by itunes. Then all of a sudden my ipod doesn't appear in itunes. I ge
-
I have Indesign CC 2014 64 and it is showing in the product list
-
Hello Experts, I have here an execution plan for a query and appreciate your support if you have any recommendations could help enhance it