You are currently offline, serving cached version

Docker HTTP API

The docker API allows you to run all docxtemplater modules contained in the ENTREPRISE plan, without having to configure them. The modules are already configured to good defaults and work well with each other.

The API exposes an HTTP POST route to do the generation that takes as input the template file and the data to be used for the generation.

The API outputs the generated file.

The docker image can be used to generate documents from other languages (Java, .Net, Ruby, Golang, …), since it only requires to do one HTTP Call.

Usage with curl

This example requires you to have input.docx, data.json and it exports output.docx

# creates a new file descriptor 3 that redirects to 1 (STDOUT)
exec 3>"output.docx"

# Run curl in a separate command,
# capturing output of -w "%{http_code}" into HTTP_STATUS
# and sending the content to this command's STDOUT with -o >(cat >&3)

curl --silent \
   -X POST \
   -F "data=@data.json" \
   -F "filecomment=This is an image file" \
   -F "doc=@input.docx" \
   -w "%{http_code}" \
   "$host/api/v1/generate" \
   -o >(cat >&3) >/tmp/httpstatus || code="$?"

Configuration

It is possible to configure your instance by editing the configuration.js file.

There are different parts that you can configure.

By implementing configureAngularParser, you can add angular filters that you want to be able to use in your template :

configureAngularParser(expressions) {
    /* Here you can define custom filters
     * For example if you wish to write { clientName | upper }
     */

    expressions.filters.upper = function(input) {
        // This condition should be used to make sure that if your input is undefined, your output will be undefined as well and will not throw an error

        if(!input)
            return input;
        return input.toUpperCase();
    }
    return expressions;
},

By implementing configureDocxtemplater, you can attach additional modules that you have developped yourself.

configureDocxtemplater(doc) {
    /*
     * Here you can configure the docxtemplater instance before compiling/rendering
     * For example :
     *
     * doc.attachModule(new MyCustomModule());
     */
    return doc;
},

By implementing configureModule, you can modify the configuration of a given module.

configureModule(moduleName, options) {
    /*
     * Here you can configure each of the docxtemplater modules
     * For example to fetch urls for the image module :
     */

    const https = require("https");
    const http = require("http");
    const Stream = require("stream").Transform;

    if (moduleName === "image") {
       options.getImage = function (url) {
           return new Promise(function (resolve, reject) {
               (url.substr(0, 5) === "https" ? https : http)
               .request(url, function (response) {
                   if (response.statusCode !== 200) {
                       return reject(
                           new Error(
                               `Request to ${url} failed, status code: ${response.statusCode}`
                           )
                       );
                   }
                   const data = new Stream();
                   response.on("data", function (chunk) {
                       data.push(chunk);
                   });
                   response.on("end", function () {
                       resolve(data.read());
                   });
                   response.on("error", function (e) {
                       reject(e);
                   });
               })
               .end();
           });
       };
    }

    return options;
}

Specs to host the docker image

You can host the docker image on an EC2 Amazon instance for example, or on a virtual machine that you own.

Recommended specs would be :

  • A decent CPU, the docker image uses only one core (no parallelism in docxtemplater), so you don't "need" a 16 CPU server. (But you can have one instance of the docker image for each CPU if you expect very high load). Docxtemplater is CPU bound, meaning that it is there that speed improvements can be made mostly.

  • 2GB of Ram or more for each instance of the docker image

  • SSD and good network quality cannot hurt as well.

CHANGELOG

3.13.0

  • Use async data generation and make it possible to configure a single module (for example the image module)
  • Update table-module-3.13.7
  • Update slides-module-3.3.5
  • Update image-module-3.8.13
  • Update html-module-3.26.9
  • Update error-location-module-3.2.5
  • Update docxtemplater to 3.25.0
  • Update chart-module-3.1.0

3.12.1

  • Allow up to 25MB json data when using form field
  • Update xlsx-module-3.6.3
  • Update word-run-module-3.1.4
  • Update table-module-3.13.6
  • Update subtemplate-module-3.7.0
  • Update subsection-module-3.3.12
  • Update styling-module-3.3.6
  • Update slides-module-3.3.4
  • Update qrcode-module-3.2.6
  • Update pptx-sub-module-3.0.17
  • Update paragraph-placeholder-module-3.2.5
  • Update meta-module-3.2.6
  • Update image-module-3.8.12
  • Update html-pptx-module-3.2.4
  • Update html-module-3.26.6
  • Update footnotes-module-3.2.6
  • Update error-location-module-3.2.4
  • Update docxtemplater to 3.23.1
  • Update chart-module-3.0.2

