0.2.4 • Published 6 years ago

docxtemplater-link-module v0.2.4

Weekly downloads
1,033
License
MIT
Repository
github
Last release
6 years ago

docxtemplater-link-module

Hyperlink module for docxtemplater

Download count ghit.me Build Status

Installation:

You will need docxtemplater v2.1.1: npm install docxtemplater

Install this module: npm install docxtemplater-link-module

Usage: Text and URL

The example below will displays the following hyperlink:

Lorem ipsum dolor sit amet.

Your docx should contain the text: Lorem ipsum {^link} amet..

var fs = require('fs');
var content = fs.readFileSync(__dirname + "/example-href.docx", "binary");
var DocxGen = require('docxtemplater');
var LinkModule = require('docxtemplater-link-module');
var linkModule = new LinkModule();
 
var docx = new DocxGen()
	.attachModule(linkModule)
	.load(content)
	.setData({
		link : {
			text : "dolor sit",
			url : "http://google.com"
		}
	}).
	render();
var buffer = docx
	.getZip()
	.generate({type:"nodebuffer"});
fs.writeFile("test.docx", buffer);

Usage: URL only

The example below will displays the following hyperlink:

Lorem ipsum http://google.com amet.

Your docx should contain the text: Lorem ipsum {^link} amet..

var fs = require('fs');
var content = fs.readFileSync(__dirname + "/example-href.docx", "binary");
var DocxGen = require('docxtemplater');
var LinkModule = require('docxtemplater-link-module');
var linkModule = new LinkModule();
 
var docx = new DocxGen()
	.attachModule(linkModule)
	.load(content)
	.setData({
		link : "http://google.com"
	}).
	render();
var buffer = docx
	.getZip()
	.generate({type:"nodebuffer"});
fs.writeFile("test.docx", buffer);

Usage: Email address support

The example below will displays the following hyperlink:

Lorem ipsum john.smith@example.com amet.

Your docx should contain the text: Lorem ipsum {^link} amet..

var fs = require('fs');
var content = fs.readFileSync(__dirname + "/example-mailto.docx", "binary");
var DocxGen = require('docxtemplater');
var LinkModule = require('docxtemplater-link-module');
var linkModule = new LinkModule();
 
var docx = new DocxGen()
	.attachModule(linkModule)
	.load(content)
	.setData({
		link : "john.smith@example.com"
	}).
	render();
var buffer = docx
	.getZip()
	.generate({type:"nodebuffer"});
fs.writeFile("test.docx", buffer);

Usage: Text and URL in powerpoint pptx

The example below will displays the following hyperlink powerpoint:

Lorem ipsum dolor sit amet.

Your pptx should contain the text: Lorem ipsum {^link} amet..

var fs = require('fs');
var content = fs.readFileSync(__dirname + "/example-href.pptx", "binary");
var DocxGen = require('docxtemplater');
var LinkModule = require('docxtemplater-link-module');
var linkModule = new LinkModule();
 
var docx = new DocxGen()
	.attachModule(linkModule)
	.setOptions({ fileType : "pptx" })
	.load(content)
	.setData({
		link : {
			text : "dolor sit",
			url : "http://google.com"
		}
	}).
	render();
var buffer = docx
	.getZip()
	.generate({type:"nodebuffer"});
fs.writeFile("output-href.pptx", buffer);

Usage: Email address support in powerpoint

The example below will displays the following hyperlink:

Lorem ipsum john.smith@example.com amet.

Your pptx should contain the text: Lorem ipsum {^link} amet..

var fs = require('fs');
var content = fs.readFileSync(__dirname + "/example-mailto.pptx", "binary");
var DocxGen = require('docxtemplater');
var LinkModule = require('docxtemplater-link-module');
var linkModule = new LinkModule();
 
var docx = new DocxGen()
	.attachModule(linkModule)
	.setOptions({ fileType : "pptx" })
	.load(content)
	.setData({
		link : "john.smith@example.com"
	}).
	render();
var buffer = docx
	.getZip()
	.generate({type:"nodebuffer"});
fs.writeFile("output-mailto.pptx", buffer);

Testing

You can test that everything works fine using the command mocha. This will also create 2 docx files under the root directory that you can open to check if the docx are correct

0.2.4

6 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago