npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

printmint

v1.0.18

Published

(updating styles issues phase) you can use this using inline css styles now package is updating for copying styles automatically wait until its done or work with inline css styles # React Element Printer

Downloads

91

Readme

(updating styles issues phase) you can use this using inline css styles now package is updating for copying styles automatically wait until its done or work with inline css styles

React Element Printer

A React component to easily print any part of the page, automatically copying styles and external resources for a seamless print experience. No need to manually pass styles — it handles everything for you!

Installation

Install the package via npm:

npm install printmint

Or using yarn:

yarn add printmint

Usage

The ReactElementPrinter component allows you to print content with just a few simple steps. You can customize the print behavior, including the title, styles, and before/after print callbacks.

Basic Example

import React, { useRef } from 'react';
import ReactElementPrinter from 'printmint';

const MyComponent = () => {
  const printerRef = useRef();

  return (
    <div>
      <h1>My Page</h1>
      <p>This is some content to be printed.</p>

      <ReactElementPrinter ref={printerRef}>
        <div>
          <h2>This will be printed</h2>
          <p>Along with its styles</p>
        </div>
      </ReactElementPrinter>

      <button onClick={() => printerRef.current.print()}>Print</button>
    </div>
  );
};

export default MyComponent;

Print Multiple Sections Example

In this example, you can print multiple sections of the page, each with different content.

import React, { useRef } from 'react';
import ReactElementPrinter from 'printmint';

const MultiSectionPrint = () => {
  const sectionRef1 = useRef();
  const sectionRef2 = useRef();

  return (
    <div>
      <h1>Multi Section Print</h1>
      <p>This section is visible, but only part of it will be printed.</p>

      <ReactElementPrinter ref={sectionRef1}>
        <div>
          <h2>Section 1</h2>
          <p>This is content from Section 1 that will be printed.</p>
        </div>
      </ReactElementPrinter>

      <ReactElementPrinter ref={sectionRef2}>
        <div>
          <h2>Section 2</h2>
          <p>This is content from Section 2 that will also be printed.</p>
        </div>
      </ReactElementPrinter>

      <button onClick={() => sectionRef1.current.print()}>Print Section 1</button>
      <button onClick={() => sectionRef2.current.print()}>Print Section 2</button>
    </div>
  );
};

export default MultiSectionPrint;

Full Customization Example

This example shows how you can use the documentTitle and onBeforePrint/onAfterPrint callbacks to fully customize the print process.

import React, { useRef } from 'react';
import ReactElementPrinter from 'printmint';

const CustomPrintExample = () => {
  const printerRef = useRef();

  const handleBeforePrint = () => {
    console.log('Before print');
  };

  const handleAfterPrint = () => {
    console.log('After print');
  };

  return (
    <div>
      <h1>Custom Print Example</h1>
      <ReactElementPrinter
        ref={printerRef}
        documentTitle="Custom Printed Document"
        onBeforePrint={handleBeforePrint}
        onAfterPrint={handleAfterPrint}
      >
        <div>
          <h2>This will be printed with custom title and callbacks</h2>
          <p>This content is printed with customized before and after actions.</p>
        </div>
      </ReactElementPrinter>

      <button onClick={() => printerRef.current.print()}>Print</button>
    </div>
  );
};

export default CustomPrintExample;

Props

| Prop | Type | Default | Description | |-------------------|-------------------------|-----------|-----------------------------------------------------------------------------| | documentTitle | string | 'Print' | Title of the printed document. | | onBeforePrint | function | null | Callback function to be executed before printing. | | onAfterPrint | function | null | Callback function to be executed after printing. |

Ref API

You can use the print method via the ref to trigger the print action.

const printerRef = useRef();

const handlePrint = () => {
  printerRef.current.print();
};

Features

  • Automatic Style Copying: The printed content will inherit the styles from the main page without needing to manually pass them.
  • External Stylesheets Support: External stylesheets (e.g., Google Fonts) are also copied into the print window.
  • Customizable Callbacks: Execute functions before and after printing to customize the print flow.
  • Seamless Integration: Easily integrate it into any part of your React app without modifying the structure.

How It Works

  1. The ReactElementPrinter component renders the content you want to print.
  2. When you trigger the print action, it copies the content and all relevant styles from your page (including external CSS and linked styles).
  3. It creates a new print window, sets up the content, and prints it.

License

ISC License.