Git Product home page Git Product logo

fponticelli / docxtemplater Goto Github PK

View Code? Open in Web Editor NEW

This project forked from open-xml-templating/docxtemplater

0.0 2.0 0.0 14.57 MB

Generate docx and pptx from templates, from Node.js, the Browser and the command line / Demo: http://javascript-ninja.fr/docxtemplater/v1/examples/demo.html

Home Page: http://docxtemplater.com

License: Other

CoffeeScript 41.85% JavaScript 53.36% HTML 1.15% CSS 3.65%

docxtemplater's Introduction

docxtemplater v1

Join the chat at https://gitter.im/open-xml-templating/docxtemplater

Build Status Download count Current tag Issues closed

docxtemplater logo

docxtemplater is a library to generate docx/pptx documents from a docx/pptx template. It can replace {placeholders} with data and also supports loops and conditions. The templates can be edited by non-programmers, eg for example your clients.

Note: The CLI will soon be moved to another repository : keep posted on https://github.com/open-xml-templating/docxtemplater-cli

Features

Demo Site

Quickstart in Node

Installation: npm install docxtemplater

var fs = require('fs');
var Docxtemplater = require('docxtemplater');

//Load the docx file as a binary
var content = fs
    .readFileSync(__dirname + "/input.docx", "binary");

var doc = new Docxtemplater(content);

//set the templateVariables
doc.setData({
    "first_name":"Hipp",
    "last_name":"Edgar",
    "phone":"0652455478",
    "description":"New Website"
});

//apply them (replace all occurences of {first_name} by Hipp, ...)
doc.render();

var buf = doc.getZip()
             .generate({type:"nodebuffer"});

fs.writeFileSync(__dirname+"/output.docx",buf);

You can download input.docx and put it in the same folder than your script.

Quickstart in the browser

Installation

JS download

You can directly download built versions from github : https://github.com/open-xml-templating/docxtemplater-build/tree/master/build

Bower

Thanks to pykiss, it's now possible to install docxtemplater with bower: This in an unofficial method to install docxtemplater in the browser

bower install --save docxtemplater-pykiss

Build it yourself

git clone [email protected]:open-xml-templating/docxtemplater.git && cd docxtemplater
# git checkout v1.0.4 # Optional
npm install -g gulp jasmine-node uglify-js browserify
npm install
gulp allCoffee
mkdir build -p
browserify -r ./js/docxgen.js -s Docxgen > build/docxgen.js
uglifyjs build/docxgen.js > build/docxgen.min.js # Optional

The -s Docxgen will export docxgen to window.Docxgen for easy usage (on some systems, it might export it in window.docxgen (see open-xml-templating#118))

Html demo

Create the following html

<html>
    <script src="build/docxgen.js"></script>
    <script src="vendor/FileSaver.min.js"></script>
    <script src="vendor/jszip-utils.js"></script>
    <!--
    Mandatory in IE 6, 7, 8 and 9.
    -->
    <!--[if IE]>
        <script type="text/javascript" src="examples/vendor/jszip-utils-ie.js"></script>
    <![endif]-->
    <script>
    var loadFile=function(url,callback){
        JSZipUtils.getBinaryContent(url,callback);
    }
    loadFile("examples/tagExample.docx",function(err,content){
        if (err) { throw e};
        doc=new Docxgen(content);
        doc.setData( {"first_name":"Hipp",
            "last_name":"Edgar",
            "phone":"0652455478",
            "description":"New Website"
            }
        ) //set the templateVariables
        doc.render() //apply them (replace all occurences of {first_name} by Hipp, ...)
        out=doc.getZip().generate({type:"blob"}) //Output the document using Data-URI
        saveAs(out,"output.docx")
    })
    </script>
</html>

Documentation

The full documentation of v1 can be found on read the docs.

See upgrade.md for information about how to migrate from 0.7

Similar libraries

They are a few similar libraries that work with docx, here’s a list of those I know a bit about:

  • docx4j :JAVA, this is probably the biggest docx library out there. They is no built in templating engine, but you can generate your docx yourself programmatically
  • docx.js: Javascript in the browser, you can create (not modify) your docx from scratch, but only do very simple things such as adding non formatted text
  • xlsx-templater : its working quite well, does the same as here but for xlsx

Modules

Functionality can be added with modules. They is yet no doc for the modules because it is not completely mature yet, but you can open an issue if you have any question about it.

Here is the list of existing modules:

Professional Support

I can give your company support for installing, extending, answering support questions, or maintainning your app that runs docxtemplater. You can find my email address on my profile

docxtemplater's People

Contributors

aaronbaker avatar balazsbohonyi avatar cheapsteak avatar dderg avatar edi9999 avatar fponticelli avatar frapontillo avatar gitter-badger avatar netei avatar sgrignard avatar tamagokun avatar tdonia avatar totalwar 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.