Save react-pdf rendered file to state for sending it to server?

Issue

im using react-pdf library i managed to save file localy but now i would also need to save it on server since i am required to do a history display of all the files that were generated by a certain user.

                                    document={
                                        <DailyAssetPDF
                                            information={{ title, subtitle, locationName, today, selectedAssetName }}
                                            tableData={tableData}
                                            image1={{
                                                chart1, chart2, chart4 // donut chart
                                            }}
                                            image2={
                                                this.chartRef3.current.chartInstance.toBase64Image() || // chart bar
                                                ""
                                            }
                                            LN={LN}
                                            language={language}
                                        />
                                    }
                                    fileName={`${title}.pdf`}
                                >
                                    {({ loading }) =>
                                        loading ? (
                                            LN[language].loadingDocument
                                        ) : (
                                            <Button>{LN[language].report_export_btn}</Button>
                                        )
                                    }
                                </PDFDownloadLink> ```

Solution

the best solution for me was:

  1. send the data that we want on the pdf file from to backend [json FORMAT]

  2. create the same pdf in the backend and save it there [using multer ..] OR on DB

for more inspiration visit : https://github.com/exportsdk/sample-react-pdf-api

Answered By – Reda El Ouahabi

Answer Checked By – Candace Johnson (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.