DOCX Demo 3

node v10.17.0
version: 4.0.0
endpointsharetweet
const docx = require('docx@4.0.0'); const express = require("@runkit/runkit/express-endpoint/1.0.0"); const app = express(exports); const { Document, Indent, Numbering, Paragraph, Packer } = docx; app.get("/", async (req, res) => { const doc = new Document(); const numbering = new Numbering(); const abstractNum = numbering.createAbstractNumbering(); abstractNum.createLevel(0, "upperRoman", "%1", "start") .addParagraphProperty(new Indent(720, 260)); abstractNum.createLevel(1, "decimal", "%2.", "start") .addParagraphProperty(new Indent(1440, 980)); abstractNum.createLevel(2, "lowerLetter", "%3)", "start") .addParagraphProperty(new Indent(2160, 1700)); const concrete = numbering.createConcreteNumbering(abstractNum); const topLevelP = new Paragraph("Hey you"); const subP = new Paragraph("What's up fam"); const secondSubP = new Paragraph("Hello World 2"); const subSubP = new Paragraph("Yeah boi"); topLevelP.setNumbering(concrete, 0); subP.setNumbering(concrete, 1); secondSubP.setNumbering(concrete, 1); subSubP.setNumbering(concrete, 2); doc.addParagraph(topLevelP); doc.addParagraph(subP); doc.addParagraph(secondSubP); doc.addParagraph(subSubP); 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')); });
Loading…

no comments

    sign in to comment