Files
docx-js/demo/browser-demo.html

46 lines
1.4 KiB
HTML
Raw Normal View History

<!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() {
const doc = new docx.Document();
2019-07-31 08:48:02 +01:00
doc.addSection({
children: [
new docx.Paragraph({
2019-07-31 08:48:02 +01:00
children: [
new docx.TextRun("Hello World"),
new docx.TextRun({
2019-07-31 08:48:02 +01:00
text: "Foo Bar",
bold: true,
}),
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
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>
</html>