Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/luxonauta/printelements
🖨️ A JavaScript library to easily print content from web pages.
https://github.com/luxonauta/printelements
html pdf print
Last synced: 20 days ago
JSON representation
🖨️ A JavaScript library to easily print content from web pages.
- Host: GitHub
- URL: https://github.com/luxonauta/printelements
- Owner: luxonauta
- License: mit
- Created: 2020-06-16T20:20:14.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-04-15T02:05:08.000Z (7 months ago)
- Last Synced: 2024-05-02T05:01:12.444Z (7 months ago)
- Topics: html, pdf, print
- Language: JavaScript
- Homepage:
- Size: 114 KB
- Stars: 21
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: license.md
Awesome Lists containing this project
README
# printElements
> A JavaScript library to easily print content from web pages.
## Motivation
Creating a print-ready PDF from web content can be tricky and time-consuming. This library simplifies the process, allowing you to print only the content you need with minimal fuss.
## Features
- Select specific HTML tags within a specified container for printing;
- Exclude elements with a designated class from the print output;
- Handles dynamic DOM environments by ensuring the print operation is only executed when the DOM is fully accessible;
- Provides flexibility with configurable delay options to manage different rendering times.## Quick Start
### Via CDN
```html
```
Or download it directly from the [GitHub repository](https://github.com/luxonauta/printElements/tree/main/dist).
## Usage
Wrap the content to be printed within a `` tag. Then call `printElements(options)` with your specified options:
```html
Your Content Here
document.addEventListener("DOMContentLoaded", () => {
const printOptions = {
targets: ["index.html"],
tags: ["h1", "p", "li"],
willNotPrint: "exclude",
wrapper: "main",
delay: 150 // Optional delay in milliseconds before printing
};document.getElementById("printBtn").onclick = () =>
printElements(printOptions);
});
```
- `wrapper`: Specify the container element whose contents you want to print (default is `"main"`);
- `willNotPrint`: Apply the class `"exclude"` to any HTML element within the wrapper to prevent it from being printed;
- `delay`: Customize the delay in milliseconds before the print command is executed, to ensure all content is rendered properly.### License
Released under the [MIT License](/license.md). You are free to use and modify it for your projects.