0

I have a reports app that runs ReactJS on the client-side and NodeJS on the server-side. The app displays a report and contains content like Tables, Graphs, SVGs and more.

I want to export this report to PDF with a proper layout with the click of a button.

What is the best way to achieve this functionality? Please suggest both vectorized and non-vectorized solutions to this problem.

The image below is my React App and I want to export the red-bordered box to a nicely structured PDF file.

This is how my React App looks like. I want to export the red bordered box that contains the actual report to a PDF file

1 Answers1

0

You can create a PDF using puppeteer in this package you can access the browser’s print window pragmatically. Using that print window you can export the pdf.

This is the way that you can do it.

const page = await browser.newPage();

await page.emulateMediaType('print');

pdf = await page.pdf({printBackground: true,width: `21cm`,height: `${height}px`,pageRanges: '1',});

Thanks.

Radika Dilanka
  • 474
  • 4
  • 13