Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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




Print


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.