Invoicing from the command line

Are you a freelancer? You don’t need to leave your command line to create invoices for your clients. InvoicePrinter is a Ruby library for producing PDF invoices without too much hassle. If you haven’t seen it before, you can read more about it in the announcement or its GitHub page. With the upcoming 1.1.0 release (currently as release candidate) a command line executable is included so you can now use command line to invoice your clients. No need to learn Ruby, just pass the data in the familiar JSON format! Here is how to create your first invoices.


InvoicePrinter requires Ruby. If you are on Fedora or Fedora-based systems just run:

And then install the pre-release of the gem via RubyGems (we need 1.1.0.rc1 or higher):

Now the executable called invoice_printer should be available on your path.

Creating the first invoice

Now opening out.pdf will give you a familiar structure of an invoice. But something is missing. Data!

As I suggested in the beginning we need to provide InvoicePrinter with a JSON representing our data. Here is one that is not empty:

The command changes to:

out.pdf is your first real invoice, so congratulations!

Editing labels

We fixed our empty invoice with data but what if we don’t like our predefined labels? There is a --labels switch we can take advantage of and provide our own in JSON. The following command would translate the labels into Czech:

For clarity this is the JSON used:

Changing the default font

Attentive readers noticed that I used an extra --font switch in the last example. This is to change to default font to something that would support my language of choice (Czech in this case).

Including company logo

If you are a serious business you probably include a logotype on your invoices. InvoicePrinter supports logotypes with --logo switch so the only thing you need to do is to provide a path to the image itself as follows:

Remember you can always run invoice_printer --help if you don’t remember a particular switch. And remember that InvoicePrinter is an actual Ruby library you can include in your programs, just go and read README.

Happy hacking and invoicing!

Leave a comment

Your email address will not be published. Required fields are marked *