Giter VIP home page Giter VIP logo

docxtemplater-link-module's Introduction

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 [email protected] 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 : "[email protected]"
	}).
	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 [email protected] 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 : "[email protected]"
	}).
	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

docxtemplater-link-module's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.