2018-04-24 22:56:56 +01:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
2019-07-31 08:48:02 +01:00
|
|
|
<head>
|
|
|
|
<script src="../build/index.js"></script>
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.js"></script>
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
<h1>DOCX browser Word document generation</h1>
|
|
|
|
|
|
|
|
<button type="button" onclick="generate()">Click to generate document</button>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
function generate() {
|
2019-10-12 22:16:36 +01:00
|
|
|
const doc = new docx.Document();
|
2019-07-31 08:48:02 +01:00
|
|
|
|
|
|
|
doc.addSection({
|
|
|
|
children: [
|
2019-10-12 22:16:36 +01:00
|
|
|
new docx.Paragraph({
|
2019-07-31 08:48:02 +01:00
|
|
|
children: [
|
2019-10-12 22:16:36 +01:00
|
|
|
new docx.TextRun("Hello World"),
|
|
|
|
new docx.TextRun({
|
2019-07-31 08:48:02 +01:00
|
|
|
text: "Foo Bar",
|
|
|
|
bold: true,
|
|
|
|
}),
|
2019-10-12 22:16:36 +01:00
|
|
|
new docx.TextRun({
|
2019-07-31 08:48:02 +01:00
|
|
|
text: "Github is the best",
|
|
|
|
bold: true,
|
|
|
|
}).tab(),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2019-08-07 22:12:14 +01:00
|
|
|
|
2019-10-12 22:16:36 +01:00
|
|
|
docx.Packer.toBlob(doc).then((blob) => {
|
2019-07-31 08:48:02 +01:00
|
|
|
console.log(blob);
|
|
|
|
saveAs(blob, "example.docx");
|
|
|
|
console.log("Document created successfully");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</body>
|
2018-04-24 22:56:56 +01:00
|
|
|
</html>
|