Skip to content

Commit

Permalink
Updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jjhbw committed Apr 19, 2020
1 parent 149e66d commit a108aa2
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,35 +279,33 @@ The JS snippet must return an _image object_ or a Promise of an _image object_,

* `width` in cm
* `height` in cm
* `thumbnail` _[optional]_: non-SVG image to use when SVG is not supported or shown in preview (only relevant when image is SVG). See example below.
* `data`: either an ArrayBuffer or a base64 string with the image data
* `extension`: e.g. `.png`
* `thumbnail` _[optional]_: when injecting an SVG image, a fallback non-SVG (png/jpg/gif, etc.) image is necessary. This thumbnail is used when SVG images are not supported or when the document is previewed. See example below.

Images can also be SVG. These needs a thumbnail (fallback) to be specified along with the image data.

The SVG can be injected from a js context as shown below
Injecting an SVG is slightly different than other images, as a `thumbnail` needs to be specified:

In the .docx template:
```
+++IMAGE injectSvg()+++
```

In the `createReport` call:
```js
additionalJsContext: {
injectSvg: () => {
const data = Buffer.from(`<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
const svg_data = Buffer.from(`<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect x="10" y="10" height="100" width="100" style="stroke:#ff0000; fill: #0000ff"/>
</svg>`, 'utf-8');
return { width: 6, height: 6, data, extension: '.svg', thumbnail: './thumbnail.png' };
const thumbnail = {
data: fs.readFileSync('sample.png'),
extension: '.png',
};
return { width: 6, height: 6, data: svg_data, extension: '.svg', thumbnail };
}
}
```

Or the svg can be given directly as a path:

```
+++IMAGE ({ width: 3, height: 3, path: './sample.svg', thumbnail: './thumb.png' })+++
```

### `LINK`

Includes a hyperlink with the data resulting from evaluating a JavaScript snippet:
Expand Down

0 comments on commit a108aa2

Please sign in to comment.