I’m trying to generate PDF files from a Python script for a project due soon but can’t figure out the right approach with the available options. Has anyone done this before?
ReportLab is the usual starting point if you need to draw text, tables and images directly from Python. For an existing HTML layout, WeasyPrint can be quicker, especially for worksheets. I’ve used ReportLab for marking sheets, and its basic canvas example got me going without much fuss.
Had the same thing last month trying to auto make our weekly reports. I am no python expert but we used reportlab and it did the job for adding text and tables. Install it then follow a basic tutorial to set the page size and write your content. If that feels heavy maybe fpdf is simpler from what I heard.
I tried a few of the Python PDF libraries and got lost in the docs every time. What worked for me was building the pages in LibreOffice Writer and letting my little script export them to PDF instead. If you’re in a hurry, that route saved me a week of fiddling.
I don’t write code, so Python is a bit beyond me. When I need a quick contract or estimate, I do myself a favour and just use PDFcap to generate the final file from a normal document. If you absolutely have to use code, I have heard folks mention something called ReportLab. Are you on a Mac or a Windows machine?
@nicholasb23 That LibreOffice trick is clever, I never thought of driving it from a script. We do something similar at the library with mail merge for volunteer schedules. One tip: test your export on one page first, fonts sometimes shift between Writer and the final PDF. Avoid fancy templates with floating images, they tend to jump around when the file gets converted. Learned that one the hard way.
honestly i dont use python much for pdfs, but ive seen people use reportlab or fpdf for basic stuff. if you need something that matches an existing layout, i always start by building a reusable template and filling in the fields from the script instead of generating everything from scratch. that way you can tweak the look in your pdf tool and just swap the data each time. what kind of content are you trying to put in them?
I used reportlab for a small project, works fine for basic text and tables. If you need html to pdf, weasyprint is easier to set up.
@nicholasb23 The LibreOffice trick is what I fall back on too, our flyers already live in Writer and driving the export from a script saves me redoing layouts by hand every quarter. One thing I learned the hard way: keep the template on your own machine, since shared drive fonts never quite match and the spacing shifts. For @HarperONeill’s deadline I’d still try reportlab, it handled our tables fine.