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() {
|
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
|
|
|
],
|
|
|
|
});
|
|
|
|
|
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>
|