ghost-paper 0.2.0 → 0.3.1
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/README.md +5 -3
- package/dist/{-5YRZFEDB.js → -7SCHCOLC.js} +1 -1
- package/dist/{chunk-B7BSOHDL.js → chunk-QUOENJTZ.js} +22 -0
- package/dist/cli.js +5 -4
- package/package.json +2 -2
- package/dist/-6A745MKY.js +0 -10
- package/dist/-ANANGS26.js +0 -10
- package/dist/-EON5YM73.js +0 -10
- package/dist/-FCFRRCIG.js +0 -10
- package/dist/-G2AWPUXZ.js +0 -10
- package/dist/-HRRPL4SN.js +0 -10
- package/dist/-K6SQE2E5.js +0 -10
- package/dist/-N6RDWVBC.js +0 -10
- package/dist/-NRPITI2A.js +0 -10
- package/dist/-OKZHAHO3.js +0 -10
- package/dist/-RMMSGBXC.js +0 -10
- package/dist/-RZB6N6OZ.js +0 -10
- package/dist/-TG5MSQYZ.js +0 -10
- package/dist/-TTLTI6LQ.js +0 -10
- package/dist/-U5MQJGM2.js +0 -10
- package/dist/-YCMFHAET.js +0 -10
- package/dist/chunk-2QOHE4NF.js +0 -1464
- package/dist/chunk-3HX4SVJH.js +0 -1504
- package/dist/chunk-4P2YAHD2.js +0 -1522
- package/dist/chunk-6WF3MSUR.js +0 -1362
- package/dist/chunk-DSRRH4T2.js +0 -1425
- package/dist/chunk-J2XA7LOH.js +0 -1463
- package/dist/chunk-MNZVZ2ZA.js +0 -1464
- package/dist/chunk-NUWIGEJ3.js +0 -1462
- package/dist/chunk-QMHJ3BGD.js +0 -1471
- package/dist/chunk-RMODJYHI.js +0 -1526
- package/dist/chunk-SOKYK7YV.js +0 -1496
- package/dist/chunk-TV6ABXBU.js +0 -1534
- package/dist/chunk-TW7HQTU6.js +0 -1444
- package/dist/chunk-U2G5K2PR.js +0 -1465
- package/dist/chunk-UWUILD43.js +0 -1471
- package/dist/chunk-ZRSWDAXH.js +0 -1433
- package/dist/pdf-ADH6BBSB.js +0 -71
- package/dist/pdf-EDRHZK4V.js +0 -72
- package/dist/pdf-HC6MMT72.js +0 -62
- package/dist/pdf-SKUNOP45.js +0 -62
- package/dist/pdf-TQDMPPSC.js +0 -71
- package/dist/pdf-VCMDLIDX.js +0 -71
- package/dist/pdf-WLYWKSHR.js +0 -71
package/dist/pdf-ADH6BBSB.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
// src/pdf.ts
|
|
2
|
-
import { existsSync } from "fs";
|
|
3
|
-
import { writeFile } from "fs/promises";
|
|
4
|
-
var CHROME_PATHS = {
|
|
5
|
-
darwin: [
|
|
6
|
-
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
|
7
|
-
"/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
|
|
8
|
-
"/Applications/Chromium.app/Contents/MacOS/Chromium"
|
|
9
|
-
],
|
|
10
|
-
linux: [
|
|
11
|
-
"/usr/bin/google-chrome",
|
|
12
|
-
"/usr/bin/google-chrome-stable",
|
|
13
|
-
"/usr/bin/chromium",
|
|
14
|
-
"/usr/bin/chromium-browser",
|
|
15
|
-
"/snap/bin/chromium"
|
|
16
|
-
],
|
|
17
|
-
win32: [
|
|
18
|
-
"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe",
|
|
19
|
-
"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
|
|
20
|
-
]
|
|
21
|
-
};
|
|
22
|
-
function findChrome() {
|
|
23
|
-
const envPath = process.env.CHROME_PATH;
|
|
24
|
-
if (envPath && existsSync(envPath)) return envPath;
|
|
25
|
-
const candidates = CHROME_PATHS[process.platform] ?? [];
|
|
26
|
-
for (const p of candidates) {
|
|
27
|
-
if (existsSync(p)) return p;
|
|
28
|
-
}
|
|
29
|
-
throw new Error(
|
|
30
|
-
"Chrome not found. Install Google Chrome or set CHROME_PATH environment variable."
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
function escapeHtml(s) {
|
|
34
|
-
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
35
|
-
}
|
|
36
|
-
async function generatePdf(opts) {
|
|
37
|
-
const chromePath = findChrome();
|
|
38
|
-
const puppeteer = await import("puppeteer-core");
|
|
39
|
-
const browser = await puppeteer.default.launch({
|
|
40
|
-
executablePath: chromePath,
|
|
41
|
-
headless: true,
|
|
42
|
-
args: ["--no-sandbox", "--disable-setuid-sandbox"]
|
|
43
|
-
});
|
|
44
|
-
try {
|
|
45
|
-
const page = await browser.newPage();
|
|
46
|
-
await page.setContent(opts.html, { waitUntil: "networkidle0" });
|
|
47
|
-
await page.waitForFunction("!!window.__ghostPaperChartsReady", {
|
|
48
|
-
timeout: 15e3
|
|
49
|
-
});
|
|
50
|
-
await new Promise((r) => setTimeout(r, 300));
|
|
51
|
-
const title = escapeHtml(opts.title ?? "");
|
|
52
|
-
const headerTemplate = `<div style="font-size: 8px; font-family: -apple-system, system-ui, sans-serif; color: #999; width: 100%; padding: 0 1.1in 0 1.14in; letter-spacing: 0.5px; text-transform: uppercase;">${title}</div>`;
|
|
53
|
-
const footerTemplate = `<div style="font-size: 8px; font-family: -apple-system, system-ui, sans-serif; color: #999; width: 100%; text-align: right; padding: 0 1.1in 0 1.14in;"><span class="pageNumber"></span> / <span class="totalPages"></span></div>`;
|
|
54
|
-
const pdfBuffer = await page.pdf({
|
|
55
|
-
format: opts.pageSize ?? "A4",
|
|
56
|
-
landscape: opts.landscape ?? false,
|
|
57
|
-
margin: { top: "0.75in", right: "1.1in", bottom: "0.75in", left: "0.5in" },
|
|
58
|
-
printBackground: true,
|
|
59
|
-
displayHeaderFooter: true,
|
|
60
|
-
headerTemplate,
|
|
61
|
-
footerTemplate
|
|
62
|
-
});
|
|
63
|
-
await writeFile(opts.outputPath, pdfBuffer);
|
|
64
|
-
} finally {
|
|
65
|
-
await browser.close();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
export {
|
|
69
|
-
findChrome,
|
|
70
|
-
generatePdf
|
|
71
|
-
};
|
package/dist/pdf-EDRHZK4V.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
// src/pdf.ts
|
|
2
|
-
import { existsSync } from "fs";
|
|
3
|
-
import { writeFile } from "fs/promises";
|
|
4
|
-
var CHROME_PATHS = {
|
|
5
|
-
darwin: [
|
|
6
|
-
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
|
7
|
-
"/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
|
|
8
|
-
"/Applications/Chromium.app/Contents/MacOS/Chromium"
|
|
9
|
-
],
|
|
10
|
-
linux: [
|
|
11
|
-
"/usr/bin/google-chrome",
|
|
12
|
-
"/usr/bin/google-chrome-stable",
|
|
13
|
-
"/usr/bin/chromium",
|
|
14
|
-
"/usr/bin/chromium-browser",
|
|
15
|
-
"/snap/bin/chromium"
|
|
16
|
-
],
|
|
17
|
-
win32: [
|
|
18
|
-
"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe",
|
|
19
|
-
"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
|
|
20
|
-
]
|
|
21
|
-
};
|
|
22
|
-
function findChrome() {
|
|
23
|
-
const envPath = process.env.CHROME_PATH;
|
|
24
|
-
if (envPath && existsSync(envPath)) return envPath;
|
|
25
|
-
const candidates = CHROME_PATHS[process.platform] ?? [];
|
|
26
|
-
for (const p of candidates) {
|
|
27
|
-
if (existsSync(p)) return p;
|
|
28
|
-
}
|
|
29
|
-
throw new Error(
|
|
30
|
-
"Chrome not found. Install Google Chrome or set CHROME_PATH environment variable."
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
function escapeHtml(s) {
|
|
34
|
-
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
35
|
-
}
|
|
36
|
-
async function generatePdf(opts) {
|
|
37
|
-
const chromePath = findChrome();
|
|
38
|
-
const puppeteer = await import("puppeteer-core");
|
|
39
|
-
const browser = await puppeteer.default.launch({
|
|
40
|
-
executablePath: chromePath,
|
|
41
|
-
headless: true,
|
|
42
|
-
args: ["--no-sandbox", "--disable-setuid-sandbox"]
|
|
43
|
-
});
|
|
44
|
-
try {
|
|
45
|
-
const page = await browser.newPage();
|
|
46
|
-
await page.setViewport({ width: 1200, height: 800, deviceScaleFactor: 2 });
|
|
47
|
-
await page.setContent(opts.html, { waitUntil: "networkidle0" });
|
|
48
|
-
await page.waitForFunction("!!window.__ghostPaperChartsReady", {
|
|
49
|
-
timeout: 15e3
|
|
50
|
-
});
|
|
51
|
-
await new Promise((r) => setTimeout(r, 300));
|
|
52
|
-
const title = escapeHtml(opts.title ?? "");
|
|
53
|
-
const headerTemplate = `<div style="font-size: 8px; font-family: -apple-system, system-ui, sans-serif; color: #999; width: 100%; padding: 0 0.65in; letter-spacing: 0.5px; text-transform: uppercase;">${title}</div>`;
|
|
54
|
-
const footerTemplate = `<div style="font-size: 8px; font-family: -apple-system, system-ui, sans-serif; color: #999; width: 100%; text-align: right; padding: 0 0.65in;"><span class="pageNumber"></span> / <span class="totalPages"></span></div>`;
|
|
55
|
-
const pdfBuffer = await page.pdf({
|
|
56
|
-
format: opts.pageSize ?? "A4",
|
|
57
|
-
landscape: opts.landscape ?? false,
|
|
58
|
-
margin: { top: "0.7in", right: "0.65in", bottom: "0.7in", left: "0.65in" },
|
|
59
|
-
printBackground: true,
|
|
60
|
-
displayHeaderFooter: true,
|
|
61
|
-
headerTemplate,
|
|
62
|
-
footerTemplate
|
|
63
|
-
});
|
|
64
|
-
await writeFile(opts.outputPath, pdfBuffer);
|
|
65
|
-
} finally {
|
|
66
|
-
await browser.close();
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
export {
|
|
70
|
-
findChrome,
|
|
71
|
-
generatePdf
|
|
72
|
-
};
|
package/dist/pdf-HC6MMT72.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
// src/pdf.ts
|
|
2
|
-
import { existsSync } from "fs";
|
|
3
|
-
import { writeFile } from "fs/promises";
|
|
4
|
-
var CHROME_PATHS = {
|
|
5
|
-
darwin: [
|
|
6
|
-
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
|
7
|
-
"/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
|
|
8
|
-
"/Applications/Chromium.app/Contents/MacOS/Chromium"
|
|
9
|
-
],
|
|
10
|
-
linux: [
|
|
11
|
-
"/usr/bin/google-chrome",
|
|
12
|
-
"/usr/bin/google-chrome-stable",
|
|
13
|
-
"/usr/bin/chromium",
|
|
14
|
-
"/usr/bin/chromium-browser",
|
|
15
|
-
"/snap/bin/chromium"
|
|
16
|
-
],
|
|
17
|
-
win32: [
|
|
18
|
-
"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe",
|
|
19
|
-
"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
|
|
20
|
-
]
|
|
21
|
-
};
|
|
22
|
-
function findChrome() {
|
|
23
|
-
const envPath = process.env.CHROME_PATH;
|
|
24
|
-
if (envPath && existsSync(envPath)) return envPath;
|
|
25
|
-
const candidates = CHROME_PATHS[process.platform] ?? [];
|
|
26
|
-
for (const p of candidates) {
|
|
27
|
-
if (existsSync(p)) return p;
|
|
28
|
-
}
|
|
29
|
-
throw new Error(
|
|
30
|
-
"Chrome not found. Install Google Chrome or set CHROME_PATH environment variable."
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
async function generatePdf(opts) {
|
|
34
|
-
const chromePath = findChrome();
|
|
35
|
-
const puppeteer = await import("puppeteer-core");
|
|
36
|
-
const browser = await puppeteer.default.launch({
|
|
37
|
-
executablePath: chromePath,
|
|
38
|
-
headless: true,
|
|
39
|
-
args: ["--no-sandbox", "--disable-setuid-sandbox"]
|
|
40
|
-
});
|
|
41
|
-
try {
|
|
42
|
-
const page = await browser.newPage();
|
|
43
|
-
await page.setContent(opts.html, { waitUntil: "networkidle0" });
|
|
44
|
-
await page.waitForFunction("!!window.__ghostPaperChartsReady", {
|
|
45
|
-
timeout: 15e3
|
|
46
|
-
});
|
|
47
|
-
await new Promise((r) => setTimeout(r, 300));
|
|
48
|
-
const pdfBuffer = await page.pdf({
|
|
49
|
-
format: opts.pageSize ?? "A4",
|
|
50
|
-
landscape: opts.landscape ?? false,
|
|
51
|
-
margin: { top: "48px", right: "48px", bottom: "48px", left: "48px" },
|
|
52
|
-
printBackground: true
|
|
53
|
-
});
|
|
54
|
-
await writeFile(opts.outputPath, pdfBuffer);
|
|
55
|
-
} finally {
|
|
56
|
-
await browser.close();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
export {
|
|
60
|
-
findChrome,
|
|
61
|
-
generatePdf
|
|
62
|
-
};
|
package/dist/pdf-SKUNOP45.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
// src/pdf.ts
|
|
2
|
-
import { existsSync } from "fs";
|
|
3
|
-
import { writeFile } from "fs/promises";
|
|
4
|
-
var CHROME_PATHS = {
|
|
5
|
-
darwin: [
|
|
6
|
-
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
|
7
|
-
"/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
|
|
8
|
-
"/Applications/Chromium.app/Contents/MacOS/Chromium"
|
|
9
|
-
],
|
|
10
|
-
linux: [
|
|
11
|
-
"/usr/bin/google-chrome",
|
|
12
|
-
"/usr/bin/google-chrome-stable",
|
|
13
|
-
"/usr/bin/chromium",
|
|
14
|
-
"/usr/bin/chromium-browser",
|
|
15
|
-
"/snap/bin/chromium"
|
|
16
|
-
],
|
|
17
|
-
win32: [
|
|
18
|
-
"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe",
|
|
19
|
-
"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
|
|
20
|
-
]
|
|
21
|
-
};
|
|
22
|
-
function findChrome() {
|
|
23
|
-
const envPath = process.env.CHROME_PATH;
|
|
24
|
-
if (envPath && existsSync(envPath)) return envPath;
|
|
25
|
-
const candidates = CHROME_PATHS[process.platform] ?? [];
|
|
26
|
-
for (const p of candidates) {
|
|
27
|
-
if (existsSync(p)) return p;
|
|
28
|
-
}
|
|
29
|
-
throw new Error(
|
|
30
|
-
"Chrome not found. Install Google Chrome or set CHROME_PATH environment variable."
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
async function generatePdf(opts) {
|
|
34
|
-
const chromePath = findChrome();
|
|
35
|
-
const puppeteer = await import("puppeteer-core");
|
|
36
|
-
const browser = await puppeteer.default.launch({
|
|
37
|
-
executablePath: chromePath,
|
|
38
|
-
headless: true,
|
|
39
|
-
args: ["--no-sandbox", "--disable-setuid-sandbox"]
|
|
40
|
-
});
|
|
41
|
-
try {
|
|
42
|
-
const page = await browser.newPage();
|
|
43
|
-
await page.setContent(opts.html, { waitUntil: "networkidle0" });
|
|
44
|
-
await page.waitForFunction("!!window.__ghostPaperChartsReady", {
|
|
45
|
-
timeout: 15e3
|
|
46
|
-
});
|
|
47
|
-
await new Promise((r) => setTimeout(r, 300));
|
|
48
|
-
const pdfBuffer = await page.pdf({
|
|
49
|
-
format: opts.pageSize ?? "A4",
|
|
50
|
-
landscape: opts.landscape ?? false,
|
|
51
|
-
margin: { top: "56px", right: "56px", bottom: "56px", left: "56px" },
|
|
52
|
-
printBackground: true
|
|
53
|
-
});
|
|
54
|
-
await writeFile(opts.outputPath, pdfBuffer);
|
|
55
|
-
} finally {
|
|
56
|
-
await browser.close();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
export {
|
|
60
|
-
findChrome,
|
|
61
|
-
generatePdf
|
|
62
|
-
};
|
package/dist/pdf-TQDMPPSC.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
// src/pdf.ts
|
|
2
|
-
import { existsSync } from "fs";
|
|
3
|
-
import { writeFile } from "fs/promises";
|
|
4
|
-
var CHROME_PATHS = {
|
|
5
|
-
darwin: [
|
|
6
|
-
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
|
7
|
-
"/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
|
|
8
|
-
"/Applications/Chromium.app/Contents/MacOS/Chromium"
|
|
9
|
-
],
|
|
10
|
-
linux: [
|
|
11
|
-
"/usr/bin/google-chrome",
|
|
12
|
-
"/usr/bin/google-chrome-stable",
|
|
13
|
-
"/usr/bin/chromium",
|
|
14
|
-
"/usr/bin/chromium-browser",
|
|
15
|
-
"/snap/bin/chromium"
|
|
16
|
-
],
|
|
17
|
-
win32: [
|
|
18
|
-
"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe",
|
|
19
|
-
"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
|
|
20
|
-
]
|
|
21
|
-
};
|
|
22
|
-
function findChrome() {
|
|
23
|
-
const envPath = process.env.CHROME_PATH;
|
|
24
|
-
if (envPath && existsSync(envPath)) return envPath;
|
|
25
|
-
const candidates = CHROME_PATHS[process.platform] ?? [];
|
|
26
|
-
for (const p of candidates) {
|
|
27
|
-
if (existsSync(p)) return p;
|
|
28
|
-
}
|
|
29
|
-
throw new Error(
|
|
30
|
-
"Chrome not found. Install Google Chrome or set CHROME_PATH environment variable."
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
function escapeHtml(s) {
|
|
34
|
-
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
35
|
-
}
|
|
36
|
-
async function generatePdf(opts) {
|
|
37
|
-
const chromePath = findChrome();
|
|
38
|
-
const puppeteer = await import("puppeteer-core");
|
|
39
|
-
const browser = await puppeteer.default.launch({
|
|
40
|
-
executablePath: chromePath,
|
|
41
|
-
headless: true,
|
|
42
|
-
args: ["--no-sandbox", "--disable-setuid-sandbox"]
|
|
43
|
-
});
|
|
44
|
-
try {
|
|
45
|
-
const page = await browser.newPage();
|
|
46
|
-
await page.setContent(opts.html, { waitUntil: "networkidle0" });
|
|
47
|
-
await page.waitForFunction("!!window.__ghostPaperChartsReady", {
|
|
48
|
-
timeout: 15e3
|
|
49
|
-
});
|
|
50
|
-
await new Promise((r) => setTimeout(r, 300));
|
|
51
|
-
const title = escapeHtml(opts.title ?? "");
|
|
52
|
-
const headerTemplate = `<div style="font-size: 8px; font-family: -apple-system, system-ui, sans-serif; color: #999; width: 100%; padding: 0 0.65in; letter-spacing: 0.5px; text-transform: uppercase;">${title}</div>`;
|
|
53
|
-
const footerTemplate = `<div style="font-size: 8px; font-family: -apple-system, system-ui, sans-serif; color: #999; width: 100%; text-align: right; padding: 0 0.65in;"><span class="pageNumber"></span> / <span class="totalPages"></span></div>`;
|
|
54
|
-
const pdfBuffer = await page.pdf({
|
|
55
|
-
format: opts.pageSize ?? "A4",
|
|
56
|
-
landscape: opts.landscape ?? false,
|
|
57
|
-
margin: { top: "0.7in", right: "0.65in", bottom: "0.7in", left: "0.65in" },
|
|
58
|
-
printBackground: true,
|
|
59
|
-
displayHeaderFooter: true,
|
|
60
|
-
headerTemplate,
|
|
61
|
-
footerTemplate
|
|
62
|
-
});
|
|
63
|
-
await writeFile(opts.outputPath, pdfBuffer);
|
|
64
|
-
} finally {
|
|
65
|
-
await browser.close();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
export {
|
|
69
|
-
findChrome,
|
|
70
|
-
generatePdf
|
|
71
|
-
};
|
package/dist/pdf-VCMDLIDX.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
// src/pdf.ts
|
|
2
|
-
import { existsSync } from "fs";
|
|
3
|
-
import { writeFile } from "fs/promises";
|
|
4
|
-
var CHROME_PATHS = {
|
|
5
|
-
darwin: [
|
|
6
|
-
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
|
7
|
-
"/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
|
|
8
|
-
"/Applications/Chromium.app/Contents/MacOS/Chromium"
|
|
9
|
-
],
|
|
10
|
-
linux: [
|
|
11
|
-
"/usr/bin/google-chrome",
|
|
12
|
-
"/usr/bin/google-chrome-stable",
|
|
13
|
-
"/usr/bin/chromium",
|
|
14
|
-
"/usr/bin/chromium-browser",
|
|
15
|
-
"/snap/bin/chromium"
|
|
16
|
-
],
|
|
17
|
-
win32: [
|
|
18
|
-
"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe",
|
|
19
|
-
"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
|
|
20
|
-
]
|
|
21
|
-
};
|
|
22
|
-
function findChrome() {
|
|
23
|
-
const envPath = process.env.CHROME_PATH;
|
|
24
|
-
if (envPath && existsSync(envPath)) return envPath;
|
|
25
|
-
const candidates = CHROME_PATHS[process.platform] ?? [];
|
|
26
|
-
for (const p of candidates) {
|
|
27
|
-
if (existsSync(p)) return p;
|
|
28
|
-
}
|
|
29
|
-
throw new Error(
|
|
30
|
-
"Chrome not found. Install Google Chrome or set CHROME_PATH environment variable."
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
function escapeHtml(s) {
|
|
34
|
-
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
35
|
-
}
|
|
36
|
-
async function generatePdf(opts) {
|
|
37
|
-
const chromePath = findChrome();
|
|
38
|
-
const puppeteer = await import("puppeteer-core");
|
|
39
|
-
const browser = await puppeteer.default.launch({
|
|
40
|
-
executablePath: chromePath,
|
|
41
|
-
headless: true,
|
|
42
|
-
args: ["--no-sandbox", "--disable-setuid-sandbox"]
|
|
43
|
-
});
|
|
44
|
-
try {
|
|
45
|
-
const page = await browser.newPage();
|
|
46
|
-
await page.setContent(opts.html, { waitUntil: "networkidle0" });
|
|
47
|
-
await page.waitForFunction("!!window.__ghostPaperChartsReady", {
|
|
48
|
-
timeout: 15e3
|
|
49
|
-
});
|
|
50
|
-
await new Promise((r) => setTimeout(r, 300));
|
|
51
|
-
const title = escapeHtml(opts.title ?? "");
|
|
52
|
-
const headerTemplate = `<div style="font-size: 8px; font-family: -apple-system, system-ui, sans-serif; color: #999; width: 100%; padding: 0 1.5in 0 1.24in; letter-spacing: 0.5px; text-transform: uppercase;">${title}</div>`;
|
|
53
|
-
const footerTemplate = `<div style="font-size: 8px; font-family: -apple-system, system-ui, sans-serif; color: #999; width: 100%; text-align: right; padding: 0 1.5in 0 1.24in;"><span class="pageNumber"></span> / <span class="totalPages"></span></div>`;
|
|
54
|
-
const pdfBuffer = await page.pdf({
|
|
55
|
-
format: opts.pageSize ?? "A4",
|
|
56
|
-
landscape: opts.landscape ?? false,
|
|
57
|
-
margin: { top: "0.75in", right: "1.5in", bottom: "0.75in", left: "0.6in" },
|
|
58
|
-
printBackground: true,
|
|
59
|
-
displayHeaderFooter: true,
|
|
60
|
-
headerTemplate,
|
|
61
|
-
footerTemplate
|
|
62
|
-
});
|
|
63
|
-
await writeFile(opts.outputPath, pdfBuffer);
|
|
64
|
-
} finally {
|
|
65
|
-
await browser.close();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
export {
|
|
69
|
-
findChrome,
|
|
70
|
-
generatePdf
|
|
71
|
-
};
|
package/dist/pdf-WLYWKSHR.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
// src/pdf.ts
|
|
2
|
-
import { existsSync } from "fs";
|
|
3
|
-
import { writeFile } from "fs/promises";
|
|
4
|
-
var CHROME_PATHS = {
|
|
5
|
-
darwin: [
|
|
6
|
-
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
|
7
|
-
"/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
|
|
8
|
-
"/Applications/Chromium.app/Contents/MacOS/Chromium"
|
|
9
|
-
],
|
|
10
|
-
linux: [
|
|
11
|
-
"/usr/bin/google-chrome",
|
|
12
|
-
"/usr/bin/google-chrome-stable",
|
|
13
|
-
"/usr/bin/chromium",
|
|
14
|
-
"/usr/bin/chromium-browser",
|
|
15
|
-
"/snap/bin/chromium"
|
|
16
|
-
],
|
|
17
|
-
win32: [
|
|
18
|
-
"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe",
|
|
19
|
-
"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
|
|
20
|
-
]
|
|
21
|
-
};
|
|
22
|
-
function findChrome() {
|
|
23
|
-
const envPath = process.env.CHROME_PATH;
|
|
24
|
-
if (envPath && existsSync(envPath)) return envPath;
|
|
25
|
-
const candidates = CHROME_PATHS[process.platform] ?? [];
|
|
26
|
-
for (const p of candidates) {
|
|
27
|
-
if (existsSync(p)) return p;
|
|
28
|
-
}
|
|
29
|
-
throw new Error(
|
|
30
|
-
"Chrome not found. Install Google Chrome or set CHROME_PATH environment variable."
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
function escapeHtml(s) {
|
|
34
|
-
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
35
|
-
}
|
|
36
|
-
async function generatePdf(opts) {
|
|
37
|
-
const chromePath = findChrome();
|
|
38
|
-
const puppeteer = await import("puppeteer-core");
|
|
39
|
-
const browser = await puppeteer.default.launch({
|
|
40
|
-
executablePath: chromePath,
|
|
41
|
-
headless: true,
|
|
42
|
-
args: ["--no-sandbox", "--disable-setuid-sandbox"]
|
|
43
|
-
});
|
|
44
|
-
try {
|
|
45
|
-
const page = await browser.newPage();
|
|
46
|
-
await page.setContent(opts.html, { waitUntil: "networkidle0" });
|
|
47
|
-
await page.waitForFunction("!!window.__ghostPaperChartsReady", {
|
|
48
|
-
timeout: 15e3
|
|
49
|
-
});
|
|
50
|
-
await new Promise((r) => setTimeout(r, 300));
|
|
51
|
-
const title = escapeHtml(opts.title ?? "");
|
|
52
|
-
const headerTemplate = `<div style="font-size: 8px; font-family: -apple-system, system-ui, sans-serif; color: #999; width: 100%; padding: 0 1in; letter-spacing: 0.5px; text-transform: uppercase;">${title}</div>`;
|
|
53
|
-
const footerTemplate = `<div style="font-size: 8px; font-family: -apple-system, system-ui, sans-serif; color: #999; width: 100%; text-align: right; padding: 0 1in;"><span class="pageNumber"></span> / <span class="totalPages"></span></div>`;
|
|
54
|
-
const pdfBuffer = await page.pdf({
|
|
55
|
-
format: opts.pageSize ?? "A4",
|
|
56
|
-
landscape: opts.landscape ?? false,
|
|
57
|
-
margin: { top: "0.75in", right: "1in", bottom: "0.75in", left: "1in" },
|
|
58
|
-
printBackground: true,
|
|
59
|
-
displayHeaderFooter: true,
|
|
60
|
-
headerTemplate,
|
|
61
|
-
footerTemplate
|
|
62
|
-
});
|
|
63
|
-
await writeFile(opts.outputPath, pdfBuffer);
|
|
64
|
-
} finally {
|
|
65
|
-
await browser.close();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
export {
|
|
69
|
-
findChrome,
|
|
70
|
-
generatePdf
|
|
71
|
-
};
|