2018-04-24 22:56:56 +01:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
|
|
|
|
<head>
|
2018-08-23 01:12:54 +01:00
|
|
|
<script src="../build/index.js"></script>
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.js"></script>
|
2018-04-24 22:56:56 +01:00
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<h1>DOCX browser Word document generation</h1>
|
|
|
|
|
|
|
|
<button type="button" onclick="generate()">Click to generate document</button>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
function generate() {
|
2018-08-23 01:12:54 +01:00
|
|
|
const doc = new Document();
|
|
|
|
|
|
|
|
const paragraph = new Paragraph("Hello World");
|
|
|
|
const institutionText = new TextRun("Foo Bar").bold();
|
|
|
|
const dateText = new TextRun("Github is the best").tab().bold();
|
|
|
|
paragraph.addRun(institutionText);
|
|
|
|
paragraph.addRun(dateText);
|
|
|
|
|
2019-06-25 23:17:56 +01:00
|
|
|
doc.add(paragraph);
|
2018-08-23 01:12:54 +01:00
|
|
|
|
|
|
|
const packer = new Packer();
|
|
|
|
|
|
|
|
packer.toBlob(doc).then(blob => {
|
|
|
|
console.log(blob);
|
|
|
|
saveAs(blob, "example.docx");
|
|
|
|
console.log("Document created successfully");
|
|
|
|
});
|
2018-04-24 22:56:56 +01:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
|
|
|
|
</html>
|