Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@react-pdf/renderer

Package Overview
Dependencies
Maintainers
1
Versions
144
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-pdf/renderer

Create PDF files on the browser and server

  • 3.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
490K
decreased by-14.98%
Maintainers
1
Weekly downloads
 
Created

What is @react-pdf/renderer?

@react-pdf/renderer is a library that allows you to create PDF documents using React components. It provides a way to build complex PDF documents with a declarative syntax, leveraging the power of React's component-based architecture.

What are @react-pdf/renderer's main functionalities?

Creating a Simple PDF Document

This code demonstrates how to create a simple PDF document with two sections using @react-pdf/renderer. The PDFViewer component is used to render the PDF in the browser.

const { PDFViewer, Document, Page, Text, View, StyleSheet } = require('@react-pdf/renderer');

const styles = StyleSheet.create({
  page: { flexDirection: 'row', backgroundColor: '#E4E4E4' },
  section: { margin: 10, padding: 10, flexGrow: 1 }
});

const MyDocument = () => (
  <Document>
    <Page size="A4" style={styles.page}>
      <View style={styles.section}>
        <Text>Section #1</Text>
      </View>
      <View style={styles.section}>
        <Text>Section #2</Text>
      </View>
    </Page>
  </Document>
);

const App = () => (
  <PDFViewer>
    <MyDocument />
  </PDFViewer>
);

Styling PDF Components

This example shows how to apply styles to PDF components using the StyleSheet object. The styles are similar to CSS and can be applied to various elements within the PDF document.

const { Document, Page, Text, View, StyleSheet } = require('@react-pdf/renderer');

const styles = StyleSheet.create({
  page: { flexDirection: 'row', backgroundColor: '#E4E4E4' },
  section: { margin: 10, padding: 10, flexGrow: 1, backgroundColor: '#ffffff', border: '1px solid #000' },
  text: { fontSize: 12, color: '#000' }
});

const MyStyledDocument = () => (
  <Document>
    <Page size="A4" style={styles.page}>
      <View style={styles.section}>
        <Text style={styles.text}>Styled Section #1</Text>
      </View>
      <View style={styles.section}>
        <Text style={styles.text}>Styled Section #2</Text>
      </View>
    </Page>
  </Document>
);

Embedding Images in PDF

This code demonstrates how to embed an image in a PDF document using the Image component. The image source can be a URL or a local file path.

const { Document, Page, Image, StyleSheet } = require('@react-pdf/renderer');

const styles = StyleSheet.create({
  page: { flexDirection: 'row', backgroundColor: '#E4E4E4' },
  image: { margin: 10, width: 200, height: 200 }
});

const MyImageDocument = () => (
  <Document>
    <Page size="A4" style={styles.page}>
      <Image style={styles.image} src="https://example.com/image.png" />
    </Page>
  </Document>
);

Other packages similar to @react-pdf/renderer

FAQs

Package last updated on 19 Jan 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc