React-pdf

Node API

renderToFile

Helper function to render a PDF into a file.

Usage

const MyDocument = () => (
  <Document>
    <Page>
      <Text>React-pdf</Text>
    </Page>
  </Document>
);

await renderToFile(<MyDocument />, `${__dirname}/my-doc.pdf`);

Arguments

Prop nameDescriptionDefault
documentDocument's root element to be renderedundefined
pathFile system path where the document will be createdundefined
callbackFunction to be called after rendering is finishedundefined

renderToString

Helper function to render a PDF into a string.

Usage

const MyDocument = () => (
  <Document>
    <Page>
      <Text>React-pdf</Text>
    </Page>
  </Document>
);

const value = await renderToString(<MyDocument />);

Arguments

Prop nameDescriptionDefault
documentDocument's root element to be renderedundefined

Returns

String representation of PDF document

renderToStream

Helper function to render a PDF into a Node Stream.

Usage

const MyDocument = () => (
  <Document>
    <Page>
      <Text>React-pdf</Text>
    </Page>
  </Document>
);

const stream = await renderToStream(<MyDocument />);

Arguments

Prop nameDescriptionDefault
documentDocument's root element to be renderedundefined

Returns

PDF document Stream