Comments (3)
Ended up getting it to work by sending the $host.image to a function, which sends it straight back again - will keep that, unless there's a way to read $host.image within the IMAGE tag directly:
+++IMAGE getImageObject($host.image) +++
additionalJsContext: { getImageObject: base64data => { const data = base64data; return { width: 8.8, height: 3, data, extension: '.png' }; },
from docx-templates.
If that is the exact error string you're getting, it may have something to do with string literal quoting used, as the 'command' featured in the error message lacks the data:image/png;base64,
substring.
Regardless, injecting images like this is not supported, so even if it works I wouldn't count on it working in the future.
If you really want to go this way, you can try is using anonymous function that returns your object, e.g. IMAGE ()=> { width: 6, height: 6, "data:image/png;base64,$host.image", extension: '.png' }
, taking special care to get the literal quoting correct. I'm not sure from the top of my head whether this will work, but worth a try.
from docx-templates.
Thanks @jjhbw - I've set the object value in the JSON array to the correct format - "host.image" value now looks like this:
{ width: 6, height: 6, extension: '.png', data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAlUAAAC2CAIAAAB... }
Tried then injecting it like this in the template, but it doesn't seem to like it:
+++IMAGE $host.image +++
Error is ""Error: Error executing command 'IMAGE $host.image': invalid image width: undefined (in cm)"" - which suggests that it is not able to read $host.image?
It shows up fine in an "INS" tag - perhaps it's reading it in as a string rather than an object? Thanks for your patience - not fluent in JS (as may be obvious).
from docx-templates.
Related Issues (20)
- Footer is not preserved HOT 3
- Re-evaluate need for Buffer polyfill
- Corrupted statistics analyzer HOT 1
- Update of Word directory HOT 2
- additionalJsContext always wrapped in text tag breaking styling HOT 2
- How to set image in header which is stick to the top of the header HOT 1
- Docx file corrupted when image in header
- Improve documentation on templates HOT 2
- Webpack build errors when including browser.js HOT 1
- Exec function with a subtract HOT 1
- Preprocessing of docx template? HOT 1
- [Question or maybe issue] Newlines on free text insertion
- How to add a color logic based on a value in the placeholder HOT 1
- Feature request: Field Codes as alternative to cmdDelimiter characters HOT 1
- include browser.js - SyntaxError: Private field '#comment' must be declared in an enclosing class HOT 3
- inserting HTML part ? HOT 2
- Nested IFs in a table cell issue
- New Lines on nested FOR loop inside table cell
- The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Promise
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docx-templates.