How to create a pdf file using react-pdf and your own component without using react-pdf components?

285 views Asked by At

I have my own component that uses andt I want to select some object in a table and pass it to my component and download it as a pdf.

I tried wrapping my component but nothing happened just my text was gone

const DocumentForPrint = ({ children }) => {
  return (
    <Document>
    <Page size="A4">
        { children }
    </Page>
  </Document>
  )
}
1

There are 1 answers

0
Guillaume On

I'm not sure you can wrap you own React component with the react-pdf library. You have to use to given components like or . Depending on your {{ children }} content you have 2 solutions :

  • Change the way you send props to your DocumentForPrint function and work with existing components like View, Text, Image etc.
  • There is a react-pdf-html package which add an component for this PDF generation. This will allow you to use html/css. You should be able to wrap any content using this one