Files
docx-js/demo/74-nodejs-stream.ts

31 lines
928 B
TypeScript
Raw Normal View History

2022-09-19 20:48:50 +01:00
// Exporting the document as a stream
2022-08-22 15:26:52 -05:00
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
2022-10-29 15:10:02 +01:00
import { Document, Packer, Paragraph, Tab, TextRun } from "../build";
2022-08-22 15:26:52 -05:00
const doc = new Document({
sections: [
{
properties: {},
children: [
new Paragraph({
children: [
new TextRun("Hello World"),
new TextRun({
text: "Foo Bar",
bold: true,
}),
new TextRun({
2022-10-29 15:10:02 +01:00
children: [new Tab(), "Github is the best"],
2022-08-22 15:26:52 -05:00
bold: true,
}),
],
}),
],
},
],
});
2022-09-19 20:48:50 +01:00
const stream = Packer.toStream(doc);
stream.pipe(fs.createWriteStream("My Document.docx"));