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 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-pushpdf-or-print-components

v1.1.22

Published

React components to print or push generated PDFs from your app.

Downloads

6

Readme

React PushPrintComponents

License

PushPrintComponents is a versatile React component designed to enhance your web applications with printing and PDF generation capabilities. Utilizing the jsPDF library, it captures the current view of a component, enabling it to be printed directly from the browser or saved as a PDF. This makes it an ideal solution for generating reports, invoices, or any content that requires hard copies or digital preservation.

Features

  • Direct Printing: Enables direct printing of specific components within your web application, using a customizable trigger.
  • PDF Generation: Converts the current view of a component into a PDF file, facilitating easy saving, sharing, or further processing.
  • Customizable Triggers: This feature enables the creation of personalized triggers for starting the printing process, generating PDFs, and previewing documents. It also allows for the submission of additional fields along with the PDF.
  • Styling Support: Allows for the application of a custom class to the print container, offering styling flexibility..
  • PDF Handling Callback: Supports a callback function for post-PDF generation, allowing for additional handling like local saving or API integration.

New Features in PushPrintComponents

  • showPreviewTrigger: A React component or element used as a trigger for preview screen.
  • Preview Options: Offers a comprehensive suite of configurations for preview functionality, including customizable form fields for data submission, UI customization through class names, and specific action triggers (onSubmit, onCancel) for enhanced interaction.
  • Form Fields Customization: Enable dynamic creation of form fields within the preview modal, supporting various field types (text, number, email, etc.) with validation rules, allowing for a richer data collection process before PDF generation or printing.
  • Enhanced Triggers: Introduces distinct React components or elements as triggers for printing, PDF generation, and preview display, enriching user interaction and process initiation.
  • Detailed PDF Customization: Facilitates naming the generated PDF file, customizing the submit and cancel button texts in the preview modal, and providing hooks for submission and cancellation actions.

Installation

To install the component in your project, run the following command:

Run npm install react-pushpdf-or-print-components

Usage

The example below demonstrates how to integrate PushPrintComponents into your React application, showcasing setup for print, PDF generation triggers, preview options, and handling the generated PDF through callback functions.

import React from 'react';
import ReactDOM from 'react-dom';
import PushPrintComponents, { FormField, previewOptions } from 'react-pushpdf-or-print-components';

function App() {
  const previewOptions = {
    formFields: [
      { name: 'name', type: 'text', label: 'Name', validation: { required: true } },
      { name: 'date', type: 'date', label: 'Date' }
    ],
    title: 'Preview Title',
    description: 'Please fill out the form',
    pdfFileName: 'custom-file-name.pdf',
    submitButtonText: 'Submit',
    cancelButtonText: 'Cancel',
    onSubmit: (data) => {
      console.log('Form Data:', data);
    },
    onCancel: () => {
      console.log('Preview Cancelled');
    }
    width: '80%',
    left: '10%'
  };

  return (
    <PushPrintComponents
      printTrigger={<button>Print Content</button>}
      generatePdfTrigger={<button>Generate PDF</button>}
      showPreviewTrigger={<button>Show Preview</button>}
      previewOptions={previewOptions}
      className="custom-print-class"
      onPdf={(pdf) => {
        // Further actions with the generated PDF
      }}
      style={{ fontSize: '16px' }}
    >
      <div>
        Content to be printed or saved as PDF.
      </div>
    </PushPrintComponents>
  );
}

ReactDOM.render(<App />, document.getElementById('root'));

PushPrintComponents

React component called PushPrintComponents that provides functionality for printing content, generating PDFs, and displaying a preview form with customizable options.

|Name|Type|Description |--|-----|-----| |trigger|function|A React component or element used as a trigger for initiating the print process. |generatePdfTrigger|function|A React component or element used as a trigger for generating a PDF. |showPreviewTrigger|function|A React component or element used as a trigger for displaying the preview screen with provided form fields in previewOptions. |previewOptions|object|An object containing the configuration for the share preview form, including title, form fields, and action triggers. |className|string|An optional class name to apply to the print container for custom styling. |onPdf|function|A callback function that receives the generated PDF object for additional processing. |style|object|An optional object containing custom styles to apply to the print container. (fontSize will act as main font size for the print container)

previewOptions Configuration

The previewOptions configuration allows for detailed customization of the share preview form, including:

| Name | Type | Description | |-------------------|----------|-----------------------------------------------------------------------------| | title | string | Set the title of the share preview window. | | formFields | object | Define the fields in the form, their types, default values, and validation rules. | | description | string | Provide a description or instructions for the form. | | pdfFileName | string | Set the name of the generated PDF file. | | submitButtonText | string | Customize the text for the submit button in the preview form. | | cancelButtonText | string | Customize the text for the cancel button in the preview form. | | onSubmit | function | Define a custom function to handle the form submission. | | onCancel | function | Define a custom function to handle the form cancellation. |

Other minimal configurations on previewOptions

| Name | Type | Description | |-------------------|----------|-----------------------------------------------------------------------------| | width | string | Set the width of the share preview window along with % symbol. example: 80% | | left | string | Set the left position of the share preview window along with % symbol. example: 10% |

formFields Configuration

The formFields configuration allows for dynamic creation of form fields within the preview modal, supporting various field types (text, number, email, etc.) with validation rules, allowing for a richer data collection process before PDF generation or printing.

| Name | Type | Description | |---------------|----------|-----------------------------------------------------------------------------| | name | string | The name of the form field. | | type | string | The type of the form field (text, number, email, etc.). | | label | string | The label for the form field. | | validation| object | An object containing validation rules for the form field (e.g., required: true). | | defaultValue | string | The default value for the form field. | | rows | number | The number of rows for a textarea field. |

validation Configuration

The validation configuration allows for setting validation rules for form fields, including required fields, pattern matching, minimum and maximum lengths, and minimum and maximum values.

| Name | Type | Description | |-------------|---------|-----------------------------------------------------------------------------| | required | boolean | A boolean value indicating whether the field is required. | | pattern | string | A regular expression pattern for pattern matching. | | minLength| number | The minimum length for the field value. | | maxLength| number | The maximum length for the field value. | | min | number | The minimum value for number fields. | | max | number | The maximum value for number fields. |

Contributing

We welcome contributions from the community. Please refer to our contributing guidelines for more information.

License

This project is licensed under the terms of the MIT license.

Credits

This project was bootstrapped with [Create React App]

Support

For any questions or support, please contact us at [email protected]