Hi everyone, I was recently contacted by the folks at DocRaptor telling me about their service so I decided to take it for a test drive and see for myself what it actually is.
DocRaptor provides you with an API to generate PDF and XLS files from HTML and CSS files. Today we will take a look at how we can use it to generate the PDF for a payment receipt.
We need to install the
pip install --upgrade docraptor
We also need to signup for a trial on DocRaptor.
Try running the sample code to make sure that everything is working:
If the above code works without any errors then you should have a
test.pdf file in the working directory. You can check out the official Python docs on DocRaptor’s website.
Now let’s move on and actually create a simple receipt HTML template and use that to generate a receipt.
Now we can go ahead and code up a template from scratch but what if I told you that DocRaptor already provides you with some templates which you can customize and quick start your pdf generation journey?
Let’s customize a DocRaptor template. This is the code for a receipt template which DocRaptor has on its website:
Let’s customize it to reflect the Python Tips brand.
I customized the logo, header, footer and table data and also added a “Paid” stamp below the total amount. I had to make only minimal changes in the template and now I have a really beautiful receipt template which I can use to generate PDFs.
Now run the Python code again but this time change the
If everything works fine you should end up with a similar PDF:
The usefulness of DocRaptor comes in when you have to generate tons of PDF files on the fly without utilizing a lot of your own system’s resources.
In a future post we will take a look at using Python to generate PDFs and you will see how tedious it can get. I don’t really have any need to generate so many PDFs so I can’t comment on whether DocRaptor is expensive or worth-it but it sure is a convenient service.
If you have read this far then please go ahead and give DocRaptor a try. You can avail a 10% discount by emailing DocRaptor support and mentioning this blog post.
Stay tuned for more posts in the future!