spec-up-t 0.11.36 → 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.
Files changed (2) hide show
  1. package/package.json +2 -1
  2. package/src/create-pdf.js +45 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spec-up-t",
3
- "version": "0.11.36",
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": {
@@ -51,6 +51,7 @@
51
51
  "merge-stream": "2.0.0",
52
52
  "pkg-dir": "4.2.0",
53
53
  "prismjs": ">=1.24.0",
54
+ "puppeteer": "^23.2.1",
54
55
  "readline-sync": "^1.4.10",
55
56
  "yargs": "16.2.0"
56
57
  }
@@ -0,0 +1,45 @@
1
+ const puppeteer = require('puppeteer');
2
+ const path = require('path');
3
+
4
+ (async () => {
5
+ try {
6
+ // Launch a new browser instance
7
+ const browser = await puppeteer.launch();
8
+ const page = await browser.newPage();
9
+
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}`;
13
+
14
+ // Navigate to the HTML file
15
+ await page.goto(fileUrl, { waitUntil: 'networkidle2' });
16
+
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
+ });
28
+
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
+ });
37
+
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
+ }
45
+ })();