diegomura / react-pdf

📄 Create PDF files using React
https://react-pdf.org
MIT License
14.94k stars 1.18k forks source link

Generate PDF/A compliant documents #1520

Open Skywalker13 opened 3 years ago

Skywalker13 commented 3 years ago

Hello

react-pdf is great, nevertheless it's not possible to generate PDF/A compliant documents.

I found this thread where someone has a way to generate (easily) PDF/A document with pdfkit:

Maybe it should be possible to generate this sort of document directly with react-pdf.. or maybe react-pdf should provide hooks (advanced) in order to create and play with the pdfkit context ?!

Regards

youbek commented 3 years ago

Any updates on this?

oybekalimat commented 3 years ago

Thanks for the great tool. As PDF/A is requested for the current project I'm involved in, I hope this is reachable. Please, any updates?

youbek commented 3 years ago

As a workaround, I used https://github.com/crabbly/Print.js this library to call the browser's native print of my react-pdf generated PDF document. And I was able to successfully generate PDF/A complaint document.

diegomura commented 2 years ago

I'd love to know more about this standard. How can I check if a document is PDF/A compliant? Should all PDFs be rendered with this spec or should we add a prop to control it? If so, how that prop would look like?

gius commented 6 months ago

Basically, you need to:

  1. Include XMP metadata
  2. Embed color space file
  3. Embed all fonts

The latest version of Pdfkit should support all of this. However, it is not easy to update the Pdfkit fork that is part of react-pdf.

It seemed that just some files need to be brought from the latest version of PdfKit. However, the output PDF was not a valid PDF/A file because of "invalid stream length" (more on this later). Therefore, I tried to update the reference file as well. This solved the invalid stream length problem, but somehow corrupted embedded fonts, which is critical for PDF/A. I decided to get back to the invalid stream length problem and it turned out that the only stream with problems is the one containing the color space. Moreover, the difference between the indicated stream length in the PDF and the actual embedded stream length was equal to the original stream length. It turned out that since the reference writing logic does not reset data.Length if already present, the problem is caused by this row.

I guess that someone with a better knowledge about the PDF format could make my changes less workaround-ish, but at this moment, the result is enough for us and produces valid PDF/A files ;-)

You can find all the changes here: https://github.com/eManPrague/react-pdf

Let me know if I can help with integration to the main react-pdf repo. Thank you for your great work!

florianbepunkt commented 2 weeks ago

@gius Do you maintain your fork? @diegomura Starting 01.01.2025 the majority EU businesses are required to issue electronic invoices where one of the accepted formats (ZUGFERD) requires a PDF/A3 compliant pdf. You can verify compliance using Adobe Acrobat preflight tools.

gius commented 2 weeks ago

@florianbepunkt we are not using the code in production now, so it is not actively maintained. Are there any issues?