hdoc-tools 0.9.27 → 0.9.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/hdoc-build-pdf.js
CHANGED
@@ -16,7 +16,8 @@
|
|
16
16
|
|
17
17
|
let css_files = [],
|
18
18
|
hb_logo = '',
|
19
|
-
footer = ''
|
19
|
+
footer = '',
|
20
|
+
header = '';
|
20
21
|
|
21
22
|
const file_callback = function (element) {
|
22
23
|
css_files.push(element.path);
|
@@ -32,6 +33,16 @@
|
|
32
33
|
return footer_content;
|
33
34
|
};
|
34
35
|
|
36
|
+
const get_header = function (template_path) {
|
37
|
+
let header_content = null;
|
38
|
+
try {
|
39
|
+
header_content = fs.readFileSync(path.join(template_path, 'template-header.html'), 'utf8');
|
40
|
+
} catch (err) {
|
41
|
+
console.log(`Error loading template: ${err}`);
|
42
|
+
}
|
43
|
+
return header_content;
|
44
|
+
};
|
45
|
+
|
35
46
|
exports.process_images = async function (file_path, html_source, verbose) {
|
36
47
|
const book_work_root = file_path.path.replace(file_path.relativePath, '');
|
37
48
|
if (verbose) console.log('Parsing img tags from HTML source');
|
@@ -117,7 +128,12 @@
|
|
117
128
|
}
|
118
129
|
}
|
119
130
|
|
120
|
-
|
131
|
+
// Cache header
|
132
|
+
if (header === '') {
|
133
|
+
header = get_header(pdf_template_path).replace('{{book_title}}', book_config.title).replace('{{hb_logo}}', hb_logo);
|
134
|
+
}
|
135
|
+
|
136
|
+
html_source = pdf_template_content.replace('{{book_title}}', book_config.title).replace('{{document_content}}', html_source);
|
121
137
|
|
122
138
|
// Create a new page
|
123
139
|
const page = await browser.newPage();
|
@@ -153,8 +169,14 @@
|
|
153
169
|
printBackground: true,
|
154
170
|
format: 'A4',
|
155
171
|
displayHeaderFooter: true,
|
156
|
-
headerTemplate:
|
157
|
-
footerTemplate: footer
|
172
|
+
headerTemplate: header,
|
173
|
+
footerTemplate: footer,
|
174
|
+
margin: {
|
175
|
+
top: "90px",
|
176
|
+
right: "30px",
|
177
|
+
bottom: "60px",
|
178
|
+
left: "30px"
|
179
|
+
}
|
158
180
|
});
|
159
181
|
if (verbose) console.log('PDF generation success.');
|
160
182
|
|
package/package.json
CHANGED
@@ -110,6 +110,10 @@ hr {
|
|
110
110
|
border-top: 1px solid var(--htl-c-divider-light);
|
111
111
|
}
|
112
112
|
|
113
|
+
h1 {
|
114
|
+
margin-top: -10px;
|
115
|
+
}
|
116
|
+
|
113
117
|
img,
|
114
118
|
svg {
|
115
119
|
display: inline-block;
|
@@ -139,17 +143,6 @@ video {
|
|
139
143
|
break-inside: avoid;
|
140
144
|
}
|
141
145
|
|
142
|
-
.header {
|
143
|
-
width: 100%;
|
144
|
-
position: relative;
|
145
|
-
}
|
146
|
-
|
147
|
-
.header img {
|
148
|
-
width: 150px;
|
149
|
-
float: right;
|
150
|
-
}
|
151
|
-
|
152
|
-
|
153
146
|
.after-bullets li:not(:last-child)::after {
|
154
147
|
content: "•";
|
155
148
|
padding-left: 5px;
|
@@ -0,0 +1,38 @@
|
|
1
|
+
<style>
|
2
|
+
.header {
|
3
|
+
width: 100%;
|
4
|
+
height: 60px;
|
5
|
+
position: relative;
|
6
|
+
margin-left: 28px;
|
7
|
+
margin-right: 28px;
|
8
|
+
margin-bottom: 20px;
|
9
|
+
margin-top: -5px;
|
10
|
+
}
|
11
|
+
|
12
|
+
.header img {
|
13
|
+
width: 140px;
|
14
|
+
margin-right: 5px;
|
15
|
+
margin-top: 6px;
|
16
|
+
margin-bottom: 12px;
|
17
|
+
float: right;
|
18
|
+
}
|
19
|
+
|
20
|
+
.header h3 {
|
21
|
+
font-size: 12px;
|
22
|
+
font-weight: light;
|
23
|
+
margin-left: 5px;
|
24
|
+
float: left;
|
25
|
+
margin-top: 10px;
|
26
|
+
}
|
27
|
+
.header hr {
|
28
|
+
border: none;
|
29
|
+
border-top: 1px solid rgba(60, 60, 60, 0.29);
|
30
|
+
}
|
31
|
+
</style>
|
32
|
+
|
33
|
+
<div class="header">
|
34
|
+
<img src="{{hb_logo}}" />
|
35
|
+
<h3>{{book_title}}</h3>
|
36
|
+
<div style="clear: both;"></div>
|
37
|
+
<hr/>
|
38
|
+
</div>
|
@@ -2,12 +2,6 @@
|
|
2
2
|
<html>
|
3
3
|
<head><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.9.1/font/bootstrap-icons.css" /></head>
|
4
4
|
<body>
|
5
|
-
<div class="header">
|
6
|
-
<img src="{{hb_logo}}" />
|
7
|
-
<h3>{{book_title}}</h3>
|
8
|
-
<div style="clear: both;"></div>
|
9
|
-
</div>
|
10
|
-
<hr>
|
11
5
|
{{document_content}}
|
12
6
|
</body>
|
13
7
|
</html>
|