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

46 lines
1.6 KiB
HTML
Raw Normal View History

2023-07-21 20:11:52 +01:00
<!doctype html>
<html>
2019-07-31 08:48:02 +01:00
<head>
2023-07-18 01:53:56 +01:00
<script src="../build/index.umd.js"></script>
2019-07-31 08:48:02 +01:00
<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() {
2021-03-31 21:27:40 +01:00
const doc = new docx.Document({
2021-03-19 20:53:56 +00:00
sections: [
{
2019-07-31 08:48:02 +01:00
children: [
2021-03-19 20:53:56 +00:00
new docx.Paragraph({
children: [
new docx.TextRun("Hello World"),
new docx.TextRun({
text: "Foo Bar",
bold: true,
}),
new docx.TextRun({
2022-10-29 15:10:02 +01:00
children: [new docx.Tab(), "Github is the best"],
2021-03-19 20:53:56 +00:00
bold: true,
}),
],
2019-11-21 01:02:46 +00:00
}),
2019-07-31 08:48:02 +01:00
],
2021-03-19 20:53:56 +00:00
},
2019-07-31 08:48:02 +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>