In MS word 2013 (using gdrive picture).
If you want to add an email but you don’t want to update the image (when the hosted email will change) go to insert
tab, click on pictures
, simply past the url of your image in the filename field and press insert
.
If you want the picture to be updated go to insert tab, click on pictures
, simply past the url of your image in the filename field but instead of pressing insert
, chose (in the menu under insert
) insert and link
(or link to file
. Both will work).
To update a gdrive file, just drop the new version on the new one. Google will ask you if you want to keep separate, let it go, by default it will update the old one.
How to update/refresh a linked picture in the docx?. Select the picture and refresh by pressing F9
.
PS: the gdrive file must be public (not private), the URL must be like:
https://drive.google.com/uc?export=view&id=<file_ID_here!>
(I tried other URLs wich did not work)
Need to elaborate more on Mike’s answer, to avoid confusion.
Staffer901: you are talking about 2 different subjects on this post.
- Inserting Images to the document. which i think is your bottom line question: how to insert an image with an image URL. The options that Michael mentioned, which are basically to insert classic HTML for an image, will work but i would NOT recommend you to use any of them. The reason why is because really what you are doing is storing a reference to the image that has a connection to the internet dependency, which means any user consuming that document must be connected to see the image.
What i DO recommend you to do for image insertion (permanent insertion ) is to use the range.insertInlinePictureFromBase64 method. You need to have an additional step to encode the image in the URL to a base64 string, which is what the methods accepts as input parameter and here is a good discussion on how to achieve this.. Check out a sample below showing inserting an InlinePicture on the first paragraph of the document, assumes you have the base64. Note that you can get the current insertion point and insert the pic there if needed as well. insertInlinePictureFromBase64 is a method of any objects that inherits from range, like body, paragraph, content control etc.
here is a sample:
// Run a batch operation against the Word object model.
Word.run(function (context) {
// Create a proxy object for the paragraphs collection.
var paragraphs = context.document.body.paragraphs;
// Queue a commmand to load the style property for all of the paragraphs.
context.load(paragraphs);
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
return context.sync().then(function () {
// Queue a command to get the first paragraph.
var paragraph = paragraphs.items[0];
var b64encodedImg = "iVBORw0KGgoAAAANSUhEUgAAAB4AAAANCAIAAAAxEEnAAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACFSURBVDhPtY1BEoQwDMP6/0+XgIMTBAeYoTqso9Rkx1zG+tNj1H94jgGzeNSjteO5vtQQuG2seO0av8LzGbe3anzRoJ4ybm/VeKEerAEbAUpW4aWQCmrGFWykRzGBCnYy2ha3oAIq2MloW9yCCqhgJ6NtcQsqoIKdjLbFLaiACnYyf2fODbrjZcXfr2F4AAAAAElFTkSuQmCC";
// Queue a command to insert a base64 encoded image at the beginning of the first paragraph.
paragraph.insertInlinePictureFromBase64(b64encodedImg, Word.InsertLocation.start);
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
return context.sync().then(function () {
console.log('Added an image to the first paragraph.');
});
});
})
.catch(function (error) {
console.log('Error: ' + JSON.stringify(error));
if (error instanceof OfficeExtension.Error) {
console.log('Debug info: ' + JSON.stringify(error.debugInfo));
}
});
Finally note that the setSelectedDataAsync method that Michaels mentioned, was recently updated to support image insertion, you also need to supply the base64 of the image but the benefit is that you get backwards compatibility (it will work with 2013 clients as well) here is a code sample of this:
// assumes a valid base64 is provided as the first parameter.
Office.context.document.setSelectedDataAsync(mybase64, { coercionType: 'image' }, function (result) {
if (result.status == 'succeeded')
app.showNotification("Image inserted");
else
app.showNotification("Error:" + result.error.message + " : " + error.name)
})
- Consuming images from the document. This is about getting the base64 from existing images in the document. We have a body. inlinePictures collection you can use to get all the images in the document, and you use the getBase64 method to get the base64 encoded representation of the binary. I would like to know why this is confusing in the documentation, can you please elaborate on that?
I hope this is useful.
thanks and happy coding!
-Juan.
- Topics
- >Videos
- >Word add-in
Last updated Apr 12 2020
In this video we will show you how to insert an image to your document based on a URL.
We will show you how to:
— Press on the «Insert image» option.
— Enter an image URL.
— Once the Image is loaded you can change the size by stretching it on canvas.
— Press on the «preview» button and the document will be rendered with the image displayed inside it.
Did you find this article helpful?
Didn’t find what you were looking for? Try the following for assistance or Use the Search box. |
-
Asking us questions is the fastest and most affective way to get assistance.
-
Got a question? Check out our FAQs pages for answers to commonly asked questions.
-
Check out our complete index of the FormTitan Topics organized by categories.
-
Browse our topics directory to find the feature you are looking for.
-
Contact
Still haven’t found what you were looking for? no problems… simply send us your inquiry.
- Remove From My Forums
-
Question
-
Is it possible to have PowerShell insert an image into a Word document from a URL instead of a local path? If so what is that syntax?
As you can see below I reference an image file from my local computer. I’d like to be able to use the path of an image on our SharePoint server based upon it’s URL so that I can turn this into a PS module and let anyone on my team be able to create the report
and still get the logo.Thanks for any suggestions.
cd "C:scriptsDBA-SQLBinn_Data_PermissionsWordReport" cls $endDate = (Get-Date).ToString("MM-dd-yyy_HHmmss") $Result = @() $OutputFileName = "c:PowerShellResultsSQL2005_Server_BINN-Data_Paths_" + $enddate + ".docx" $date = get-date $scriptpath = $MyInvocation.MyCommand.Path #$ScriptName = $MyInvocation.MyCommand.Name $notify = Get-QADUser $env:USERNAME | select firstname, lastname $firstName = $notify.FirstName $lastName = $notify.LastName $mycount = 0 $usr = $env:username $word = new-object -ComObject word.application $Word.Visible = $True $Document = $Word.Documents.Add() $Selection = $Word.Selection $ObjShape = $Selection.inlineshapes.AddPicture("C:Usersm0181hePicturesSQL_Dude.jpg") $objShape.HorizontalLineFormat $Selection.TypeParagraph() $Selection.Style = 'Title' $Selection.TypeText("SQL Server 2005 Audit Results") $Selection.TypeParagraph() $Selection.TypeText("File Processed: $($ScriptPath) `v") $Selection.TypeText("Report compiled on $(Get-Date) by $($firstName) $($lastName).`v") $Selection.TypeParagraph()
-
Moved by
Friday, March 18, 2016 6:52 PM
Move to more appropriate forum
-
Moved by
Answers
-
No but you can display external content by using a link but it will have to be clicked.
Embedded pictures must be downloaded first.
_(ツ)_/
-
Edited by
jrv
Wednesday, February 17, 2016 9:45 PM -
Marked as answer by
David_JunFeng
Tuesday, March 29, 2016 1:30 AM
-
Edited by
Ok this might not be as much a programming question as just a how the hell do I do it question.
I have a image URL contained in my sql database. I create a bookmark for that column in the word document.(this works fine)
Now I want to use the image URL that is passed from the database to insert an image.
I have tried hyperlink(DOES NOT WORK and DOES NOT DISPLAY IMAGE) I have tried Quick Parts — IncludePicture (DOES NOT WORK).
I have been Googleing my ass of for the past week and have not found anything that works.
ANY HELP PLEASE???????????
Ok let me simplify this. I want to insert a image using an URL. You can do this in alot of different ways I know.
For instance using Quick Parts and the selecting IncludePicture you would the past the URL of the picture and BAM image inserted.
Now I want to do exactly that with one exception. The URL is a microsoft word bookmark that I get from my database. For some reason this does not want to work. I have also checked the bookmark data and it is correct and yes it is a valid URL because if I copy and paste it from the database in the way I described above it works.
So is there any other way to do this?
I have been supplied with word-vba code that looks something like this.
Sub Insert_picture() Dim Google As String <pre>Sub Insert_picture() Dim Google As String Google = "http://maps.googleapis.com/maps/api/staticmap?center=(-26.2041028, 28.047305100000017)&zoom=17&size=500x500&markers=size:large%7Ccolor:red|(-26.2041028, 28.047305100000017)&sensor=false®ion=ZA" ActiveDocument.Bookmarks("MAPURL").Range.InlineShapes.AddPicture Google, True, True End Sub
So now my question(using this code). Is there a way to set the Google string to the MAPURL bookmark?
I need to dynamically generate the image for different locations. (Different location for each document that is greated)
Hope this helps make what I am looking for a bit clearer
Again any help will be greatly appreciated.
Updated 23-Jun-13 21:03pm
Check this code:
Sub Insert_picture() Dim Google As String ActiveDocument.Bookmarks("MAPURL").Select Google = Selection.Text ActiveDocument.Bookmarks("MAPURL").Range.InlineShapes.AddPicture Google, True, True End Sub
Be aware to have the placeholder bookmark only covering the url, and nothing else.
Updated 23-Jun-13 22:57pm
Here I check for the bookmark in the database and if it contains the mapurl bookmark it then takes the placeholder bookmark on the document and sets its text to null and the inserts the image at the bottom of the document(where the bookmark is located)
If MyBookMarks.Item(bookmark).Name = "mapurl" Then MyBookMarks.Item(bookmark).Range.Text = "" Dim oRange As Object = MyBookMarks.Item(bookmark).Range Dim saveWithDocument As Object = True Dim missing As Object = Type.Missing appWord.Application.Selection.InlineShapes.AddPicture(cmd.Columns.Item(bookmark).ToString(), missing, saveWithDocument, oRange) Else
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
MSWord2Image-PHP
This library allows you to quickly convert Microsoft Word documents to image through msword2image.com using PHP for free!
Demo
Example conversion: From demo.docx to output.png.
Note that you can try this out by visting msword2image.com and clicking «Want to convert just one?»
Installation
You can simply download this github repo as a zip file. Extract contents and include MsWordToImageConvert.php
require_once 'lib/MsWordToImageConvert.php';
Note: Please make sure cURL is enabled with your PHP installation
Usage
1. Convert from Word document URL to JPEG file
$convert = new MsWordToImageConvert($apiUser, $apiKey); $convert->fromURL('http://mswordtoimage.com/docs/demo.doc'); $convert->toFile('demo.jpeg'); // Please make sure output file is writable by your PHP process.
2. Convert from Word document URL to base 64 JPEG string
$convert = new MsWordToImageConvert($apiUser, $apiKey); $convert->fromURL('http://mswordtoimage.com/docs/demo.doc'); $base64String = $convert->toBase46EncodedString(); echo "<img src='data:image/jpeg;base64,$base64String' />";
3. Convert from Word file to JPEG file
$convert = new MsWordToImageConvert($apiUser, $apiKey); $convert->fromFile('demo.doc'); $convert->toFile('demo.jpeg'); // Please make sure output file is writable and input file is readable by your PHP process.
4. Convert from Word file to base 64 encoded JPEG string
$convert = new MsWordToImageConvert($apiUser, $apiKey); $convert->fromFile('demo.doc'); $base64String = $convert->toBase46EncodedString(); echo "<img src='data:image/jpeg;base64,$base64String' />"; // Please make sure input file is readable by your PHP process.
5. Convert from Word file to base 64 encoded GIF string
$convert = new MsWordToImageConvert($apiUser, $apiKey); $convert->fromFile('demo.doc'); $base64String = $convert->toBase46EncodedString(MsWordToImageConvertOutputImageFormat::GIF); echo "<img src='data:image/gif;base64,$base64String' />"; // Please make sure input file is readable by your PHP process.
6. Convert from Word file to base 64 encoded PNG string
$convert = new MsWordToImageConvert($apiUser, $apiKey); $convert->fromFile('demo.doc'); $base64String = $convert->toBase46EncodedString(MsWordToImageConvertOutputImageFormat::JPEG); echo "<img src='data:image/png;base64,$base64String' />"; // Please make sure input file is readable by your PHP process.
7. Get the page count of a given Word file
$convert = new MsWordToImageConvert($apiUser, $apiKey); $convert->fromFile('demo2.doc'); $toPageCount = $convert->toPageCount(); // $toPageCount will be integer representing the page count in the word file // Please make sure input file is readable by your PHP process.
8. Get the page count of a given Word file URL
$convert = new MsWordToImageConvert($apiUser, $apiKey); $convert->fromFile('http://msword2image.com/docs/demo2.doc'); $toPageCount = $convert->toPageCount(); // $toPageCount should be 5 // Please make sure input file is readable by your PHP process.
9. Get the specific page of a Word document as image
$convert = new MsWordToImageConvert($apiUser, $apiKey); $convert->fromFile('demo2.doc'); $base64String = $convert->toBase46EncodedString( MsWordToImageConvertOutputImageFormat::JPEG, 2 ); echo "<img src='data:image/jpeg;base64,$base64String' />"; // Note that pages are 0-indexed. Above code will print the third page of word document // Please make sure input file is readable by your PHP process.
Supported file formats
InputOutput | PNG | GIF | JPEG | Page count |
DOC | ✔ | ✔ | ✔ | ✔ |
DOCX | ✔ | ✔ | ✔ | ✔ |