3.12.0

  • Update xlsx-module-3.6.1
  • Update word-run-module-3.1.2
  • Update table-module-3.13.4
  • Update subtemplate-module-3.6.4
  • Update styling-module-3.3.4
  • Update slides-module-3.3.2
  • Update qrcode-module-3.2.4
  • Update pptx-sub-module-3.0.9
  • Update paragraph-placeholder-module-3.2.3
  • Update node to 14.17
  • Update meta-module-3.2.4
  • Update image-module-3.8.8
  • Update html-pptx-module-3.2.2
  • Update html-module-3.26.3
  • Update footnotes-module-3.2.3
  • Update error-location-module-3.2.2
  • Update docxtemplater to 3.22.3
  • Update dependencies
  • Add chart-module

3.12.0

  • Add chart module
  • Update xlsx-module-3.6.1
  • Update word-run-module-3.1.2
  • Update table-module-3.13.4
  • Update subtemplate-module-3.6.4
  • Update subsection-module-3.3.10
  • Update styling-module-3.3.4
  • Update slides-module-3.3.2
  • Update pptx-sub-module-3.0.10
  • Update paragraph-placeholder-module-3.2.3
  • Update node to 14.17
  • Update meta-module-3.2.4
  • Update image-module-3.8.8
  • Update html-pptx-module-3.2.2
  • Update html-module-3.26.3
  • Update footnotes-module-3.2.3
  • Update error-location-module-3.2.2
  • Update docxtemplater to 3.22.3

3.11.9

  • Update to node 14.16.0
  • Update table-module-3.12.0
  • Update image-module-3.8.4
  • Update html-module-3.25.5
  • Add linebreak option

3.11.8

  • Update xlsx-module-3.4.3
  • Update to docxtemplater 3.21.1
  • Update table-module-3.11.4
  • Update html-module-3.25.3
  • Update footnotes-module-3.2.0
  • Update angular-expressions

3.11.7

  • Upgrade angular-expressions to 1.1.2
  • Update xlsx-module-3.4.1
  • Update table-module-3.11.3
  • Update subtemplate-module-3.6.1
  • Update subsection-module-3.3.7
  • Update node to 12.20.0
  • Update meta-module-3.2.3
  • Update image-module-3.8.3
  • Update html-pptx-module-3.2.0
  • Update html-module-3.25.0

3.11.6

  • Update xlsx-module-3.3.6
  • Update word-run-module-3.1.1
  • Update table-module-3.10.0
  • Update image-module-3.7.9
  • Update html-module-3.24.2
  • Update error-location-module-3.2.0
  • Update docxtemplater to 3.19.6
  • Add Table Merge module
  • Add support for ErrorLocationModule with pptx

3.11.5

  • Update html-module-3.24.0

3.11.4

  • Update xlsx-module-3.3.3

3.11.3

  • Update table-module-3.9.6
  • Update subtemplate-module-3.6.0
  • Update footnotes-module-3.1.4
  • Return 400 instead of 500 if doc is not a zipfile
  • Add support for subtemplateSubsections option

3.11.2

  • Update html-module-3.23.7
  • Update html-pptx-module-3.1.4
  • Update table-module-3.9.5
  • Update xlsx-module-3.3.2

3.11.1

  • Update dependencies
  • Update docxtemplater to 3.17.9
  • Update html-module-3.23.0
  • Update image-module-3.7.8
  • Update node to 12.18.1
  • Update styling-module-3.3.1
  • Update subtemplate-module-3.5.6
  • Update xlsx-module-3.3.0

3.11.0

  • Add pptx-sub module
  • Update angular-expressions to 1.1.1
  • Update docxtemplater to 3.17.5
  • Update error-location-module-3.1.6
  • Update footnotes-module-3.1.3
  • Update html-module-3.22.7
  • Update html-pptx-module-3.1.1
  • Update image-module-3.7.6
  • Update meta-module-3.2.2
  • Update paragraph-placeholder-module-3.2.2
  • Update pptx-sub-module-3.0.3
  • Update qrcode-module-3.2.3
  • Update slides-module-3.2.9
  • Update styling-module-3.2.1
  • Update subsection-module-3.3.6
  • Update subtemplate-module-3.5.4
  • Update table-module-3.9.4
  • Update to node 12.16.2
  • Update word-run-module-3.1.0
  • Update xlsx-module-3.2.8

