PejmanNik / jikji

Effortless report generator and reporting tools with React and NodeJS
https://jikji.pejmannik.dev/
MIT License
50 stars 1 forks source link

How to generate PDF using only React #6

Closed PandukaNandara closed 1 year ago

PandukaNandara commented 1 year ago

I want to generate PDF using this library. Is it possible to generate without server?

PejmanNik commented 1 year ago

Yes, you can add the lib to a react project, but it will not generate a PDF file, clinets depend on the browser's capability to generate the output. so the user needs to choose save it as PDF in the browser

https://jikji.xyz/docs/csr-vs-ssg

Zhaoyikaiii commented 1 year ago

I am trying to use useReactToPrint to print the ReportView, it will trigger browser's print dialog. And the styles between them are different. I want to know is there a function I could make them are the same.

PejmanNik commented 1 year ago

You don't need the useReactToPrint, just call window.print() after the page load is completed.

unfortunately, I don't think the library has any mechanism to notify you when the page load is completed. I'll work on it for the next version but for now, you can use polling:

function isReady() {

  const poll = resolve => {
    if(window.__jikji_isReady === true) resolve();
    else setTimeout(_ => poll(resolve), 200);
  }

  return new Promise(poll);
}

and

isReady().then(x=> window.print())
PejmanNik commented 1 year ago

I'll close the issue. please feel free to reopen if you still have a problem with it