New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

printeer

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

printeer - npm Package Compare versions

Comparing version 1.2.1 to 1.2.2

src/options.js

98

bin/index.js

@@ -1,41 +0,65 @@

import $l7i9T$puppeteer from "puppeteer";
import {normalize as $l7i9T$normalize} from "path";
// src/printeer.js
import puppeteer from "puppeteer";
import { normalize } from "path";
var printeer_default = (url, outputFile, outputType = null) => {
return new Promise(async (resolve, reject) => {
outputFile = normalize(outputFile);
if (!url.startsWith("http")) {
reject("URL must start with http or https");
}
const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
const res = await page.goto(url, { waitUntil: "networkidle0" });
if (!res) {
return reject(new Error("Could not load the page."));
}
outputType = detectOutputType(outputFile, outputType);
if (res.status() !== 200) {
reject(`Error: ${res.status()}: ${res.statusText()}`);
} else {
if (outputType === "png") {
await page.screenshot({ path: outputFile });
} else {
await page.pdf({ format: "A4", path: outputFile });
}
resolve(outputFile);
}
return await browser.close();
});
};
function detectOutputType(fname, outputType) {
const validOutputTypes = ["pdf", "png"];
if (!outputType) {
const ext = fname.split(".").pop();
if (validOutputTypes.includes(ext)) {
return ext;
}
return "pdf";
}
if (!validOutputTypes.includes(outputType)) {
return "pdf";
}
return outputType;
}
var // networkidle0 - consider navigation to be finished when there are no more than 0 network connections for at least 500 ms
// networkidle2 - consider navigation to be finished when there are no more than 2 network connections for at least 500 ms.
/**
* Generate the report.
* @param {string} reportName The name of the report.
* @returns The promise of the report file.
*/ $173d6c6c8da44cf1$export$2e2bcd8739ae039 = (url, outputFile, outputType = "pdf")=>{
return new Promise(async (resolve, reject)=>{
outputFile = (0, $l7i9T$normalize)(outputFile);
if (!url.startsWith("http")) throw new Error("URL must start with http or https");
const browser = await (0, $l7i9T$puppeteer).launch({
headless: true
});
const page = await browser.newPage();
const res = await page.goto(url, {
waitUntil: "networkidle0"
});
if (!res) return reject(new Error("Could not load the page."));
if (res.status() !== 200) reject(`Error: ${res.status()}: ${res.statusText()}`);
else {
await page.pdf({
format: "A4",
path: outputFile
});
resolve(outputFile);
}
return await browser.close();
});
// src/usage.js
var usage_default = () => {
console.log("Usage: printeer <url> <outputFile>");
};
const $cf838c15c8b009ba$export$4f653a8d4fdb37ed = (0, $173d6c6c8da44cf1$export$2e2bcd8739ae039);
export {$cf838c15c8b009ba$export$4f653a8d4fdb37ed as printeer};
// src/cli.js
(async function main() {
const url = process.argv[2];
const outputFile = process.argv[3];
if (!url || !outputFile) {
usage_default();
process.exit(1);
}
try {
await printeer_default(url, outputFile);
} catch (e) {
console.error("Error:", e);
process.exit(1);
}
})();
//# sourceMappingURL=index.js.map

@@ -1,41 +0,50 @@

import $l7i9T$puppeteer from "puppeteer";
import {normalize as $l7i9T$normalize} from "path";
// src/printeer.js
import puppeteer from "puppeteer";
import { normalize } from "path";
var printeer_default = (url, outputFile, outputType = null) => {
return new Promise(async (resolve, reject) => {
outputFile = normalize(outputFile);
if (!url.startsWith("http")) {
reject("URL must start with http or https");
}
const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
const res = await page.goto(url, { waitUntil: "networkidle0" });
if (!res) {
return reject(new Error("Could not load the page."));
}
outputType = detectOutputType(outputFile, outputType);
if (res.status() !== 200) {
reject(`Error: ${res.status()}: ${res.statusText()}`);
} else {
if (outputType === "png") {
await page.screenshot({ path: outputFile });
} else {
await page.pdf({ format: "A4", path: outputFile });
}
resolve(outputFile);
}
return await browser.close();
});
};
function detectOutputType(fname, outputType) {
const validOutputTypes = ["pdf", "png"];
if (!outputType) {
const ext = fname.split(".").pop();
if (validOutputTypes.includes(ext)) {
return ext;
}
return "pdf";
}
if (!validOutputTypes.includes(outputType)) {
return "pdf";
}
return outputType;
}
var // networkidle0 - consider navigation to be finished when there are no more than 0 network connections for at least 500 ms
// networkidle2 - consider navigation to be finished when there are no more than 2 network connections for at least 500 ms.
/**
* Generate the report.
* @param {string} reportName The name of the report.
* @returns The promise of the report file.
*/ $173d6c6c8da44cf1$export$2e2bcd8739ae039 = (url, outputFile, outputType = "pdf")=>{
return new Promise(async (resolve, reject)=>{
outputFile = (0, $l7i9T$normalize)(outputFile);
if (!url.startsWith("http")) throw new Error("URL must start with http or https");
const browser = await (0, $l7i9T$puppeteer).launch({
headless: true
});
const page = await browser.newPage();
const res = await page.goto(url, {
waitUntil: "networkidle0"
});
if (!res) return reject(new Error("Could not load the page."));
if (res.status() !== 200) reject(`Error: ${res.status()}: ${res.statusText()}`);
else {
await page.pdf({
format: "A4",
path: outputFile
});
resolve(outputFile);
}
return await browser.close();
});
// src/index.js
var printeer = printeer_default;
export {
printeer
};
const $cf838c15c8b009ba$export$4f653a8d4fdb37ed = (0, $173d6c6c8da44cf1$export$2e2bcd8739ae039);
export {$cf838c15c8b009ba$export$4f653a8d4fdb37ed as printeer};
//# sourceMappingURL=index.js.map
{
"name": "printeer",
"version": "1.2.1",
"version": "1.2.2",
"description": "Prints specified web url to PDF (or Image - Coming Soon)!",

@@ -16,3 +16,6 @@ "main": "index.js",

"build-cli": "parcel build ./src/cli.js & mv index.* ./bin",
"parcel": "parcel"
"parcel": "parcel",
"esbuild": "esbuild",
"esbuild-cli": "npm run esbuild -- ./src/cli.js --outfile=./bin/index.js --bundle --platform=node --packages=external --target=node16.8 --format=esm --sourcemap",
"esbuild-lib": "npm run esbuild -- ./src/index.js --outfile=./index.js --bundle --platform=node --packages=external --target=node16.8 --format=esm --sourcemap"
},

@@ -26,2 +29,3 @@ "dependencies": {

"constants-browserify": "^1.0.0",
"esbuild": "^0.16.13",
"events": "^3.3.0",

@@ -28,0 +32,0 @@ "https-browserify": "^1.0.0",

# Printeer
Printeer is a little utility that converts any webpage to PDF. It employs Puppeteer, which makes it simple to print the website to PDF. It may be used as a command-line utility or a library. It does not yet support any print options yet. They  will, however, be added in the future.
Printeer is a little utility that converts any webpage to PDF. It employs Puppeteer, which makes it simple to print the website to PDF. It may be used as a command-line utility or a library. It does not yet support any print options yet. They will, however, be added in the future.
It automatically detects the output format from the file extension. If the extension is `.pdf`, it will print to PDF. If the extension is `.png`, it will print to PNG. If the extension is anything else, it will print to PDF.
## Installation

@@ -15,3 +17,3 @@

```bash
printeer <url> <output.pdf>
printeer <url> <output.pdf|png>
```

@@ -23,3 +25,7 @@

- [x] Use it as library through `printeer` function
- [ ] Support web to png printing
- [ ] Accept page size option
- [x] Support web to png printing
- [ ] Accept page size and other print options
- [ ] Run printeer as a service (with a web interface) with CDP (Chrome DevTools Protocol) to print webpages to PDF and PNG
##
> **Note:** Master branch is not stable. Use the latest release instead.

@@ -20,4 +20,9 @@ import printeer from "./printeer.js";

await printeer(url, outputFile);
// Wait for the printeer to finish.
try {
await printeer(url, outputFile);
} catch (e) {
console.error("Error:", e);
process.exit(1);
}
})();

@@ -13,3 +13,3 @@ import puppeteer from 'puppeteer';

*/
export default (url, outputFile, outputType='pdf') => {
export default (url, outputFile, outputType=null) => {

@@ -20,3 +20,3 @@ return new Promise(async (resolve, reject) => {

if (!url.startsWith('http')) {
throw new Error('URL must start with http or https');
reject('URL must start with http or https');
}

@@ -32,6 +32,13 @@

// Detect outputType
outputType = detectOutputType(outputFile, outputType);
if (res.status() !== 200) {
reject(`Error: ${res.status()}: ${res.statusText()}`);
} else {
await page.pdf({ format: 'A4', path: outputFile });
if (outputType === 'png') {
await page.screenshot({ path: outputFile });
} else {
await page.pdf({ format: 'A4', path: outputFile });
}
resolve(outputFile);

@@ -41,3 +48,15 @@ }

})
}
}
function detectOutputType(fname, outputType) {
const validOutputTypes = ["pdf", "png"]
if (!outputType) {
const ext = fname.split('.').pop()
if (validOutputTypes.includes(ext)) { return ext }
return 'pdf'
}
if (!validOutputTypes.includes(outputType)) { return 'pdf' }
return outputType
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc