spec-up-t 0.11.37 → 0.11.38
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/package.json +1 -1
- package/src/create-pdf.js +35 -29
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spec-up-t",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.38",
|
|
4
4
|
"description": "Technical specification drafting tool that generates rich specification documents from markdown. Forked from https://github.com/decentralized-identity/spec-up by Daniel Buchner (https://github.com/csuwildcat)",
|
|
5
5
|
"main": "./index",
|
|
6
6
|
"repository": {
|
package/src/create-pdf.js
CHANGED
|
@@ -2,38 +2,44 @@ const puppeteer = require('puppeteer');
|
|
|
2
2
|
const path = require('path');
|
|
3
3
|
|
|
4
4
|
(async () => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
try {
|
|
6
|
+
// Launch a new browser instance
|
|
7
|
+
const browser = await puppeteer.launch();
|
|
8
|
+
const page = await browser.newPage();
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
// Define the path to the HTML file based on the directory where the script is called from
|
|
11
|
+
const filePath = path.resolve(process.cwd(), 'docs/index.html');
|
|
12
|
+
const fileUrl = `file://${filePath}`;
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
// Navigate to the HTML file
|
|
15
|
+
await page.goto(fileUrl, { waitUntil: 'networkidle2' });
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
// Remove or hide the search bar or any other element
|
|
18
|
+
await page.evaluate(() => {
|
|
19
|
+
const displayNoneInPdf = document.querySelectorAll('#header span, #container-search-h7vc6omi2hr2880'); // Adjust the selector as needed
|
|
20
|
+
if (displayNoneInPdf) {
|
|
21
|
+
displayNoneInPdf.forEach((element) => {
|
|
22
|
+
element.remove();
|
|
23
|
+
// or
|
|
24
|
+
// element.style.display = 'none';
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
// Generate the PDF
|
|
30
|
+
await page.pdf({
|
|
31
|
+
path: path.resolve(process.cwd(), 'docs/index.pdf'), // Output file path
|
|
32
|
+
format: 'A4', // Paper format
|
|
33
|
+
printBackground: true, // Print background graphics
|
|
34
|
+
displayHeaderFooter: false, // Do not display header and footer
|
|
35
|
+
preferCSSPageSize: true // Use CSS-defined page size
|
|
36
|
+
});
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
// Close the browser instance
|
|
39
|
+
await browser.close();
|
|
40
|
+
|
|
41
|
+
console.log('PDF generated successfully! Find the PDF in the same directory as the index.html file.');
|
|
42
|
+
} catch (error) {
|
|
43
|
+
console.error('Error generating PDF:', error);
|
|
44
|
+
}
|
|
39
45
|
})();
|