Giter VIP home page Giter VIP logo

docxtemplater-link-module's Introduction

A plugin for docxtemplater - docxtemplater-link-module

What

This plugin enables docxtemplater to embed hyperlinks - either emails or URLS to be embedded in docx files.

How to Do

  • A docxtemplater object stores all the files as an array in its doc.zip.files property

First module for docxtemplater.

Installation:

You will need docxtemplater v1: npm install docxtemplater@beta

install this module: npm install docxtemplater-link-module

Usage

Your docx should contain the text: {! link }

LinkModule=require(‘docxtemplater-link-module’)

linkModule=new LinkModule({centered:false})

docx=new DocxGen()
    .attachModule(linkModule)
    .load(content)
    .setData({
      link: {
        text: "Steve Jobs",
        link: '[email protected]'
      }})
    .render()

buffer= docx
        .getZip()
        .generate({type:"nodebuffer"})

fs.writeFile("test.docx",buffer);

Notice

For the link-replacer to work, the link tag: {! link } needs to be in its own <w:p>, so that means that you have to put a new line after and before the tag.

Building

You can build the coffee into js by running gulp (this will watch the directory for changes)

Testing

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

TODO

  • Try to handle links that occur in the midst of other content
  • Settle on a better syntax?
  • Handle a subject field for email links

docxtemplater-link-module's People

Contributors

halhenke avatar

Watchers

 avatar  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.