-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocx.html
More file actions
116 lines (97 loc) · 3.72 KB
/
docx.html
File metadata and controls
116 lines (97 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML to DOCX Export Demo</title>
<link rel="icon" href="data:,">
<script src="./dist/html-docx-mini.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
margin: 0;
padding: 20px;
max-width: 800px;
margin: 0 auto;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}
#content {
border: 1px solid #ccc;
padding: 20px;
margin-top: 20px;
}
img {
max-width: 100%;
height: auto;
}
</style>
</head>
<body>
<h1>HTML to DOCX Export Demo</h1>
<button id="exportButton">Export to DOCX</button>
<div id="content">
<h2>Main Title</h2>
<p id="datetime"></p>
<p>Introduction content under the main title.</p>
<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg">
<rect x="10" y="10" width="180" height="180" fill="#f0f0f0" stroke="#000000" stroke-width="2" />
<circle cx="100" cy="100" r="50" fill="#ff6347" stroke="#000000" stroke-width="2" />
<text x="100" y="100" font-family="Arial" font-size="16" fill="#000000" text-anchor="middle"
dominant-baseline="middle">SVG Test</text>
</svg>
<img src="./sample.jpeg" alt="Sample Image at Main Title">
<h3>Section 1</h3>
<p>This is content in Section 1.</p>
<img src="./sample.jpeg" alt="Sample Image in Section 1">
<div>
<h4>Subsection 1.1</h4>
<p>Details in Subsection 1.1.</p>
<img src="./sample.jpeg" alt="Sample Image in Subsection 1.1">
<div>
<h5>Sub-subsection 1.1.1</h5>
<p>More detailed content in Sub-subsection 1.1.1.</p>
<img src="./sample.jpeg" alt="Sample Image in Sub-subsection 1.1.1">
</div>
<h4>Subsection 1.2</h4>
<p>Details in Subsection 1.2.</p>
</div>
<h3>Section 2</h3>
<p>This is content in Section 2.</p>
<div>
<h4>Subsection 2.1</h4>
<p>Details in Subsection 2.1.</p>
<img src="./sample.jpeg" alt="Sample Image in Subsection 2.1">
<div>
<h5>Sub-subsection 2.1.1</h5>
<p>More detailed content in Sub-subsection 2.1.1.</p>
</div>
</div>
</div>
<script>
// Generate and insert the current date-time stamp
document.getElementById('datetime').textContent = `Generated on: ${new Date().toLocaleString()}`;
// Event listener for the export button
document.getElementById('exportButton').addEventListener('click', function (event) {
event.preventDefault();
const exportButton = document.getElementById('exportButton');
exportButton.textContent = "Export in Progress...";
exportButton.disabled = true;
const contentElement = document.getElementById('content');
// Use the HtmlDocxMini library from the bundled script
HtmlDocxMini.exportHTMLDivToDocx(contentElement, 'exported-document.docx', {
creator: 'Your Name',
title: 'Exported Document',
description: 'A document generated from HTML content'
}, function () {
exportButton.textContent = "Export to DOCX";
exportButton.disabled = false;
});
});
</script>
</body>
</html>