3.10.2

  • Add html-pptx-module 3.0.1
  • Update meta-module to 3.2.0
  • Update xlsx-module to 3.1.6
  • Add support for data:image/svg

3.10.1

Fix vulnerability CVE-2020-5219, see advisory and github issue for more detail.

3.10.0

  • Update docxtemplater to 3.16.5
  • Update paragraph-placeholder to 3.2.0
  • Update paragraph-placeholder to 3.7.1
  • Update xlsx-module to 3.1.3

3.9.9

  • Update docxtemplater to 3.16.1
  • Update html-module-3.21.6
  • Update image-module-3.7.0
  • Update xlsx-module-3.1.2
  • Update table-module-3.9.2

3.9.8

  • Update docxtemplater to 3.15.4
  • Add optional subrendering of included documents
  • Update footnotes-module-3.1.1
  • Update html-module-3.21.5
  • Update image-module-3.6.1
  • Update meta-module-3.1.0
  • Update xlsx-module-3.1.1

3.9.7

  • Update to docxtemplater 3.14.10
  • Update html-module to 3.21.1
  • Update image-module to 3.6.0
  • Use updated angular-parser
  • Update paragraph-placeholder-module to 3.1.0

3.9.6

  • Add configuration.js
  • Update node to 12.13
  • Update table-module to 3.9.1
  • Update image-module to 3.5.4
  • Use pizzip

3.9.5

  • Do not crash if nullValues contain special characters
  • Update subtemplate-module 3.5.1
  • Update subsection-module 3.3.5

3.9.4

  • Add subloop filter (for xlsx module)

3.9.3

  • Update xlsx-module to 3.1.0
  • Update html-module to 3.20.3

3.9.2

  • Update word-run-module to 3.0.6
  • Update docxtemplater to 3.14.1
  • Update xlsx-module to 3.0.2
  • Update to node 12

3.9.1

  • Add paragraph-placeholder module v3.0.0
  • Update html-module-3.20.1
  • Update docxtemplater to 3.14.0
  • Update table-module-3.7.4

3.9.0

  • Update node to 10
  • Update html-module-3.18.4

3.8.0

  • Add xlsx-module-3.0.1
  • Update docxtemplater
  • Update html-module-3.18.2

3.7.10

  • Update html-module-3.18.0
  • Update table-module-3.7.3

3.7.9

  • Update subtemplate-module-3.5.0
  • Update slides-module-3.2.1
  • Update error-location-module-3.1.4
  • Update html-module-3.17.2

3.7.8

  • Update dependencies and docxtemplater to 3.11.3
  • Update html-module-3.16.9
  • Update table-module-3.7.2

3.7.7

  • Update html-module-3.16.8
  • Update docxtemplater to 3.11.1
  • Update node to 10.15.3
  • Update table-module-3.7.1

3.7.6

  • Add support for specifiying default image size

3.7.5

  • Add support for grid pptx module
  • Update image-module-3.5.3
  • Update table-module-3.6.1
  • Update styling-module-3.2.0

3.7.4

  • Update subsection-module-3.3.4
  • Update html-module-3.16.5

3.7.3

  • Update html-module-3.16.3

3.7.2

  • Add support for stylesheet in HTML module
  • Update html-module-3.16.1

3.7.1

  • Add support for setting delimiters
  • Output nullValues in headers
  • Update html-module-3.15.0
  • Update footnotes-module-3.1.0

3.7.0

  • Update Dockerfile to use multi-layered build/run
  • Update html-module-3.14.1
  • Update image-module-3.5.2
  • Update slides-module-3.2.0
  • Update subsection-module-3.3.1
  • Update table-module-3.6.0
  • Upgrade node to version 10.15.2

3.6.7

  • Update html-module-3.13.6

3.6.6

  • Update image-module-3.5.1
  • Update node to 8.15.0
  • Update subdependencies
  • Update subtemplate-module-3.4.8
  • Update table-module-3.5.4

3.6.5

  • Update image-module-3.4.2
  • Update html-module-3.13.4
  • Update docxtemplater to 3.9.2

3.6.4

  • Update table-module-3.5.3
  • Update html-module-3.13.3

3.6.3

  • Update html-module-3.13.0

3.6.2

  • Update html-module-3.11.10
  • Update subtemplate-module-3.4.7

3.6.1

  • Update html-module-3.11.5

