Can you write me a program that can generate formatted PDFs from JSON? Preferably using the simplest of tools
Check,
- https://pandas.pydata.org/pandas-docs/stable/reference/api/p...
- https://pandas.pydata.org/pandas-docs/stable/reference/api/p...
Try something like,
import pandas as pd
file_path = 'excel_file.xlsx'
df = pd.read_excel(file_path, sheet_name='WORKSHEET NAME')
df.to_json('output.json', orient='records', indent=4)`data` isn't defined. It missed loading the json into it.
Edit here,
I've been testing some models today. It's a great solution, easy to fix. I like the package it chose.
My head is simply on evaluating things and code. Criticizing the model and output, not directed at you.
Where it gets tricky is handling more complex data structures: deeply nested objects and arrays, different date formats, varying element types and adapting the layout based on the structure. SnazzyPDF's layout engine automates those decisions. The configuration options are still limited but that's what I'm focusing on improving next.
I asked Claude to create me something to do this. It worked first go.
import json from reportlab.lib.pagesizes import letter from reportlab.platypus import SimpleDocTemplate, Table, TableStyle, Paragraph from reportlab.lib.styles import getSampleStyleSheet from reportlab.lib import colors
def create_pdf_from_json(json_file, pdf_file): # Read JSON data with open(json_file, 'r') as file: data = json.load(file)
if __name__ == "__main__": create_pdf_from_json("input.json", "output.pdf")