Generating a PDF file from React Components

后端 未结 8 1970
無奈伤痛
無奈伤痛 2020-12-02 10:45

I have been building a polling application. People are able to create their polls and get data regarding the question(s) they ask. I would like to add the functionality to l

8条回答
  •  眼角桃花
    2020-12-02 11:15

    React-PDF is a great resource for this.

    It is a bit time consuming converting your markup and CSS to React-PDF's format, but it is easy to understand. Exporting a PDF and from it is fairly straightforward.

    To allow a user to download a PDF generated by react-PDF, use their on the fly rendering, which provides a customizable download link. When clicked, the site renders and downloads the PDF for the user.

    Here's their REPL which will familiarize you with the markup and styling required. They have a download link for the PDF too, but they don't show the code for that here.

提交回复
热议问题