DOCX Demo 8

node v10.17.0
version: 4.0.0
// docx header and footer demo const docx = require('docx@4.0.0'); const express = require("@runkit/runkit/express-endpoint/1.0.0"); const app = express(exports); const { Document, Paragraph, Packer } = docx; app.get("/", async (req, res) => { const doc = new Document(); doc.createParagraph("Hello World"); doc.Header.createParagraph("Header text"); doc.Footer.createParagraph("Footer text"); const packer = new Packer(); const b64string = await packer.toBase64String(doc); res.setHeader('Content-Disposition', 'attachment; filename=My Document.docx'); res.send(Buffer.from(b64string, 'base64')); });

no comments

    sign in to comment