-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpdfMaker.js
More file actions
49 lines (42 loc) · 1.32 KB
/
Copy pathpdfMaker.js
File metadata and controls
49 lines (42 loc) · 1.32 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
const puppeteer = require("puppeteer");
(async () => {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
try {
console.log('Going to the Hacker News page');
await page.goto("https://news.ycombinator.com", {
waitUntil: "networkidle2",
timeout: 60000, // Increase the timeout to 60 seconds
});
// Add a header with the title "Created by Kalma Labs"
await page.evaluate(() => {
const header = document.createElement("div");
header.textContent = "Created by Kalma Labs";
header.style.position = "fixed";
header.style.top = "0";
header.style.width = "100%";
header.style.textAlign = "center";
header.style.fontSize = "16px";
header.style.fontWeight = "bold";
header.style.backgroundColor = "white";
header.style.padding = "10px";
header.style.zIndex = "1000";
document.body.insertBefore(header, document.body.firstChild);
});
await page.pdf({
path: "pdfMaker.pdf",
format: "a3",
margin: {
top: "50px",
right: "10mm",
bottom: "10mm",
left: "10mm",
},
});
console.log('PDF generated successfully');
} catch (error) {
console.error("failed to generate pdf:", error);
} finally {
await browser.close();
}
})();