3.6.0

  • Update node to 8.11.3
  • Update error-location-module-3.1.3
  • Update footnotes-module-3.0.7
  • Update html-module-3.10.5
  • Update image-module-3.3.4
  • Update meta-module-3.0.2
  • Update qrcode-module-3.2.1
  • Update slides-module-3.1.9
  • Update styling-module-3.1.4
  • Update subsection-module-3.2.4
  • Update subtemplate-module-3.4.5
  • Update table-module-3.5.1
  • Update table-module-3.5.2
  • Update word-run-module-3.0.5

3.5.12

  • Update html-module-3.10.1

3.5.11

  • Update html-module-3.10.0

3.5.10

  • Add grid module
  • Update table-module-3.5.0
  • Update error-location-module-3.1.1
  • Update footnotes-module-3.0.6
  • Update html-module-3.9.2
  • Update image-module-3.3.2
  • Update meta-module-3.0.1
  • Update qrcode-module-3.1.6
  • Update slides-module-3.1.8
  • Update styling-module-3.1.3
  • Update subsection-module-3.2.3
  • Update subtemplate-module-3.4.3
  • Update subtemplate-module-3.4.4
  • Update table-module-3.4.4
  • Update word-run-module-3.0.4

3.5.9

  • Update footnotes-module-3.0.5
  • Update html-module-3.8.4
  • Update image-module-3.3.1
  • Update qrcode-module-3.1.5
  • Update styling-module-3.1.2
  • Update subsection-module-3.2.2
  • Update subtemplate-module-3.4.2
  • Update table-module-3.4.3
  • Update word-run-module-3.0.3

3.5.8

  • Update docxtemplater to 3.6.6
  • Update error-location-module-3.1.0
  • Update footnotes-module-3.0.4
  • Update html-module-3.8.1
  • Update image-module-3.2.8
  • Update qrcode-module-3.1.4
  • Update styling-module-3.1.1
  • Update subsection-module-3.2.1
  • Update subtemplate-module-3.4.1
  • Update table-module-3.4.1
  • Update word-run-module-3.0.2

3.5.7

  • Update html-module 3.1.8

3.5.6

  • Update slides-module 3.1.7

3.5.5

  • Allow ’ and “ and ” as quotes in angularexpressions

3.5.4

  • Update style-module 3.1.0

3.5.3

  • Add support for base64 image/jpeg

3.5.2

  • Update html-module 3.7.1

3.5.1

  • Update html-module 3.7.0
  • Update image-module 3.2.7
  • Update slides-module 3.1.5

3.5.0

  • Add Footnotes module
  • Add Style module
  • Add meta module
  • Add word-run module

3.4.1

  • Update image-module-3.2.5
  • Update table-module-3.4.0
  • Update html-module-3.6.6

3.4.0

  • Update node version
  • Update HTMLModule to include ImageModule
  • Update html-module-3.6.4
  • Update table-module-3.3.1
  • Update docxtemplater@3.5.1
  • Update qrcode-module-3.1.3
  • Update image-module-3.2.4

3.3.5

  • Update html-module-3.6.1
  • Update image-module-3.2.2
  • Update slides-module-3.1.4
  • Update html-module-3.6.0
  • Update styling-module-3.0.0

3.3.4

  • Update subsection-module-3.1.0
  • Update slides-module-3.1.3
  • Update subtemplate-module-3.2.4
  • Update subtemplate-module-3.2.3

3.3.3

  • Update subsection-module-3.0.3
  • Update html-module-3.5.10
  • Update footnotes-module-3.0.3
  • Update image-module-3.2.1
  • Update qrcode-module-3.1.2
  • Update subtemplate-module-3.2.2

3.3.2

  • Add subsection-module-3.0.2
  • Update image-module-3.2.0
  • Update subsection-module-3.0.1
  • Update qrcode-module-3.1.1
  • Update subsection-module-3.0.0
  • Update subtemplate-module-3.2.1
  • Update table-module-3.3.0
  • Update table-module-3.2.3

3.3.1

  • Add paragraphLoop option

3.3.0

  • Update error-location-module-3.0.3
  • First iteration of error-location module
  • Update word-run-module-3.0.1
  • Update image-module-3.1.6
  • Update footnotes-module-3.0.2
  • Update html-module-3.5.9

3.2.8

  • Use logRequests for all routes

3.2.7

  • Update qrcode-module-3.1.0
  • Update image-module-3.1.5
  • Update html-module-3.5.8
  • Update html-module-3.5.7
  • Update subtemplate-module-3.2.0
  • Update subtemplate-module-3.1.9
  • Update subtemplate-module-3.1.8
  • Update html-module-3.5.6
  • Update subtemplate-module-3.1.7

3.2.6

First publicly released version