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

@react-pdf/render

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-pdf/render

  • 2.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
616K
decreased by-2.38%
Maintainers
1
Weekly downloads
 
Created

What is @react-pdf/render?

@react-pdf/render is a library for creating PDF documents using React components. It allows developers to use React's declarative syntax to design and generate PDF files programmatically.

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

Basic PDF Document Creation

This code demonstrates how to create a basic PDF document with two sections using @react-pdf/render. It uses React components to define the structure and style of the PDF.

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

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>
);

module.exports = MyDocument;

Styling PDF Components

This code sample shows how to apply styles to PDF components using the StyleSheet object from @react-pdf/render. It demonstrates setting background colors, borders, and text styles.

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

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>
);

module.exports = MyStyledDocument;

Embedding Images

This example demonstrates how to embed images in a PDF document using @react-pdf/render. The Image component is used to include an image from a URL.

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

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

const MyDocumentWithImage = () => (
  <Document>
    <Page size="A4" style={styles.page}>
      <View style={styles.section}>
        <Text>Section with Image</Text>
        <Image style={styles.image} src="https://example.com/image.png" />
      </View>
    </Page>
  </Document>
);

module.exports = MyDocumentWithImage;

Other packages similar to @react-pdf/render

FAQs

Package last updated on 09 Apr 2021

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