How to Generate CSV and PDF Files from JSON Data on a Website?

0
8
Asked By CreativePineapple42 On

I'm trying to build a user interface that can create CSV and PDF files from a templated file using JSON data. For generating the CSV, I assume I can skip certain rows and columns and directly input the data, which seems pretty straightforward. However, when it comes to PDFs, I'm a bit stuck. It sounds like I'd need to construct HTML rows and columns and then specify a class or ID to target for populating the data. Does that make sense?

I want to handle everything on my own backend without relying on third-party services. Ideally, users could just click a button to download the file. I plan to use a React state to hold the values and then parse the data, create a duplicate file, and rename it using a format like genericname/userid/dataid.filename before filling in the details. Should I generate the document in the frontend or send the data to the backend via API to process it and return the downloadable file?

If the logic is backend-driven, I'd save the file to the filesystem and check if it already exists, serving it if it does, or creating it if it doesn't. On the frontend, I want to make the file accessible by simply appending it during page load, without needing any filesystem changes. Does my approach sound reasonable? I'm open to any ideas, resources, or even constructive criticism!

1 Answer

Answered By SmartCoder88 On

For generating PDFs, I actually found a great way to do it using ODF templates. You save your template as a single XML file, edit it with your data, and then use Unoconv to convert it into a PDF. The setup worked superbly for rich text documents that needed to meet the PDF/UA2 standard for accessibility. There’s a new project called Unoserver that might be even better than Unoconv since the latter is archived now. Basically, you would use OpenOffice and control it through an API to convert your files. It's super effective!

TrendyTaco99 -

That sounds like a smart solution! Using ODF as an XML format lets you treat it like a text file, which is really flexible. I think you'll need to install Unoconv on your web hosting, but that should work well. Going with a local solution rather than a cloud API will definitely help with troubleshooting and could save costs in the long run!

Related Questions

Keep Your Screen Awake Tool

Favicon Generator

JWT Token Decoder and Viewer

Ethernet Signal Loss Calculator

Remove Duplicate Items From List

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.