Skip to content

Instantly share code, notes, and snippets.

@JasonHarrop
JasonHarrop / node-docx-to-pdf.js
Created March 21, 2019 05:46
Convert a Word document (here its in a node buffer) to PDF using docx-wasm
const docx = require("@nativedocuments/docx-wasm");
// init docx engine
docx.init({
ND_DEV_ID: "4H2I80DDEVNAJQSGGIC3K98N8S",
ND_DEV_SECRET: "3CTNJA7DBQFA8UDV2GM8I60N38",
// ND_DEV_ID: "XXXXXXXXXXXXXXXXXXXXXXXXXX", // goto https://developers.nativedocuments.com/ to get a dev-id/dev-secret
// ND_DEV_SECRET: "YYYYYYYYYYYYYYYYYYYYYYYYYY", // you can also set the credentials in the enviroment variables
ENVIRONMENT: "NODE", // required
LAZY_INIT: true // if set to false the WASM engine will be initialized right now, usefull pre-caching (like e.g. for AWS lambda)
@JasonHarrop
JasonHarrop / invoice-template-docx.js
Last active March 21, 2019 21:39
docxtemplater sample code applying invoice data to a docx to create an invoice instance
var JSZip = require('jszip');
var Docxtemplater = require('docxtemplater');
var fs = require('fs');
var path = require('path');
//Load the docx file as a binary
var content = fs
.readFileSync(path.resolve(__dirname, 'invoice-template.docx'), 'binary');
@JasonHarrop
JasonHarrop / invoice-data.json
Created March 21, 2019 05:36
Sample invoice data
{CustomerName : "Microsoft Corp",
AddressLine1: "One Microsoft Way",
City: "Redmond", State: "WA", Zip: "98052",
Country: "USA",
InvoiceDate : "14 March 2019",
InvoiceNumber: "INV123",
Items: [
{
Item_Description: "Bananas",
Item_Price: "5",
@JasonHarrop
JasonHarrop / docx-template-to-pdf.js
Last active May 23, 2022 16:10
Create PDF proposals, invoices, contracts etc in Javascript from a suitable Word document template
// Step 1: generate docx
var JSZip = require('jszip');
var Docxtemplater = require('docxtemplater');
var fs = require('fs');
var path = require('path');
//Load the docx file as a binary
var content = fs