Skip to content

Latest commit

 

History

History
123 lines (86 loc) · 2.54 KB

File metadata and controls

123 lines (86 loc) · 2.54 KB

import EditButton from '../src/components/Docs/EditButton' import NavigationButtons from '../src/components/Docs/NavigationButtons'

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 name Description Default
document Document's root element to be rendered undefined
path File system path where the document will be created undefined
callback Function to be called after rendering is finished undefined

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 name Description Default
document Document's root element to be rendered undefined

Returns

String representation of PDF document

renderToBuffer

Helper function to render a PDF into a Node Buffer.

Usage

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

const buffer = await renderToBuffer(<MyDocument />);

Arguments

Prop name Description Default
document Document's root element to be rendered undefined

Returns

Buffer 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 name Description Default
document Document's root element to be rendered undefined

Returns

PDF document Stream