Socket
Socket
Sign inDemoInstall

react-pushpdf-or-print-components

Package Overview
Dependencies
182
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-pushpdf-or-print-components

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


Version published
Weekly downloads
34
increased by209.09%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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.

NameTypeDescription
triggerfunctionA React component or element used as a trigger for initiating the print process.
generatePdfTriggerfunctionA React component or element used as a trigger for generating a PDF.
showPreviewTriggerfunctionA React component or element used as a trigger for displaying the preview screen with provided form fields in previewOptions.
previewOptionsobjectAn object containing the configuration for the share preview form, including title, form fields, and action triggers.
classNamestringAn optional class name to apply to the print container for custom styling.
onPdffunctionA callback function that receives the generated PDF object for additional processing.
styleobjectAn 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:

NameTypeDescription
titlestringSet the title of the share preview window.
formFieldsobjectDefine the fields in the form, their types, default values, and validation rules.
descriptionstringProvide a description or instructions for the form.
pdfFileNamestringSet the name of the generated PDF file.
submitButtonTextstringCustomize the text for the submit button in the preview form.
cancelButtonTextstringCustomize the text for the cancel button in the preview form.
onSubmitfunctionDefine a custom function to handle the form submission.
onCancelfunctionDefine a custom function to handle the form cancellation.

Other minimal configurations on previewOptions

NameTypeDescription
widthstringSet the width of the share preview window along with % symbol. example: 80%
leftstringSet 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.

NameTypeDescription
namestringThe name of the form field.
typestringThe type of the form field (text, number, email, etc.).
labelstringThe label for the form field.
validationobjectAn object containing validation rules for the form field (e.g., required: true).
defaultValuestringThe default value for the form field.
rowsnumberThe 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.

NameTypeDescription
requiredbooleanA boolean value indicating whether the field is required.
patternstringA regular expression pattern for pattern matching.
minLengthnumberThe minimum length for the field value.
maxLengthnumberThe maximum length for the field value.
minnumberThe minimum value for number fields.
maxnumberThe 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 kishorechandra.developer@gmail.com

Keywords

FAQs

Last updated on 29 Feb 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc