DOCX Demo 1

node v10.24.1
version: 6.0.0
endpointsharetweet
const docx = require("docx@6.0.0") const express = require("@runkit/runkit/express-endpoint/1.0.0"); const app = express(exports); const { Document, Packer, Paragraph, TextRun } = docx; app.get("/", async (req, res) => { const doc = new Document({ sections: [{ properties: {}, children: [ new Paragraph({ children: [ new TextRun("Hello World"), new TextRun({ text: "Foo Bar", bold: true, }), new TextRun({ text: "\tGithub is the best", bold: true, }), ], }), ], }], }); const b64string = await Packer.toBase64String(doc); res.setHeader('Content-Disposition', 'attachment; filename=My Document.docx'); res.send(Buffer.from(b64string, 'base64')); })
Created from: https://runkit.com/docs/endpoint
Loading…

2 comments

  • posted 4 years ago by timgarciaa
    How to convert base64 string back on frontend to download?
  • posted a year ago by 6486b9777002de0012a1c057
    Anonmous

sign in to comment