Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

DOCX Demo 6

node v10.24.1
version: 6.0.0
endpointsharetweet
const docx = require('docx@6.0.1'); const express = require("@runkit/runkit/express-endpoint/1.0.0"); const app = express(exports); const { Document, HeadingLevel, Packer, Paragraph, TextRun } = docx; app.get("/", async (req, res) => { const doc = new Document({ sections: [{ margins: { top: 0, right: 0, bottom: 0, left: 0, }, children: [ new Paragraph({ children: [ new TextRun("Hello World"), new TextRun({ text: "Foo bar", bold: true, }), new TextRun({ text: "\tGithub is the best", bold: true, }), ], }), new Paragraph({ text: "Hello World", heading: HeadingLevel.HEADING_1, }), new Paragraph("Foo bar"), new Paragraph("Github is the best"), ], }], }); const b64string = await Packer.toBase64String(doc); res.setHeader('Content-Disposition', 'attachment; filename=My Document.docx'); res.send(Buffer.from(b64string, 'base64')); });
Loading…

no comments

    sign in to comment