Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iomerkoyuncu/website-to-file
Node.js library to capture image/pdf from url.
https://github.com/iomerkoyuncu/website-to-file
puppeteer url-to-image url-to-pdf
Last synced: 16 days ago
JSON representation
Node.js library to capture image/pdf from url.
- Host: GitHub
- URL: https://github.com/iomerkoyuncu/website-to-file
- Owner: iomerkoyuncu
- License: mit
- Created: 2024-10-26T15:09:23.000Z (20 days ago)
- Default Branch: master
- Last Pushed: 2024-10-30T06:44:27.000Z (17 days ago)
- Last Synced: 2024-10-30T07:21:25.826Z (17 days ago)
- Topics: puppeteer, url-to-image, url-to-pdf
- Language: JavaScript
- Homepage:
- Size: 629 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# website-to-file
`website-to-file` is a Node.js library for capturing screenshots and generating PDFs from web pages using Puppeteer. It provides a simple interface to take images and PDF snapshots while allowing customization of various options.
## Installation
You can install `website-to-file` via npm:
```bash
npm install website-to-file
```## Usage
```javascript
const capture = require('website-to-file');
```### Functions
```javascript
capture.image(url, options);
capture.asFile.image(url, path, options);
capture.pdf(url, path, options);
```### Options
```javascript
const options = {
launchOptions: {
defaultViewport: {
width: 1920,
height: 1080,
},
},
gotoOptions: {
waitUntil: 'networkidle0',
},
evaluate: () => {
const className = document.querySelector('.className');
if (className) {
className.style.display = 'none';
}
},
waitForSelector: '.className',
waitForTimeout: 1000,
imageOptions: {
encoding: 'base64',
fullPage: true,
},
};
```### Capturing Images
```javascript
// As Base64 (can be changed in options)
const screenshot = await capture.image('https://ismetomerkoyuncu.tech');// As a file
await capture.asFile.image('https://ismetomerkoyuncu.tech', 'example.png');
```### Capturing PDFs
```javascript
await capture.pdf('https://ismetomerkoyuncu.tech', 'output.pdf');
```### Evaluating JavaScript
```javascript
// Hiding an element with a specific class
capture.pdf(
'https://medium.com/@ismetkync/closure-nedir-4b1eb7177598',
`${Date.now()}.pdf`,
{
evaluate: () => {
const className = document.querySelector('.bx');
if (className) {
className.style.display = 'none';
}
},
},
);
```