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 🙏

© 2026 – Pkg Stats / Ryan Hefner

chunka4

v1.0.0

Published

React component library for dynamic A4 page breaking and printing

Readme

ChunkA4

A React library for dynamically splitting HTML content into A4-sized pages for printing.

Features

  • Real-time pagination of dynamic HTML content
  • A4 page sizing with customizable margins
  • Print-optimized layout with proper page breaks
  • Optional print button with customizable styling
  • Minimal dependencies and lightweight footprint

Installation

npm install chunka4
# or
yarn add chunka4

Basic Usage

import React from 'react';
import { A4PageBreaker } from 'chunka4';

const MyComponent = () => {
  const htmlContent = `
    <h1>My Document</h1>
    <p>This content will be dynamically split into A4-sized pages.</p>
    <ul>
      <li>Item 1</li>
      <li>Item 2</li>
      <li>Item 3</li>
    </ul>
    <p>More content...</p>
  `;

  return (
    <div>
      <h2>Document Preview</h2>
      <A4PageBreaker content={htmlContent} />
    </div>
  );
};

export default MyComponent;

Components

A4PageBreaker

The main component that splits HTML content into A4-sized pages.

Props

| Prop | Type | Default | Description | |-------------------|------------------------|------------|--------------------------------------------------| | content | string | (required) | HTML content to be paginated | | pageStyle | React.CSSProperties | {} | Custom styling for the page containers | | showMargins | boolean | true | Whether to show standard A4 margins (20mm) | | onPagesGenerated | (count: number) => void | undefined | Callback when pages are generated | | showPrintButton | boolean | true | Whether to show the built-in print button | | printButtonText | string | "Print" | Text for the print button | | printButtonStyle | React.CSSProperties | undefined | Custom styling for the print button |

PrintButton

A standalone print button component that can be used independently.

Props

| Prop | Type | Default | Description | |----------------|------------------------|-----------|--------------------------------------------| | text | string | "Print" | Button text | | style | React.CSSProperties | {} | Custom styling for the button | | className | string | undefined | Additional CSS class name | | onBeforePrint | () => void | undefined | Callback before print dialog opens | | onAfterPrint | () => void | undefined | Callback after print dialog is initiated |

Examples

With Custom Styling

import React from 'react';
import { A4PageBreaker } from 'chunka4';

const StyledDocument = () => {
  const htmlContent = `
    <h1 style="color: #2196F3;">Styled Document</h1>
    <p>This content has custom styling.</p>
  `;

  return (
    <A4PageBreaker 
      content={htmlContent}
      pageStyle={{ 
        border: '2px solid #2196F3',
        borderRadius: '8px' 
      }}
      printButtonText="Print Document"
      printButtonStyle={{ 
        backgroundColor: '#2196F3',
        borderRadius: '8px'
      }}
    />
  );
};

Using Separate Print Button

import React from 'react';
import { A4PageBreaker, PrintButton } from 'chunka4';

const DocumentWithCustomPrint = () => {
  const htmlContent = `<h1>My Document</h1><p>Content...</p>`;
  
  return (
    <div>
      <A4PageBreaker 
        content={htmlContent}
        showPrintButton={false} 
      />
      
      <div className="button-container">
        <PrintButton 
          text="Print Document" 
          style={{ backgroundColor: '#4CAF50' }}
          onBeforePrint={() => console.log('Print started')}
        />
        <button onClick={() => window.close()}>Close</button>
      </div>
    </div>
  );
};

Page Counting

import React, { useState } from 'react';
import { A4PageBreaker } from 'chunka4';

const DocumentWithPageCount = () => {
  const [pageCount, setPageCount] = useState(0);
  const htmlContent = `<h1>My Document</h1><p>Content...</p>`;
  
  return (
    <div>
      <p>Total pages: {pageCount}</p>
      
      <A4PageBreaker 
        content={htmlContent}
        onPagesGenerated={setPageCount}
      />
    </div>
  );
};

License

MIT