Discussion on: Generate PDF invoices from Markdown using Pandoc

martin_betz profile image
Martin Betz Author

Thanks for your answers. Did you write a whole own app for your client and financial management? Or is it an add-on on a SaSS solution where you already have the customer data?

4ndrej profile image

Well, it's ultra minimalistic single purpose tool hacked together within few evenings and using for few years.

All customers / invoices data is in ruby source file so there is no need for CRUD code. Adding customer is just copy/paste in ruby file and editing few lines. Adding invoice is super easy copy/paste with just defining customer, date and invoice items. Good old copy/paste programming.

It's using Sinatra github.com/sinatra/sinatra which allows super short code. The main app which basically does just routing and params checking is under 80 lines including requires and some comments.

There is a few hundred lines of customers / invoices data too. It's growing quite slow since this is only side-job. All data are loaded into memory but I can spare few megabytes for the in memory data for sure.

The haml view files for rendering html app are under 4kB. Haml haml.info/ is saving lot of typing.

All magic happens in the invoice.prawn file which is 440 lines and about 11kB. There is the pdf layout filled with data from the customer and invoice data with lot of conditions controlling the optional data (for example VAT number is optional so I have to skip the space when there is no VAT number defined to retain the layout). There is also 15 lines dealing with preparing the VAT summary for 0/10/20% VAT per each item defined.

This prawn file generates the pdf which is shown in the Chrome so I can preview it and then save and send to customer.