Skip to content

Commit

Permalink
Fixed Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
evilc0des committed Jan 26, 2019
1 parent d7cecb5 commit 3c18ebc
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
44 changes: 41 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ Installation
You first need to install docxtemplater by following its [installation guide](https://docxtemplater.readthedocs.io/en/latest/installation.html).

For Node.js install this package:
```
```bash
npm install docxtemplater-image-module-free
```

For the browser find builds in `build/` directory.

Alternatively, you can create your own build from the sources:
```
```bash
npm run compile
npm run browserify
npm run uglify
Expand Down Expand Up @@ -284,4 +284,42 @@ opts.getSize = function (img, tagValue, tagName) {
return [300, 300];
};
```
```

## Base64 include

You can use base64 images with the following code:

```js
function base64DataURLToArrayBuffer(dataURL) {
const base64Regex = /^data:image\/(png|jpg|svg|svg\+xml);base64,/;
if (!base64Regex.test(dataURL)) {
return false;
}
const stringBase64 = dataURL.replace(base64Regex, "");
let binaryString;
if (typeof window !== "undefined") {
binaryString = window.atob(stringBase64);
} else {
binaryString = new Buffer(stringBase64, "base64").toString("binary");
}
const len = binaryString.length;
const bytes = new Uint8Array(len);
for (let i = 0; i < len; i++) {
const ascii = binaryString.charCodeAt(i);
bytes[i] = ascii;
}
return bytes.buffer;
}
const imageOpts = {
getImage(tag) {
return base64DataURLToArrayBuffer(tag);
},
getSize() {
return [100, 100];
},
};
doc.attachModule(new ImageModule(imageOpts));
```


2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "docxtemplater-image-module-free",
"version": "1.1.0",
"version": "1.1.1",
"description": "Open Source Image Module for docxtemplater",
"main": "js/index.js",
"scripts": {
Expand Down

0 comments on commit 3c18ebc

Please sign in to comment.