Created
January 24, 2018 21:44
-
-
Save kbrandl/a48b16248563d3776a59f4e46b43f8d7 to your computer and use it in GitHub Desktop.
Shared with Script Lab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 48423914-how-to-get-a-base64-representation-of-a-selected-image-in-word-for-ipad | |
description: '' | |
author: kbrandl | |
host: WORD | |
api_set: {} | |
script: | |
content: |- | |
$("#run").click(() => tryCatch(run)); | |
function run() { | |
return Word.run(function (context) { | |
// Getting the selected range | |
var range = context.document.getSelection(); | |
// Getting the image from the selected range | |
var picture = range.inlinePictures.getFirstOrNullObject(); | |
context.load(picture); | |
// Loading the image properties so we can access it later | |
return context.sync() | |
.then(function () { | |
var picbase64 = picture.getBase64ImageSrc(); | |
return context.sync() | |
.then(function () { | |
console.log("Base64 string is " + picbase64.value); | |
}); | |
}); | |
}) | |
} | |
/** Default helper for invoking an action and handling errors. */ | |
function tryCatch(callback) { | |
Promise.resolve() | |
.then(callback) | |
.catch(function (error) { | |
OfficeHelpers.UI.notify(error); | |
OfficeHelpers.Utilities.log(error); | |
}); | |
} | |
language: typescript | |
template: | |
content: |- | |
<p class="ms-font-m">Executes a simple code snippet</p> | |
<button id="run" class="ms-Button"> | |
<span class="ms-Button-label">Run code</span> | |
</button> | |
language: html | |
style: | |
content: |- | |
body { | |
margin: 0; | |
padding: 10px; | |
} | |
/* Button customization, including overwriting some Fabric defaults */ | |
.ms-Button, .ms-Button:focus { | |
background: #2b579a; | |
border: #2b579a; | |
} | |
.ms-Button > .ms-Button-label, | |
.ms-Button:focus > .ms-Button-label, | |
.ms-Button:hover > .ms-Button-label { | |
color: white; | |
} | |
.ms-Button:hover, .ms-Button:active { | |
background: #204072; | |
} | |
.ms-Button.is-disabled, .ms-Button:disabled { | |
background-color: #f4f4f4; | |
border-color: #f4f4f4; | |
} | |
.ms-Button.is-disabled .ms-Button-label, | |
.ms-Button:disabled .ms-Button-label { | |
color: #a6a6a6; | |
} | |
language: css | |
libraries: | | |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js | |
https://appsforoffice.microsoft.com/lib/1/hosted/office.d.ts | |
office-ui-fabric-js@1.4.0/dist/css/fabric.min.css | |
office-ui-fabric-js@1.4.0/dist/css/fabric.components.min.css | |
core-js@2.4.1/client/core.min.js | |
@types/core-js | |
@microsoft/office-js-helpers@0.7.4/dist/office.helpers.min.js | |
@microsoft/office-js-helpers@0.7.4/dist/office.helpers.d.ts | |
jquery@3.1.1 | |
@types/jquery |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment