loading...
Cover image for I just released InvoicePrinter 2.0

I just released InvoicePrinter 2.0

strzibny profile image Josef Strzibny ・2 min read

InvoicePrinter is a Ruby library, server, and command-line client to make beautiful PDF invoices without browsers in no time. It's pure Ruby, but can be also used outside the Ruby world as a Docker container with a simple JSON API.

New features in 2.0:

  • New modern look & feel
  • More flexible buyer/seller boxes
  • Server is decoupled to a separate gem invoice_printer_server
  • New bundled fonts in a separate gem invoice_printer_fonts
  • Official Docker image
  • Prawn 2.2

Here is the project GitHub page, in the examples/ directory you can find a lot of code examples and how they look as PDFs. Follow docs/ to learn more about using it as a library, server or a command-line client.

Here is one example (download the final PDF):

Alt Text

And Ruby code to generate it:

#!/usr/bin/env ruby
# This is an example of a international invoice with Czech labels and English translation.

require 'invoice_printer'

labels = {
  name: 'Faktura',
  provider: 'Prodejce',
  purchaser: 'Kupující',
  tax_id: 'IČ',
  tax_id2: 'DIČ',
  payment: 'Forma úhrady',
  payment_by_transfer: 'Platba na následující účet:',
  account_number: 'Číslo účtu',
  issue_date: 'Datum vydání',
  due_date: 'Datum splatnosti',
  item: 'Položka',
  quantity: 'Počet',
  unit: 'MJ',
  price_per_item: 'Cena za položku',
  amount: 'Celkem bez daně',
  subtotal: 'Cena bez daně',
  tax: 'DPH 21 %',
  total: 'Celkem'
}

# Default English labels as sublabels
sublabels = InvoicePrinter::PDFDocument::DEFAULT_LABELS
labels.merge!({ sublabels: sublabels })

first_item = InvoicePrinter::Document::Item.new(
  name: 'Konzultace',
  quantity: '2',
  unit: 'hod',
  price: 'Kč 500',
  amount: 'Kč 1.000'
)

second_item = InvoicePrinter::Document::Item.new(
  name: 'Programování',
  quantity: '10',
  unit: 'hod',
  price: 'Kč 900',
  amount: 'Kč 9.000'
)

provider_address = <<ADDRESS
Rolnická 1
747 05  Opava
Kateřinky
ADDRESS

purchaser_address = <<ADDRESS
Ostravská 1
747 70  Opava
ADDRESS

invoice = InvoicePrinter::Document.new(
  number: 'č. 198900000001',
  provider_name: 'Petr Nový',
  provider_lines:  provider_address,
  provider_tax_id: '56565656',
  purchaser_name: 'Adam Černý',
  purchaser_lines: purchaser_address,
  issue_date: '05/03/2016',
  due_date: '19/03/2016',
  subtotal: 'Kč 10.000',
  tax: 'Kč 2.100',
  total: 'Kč 12.100,-',
  bank_account_number: '156546546465',
  account_iban: 'IBAN464545645',
  account_swift: 'SWIFT5456',
  items: [first_item, second_item],
  note: 'Osoba je zapsána v živnostenském rejstříku.'
)

InvoicePrinter.print(
  document: invoice,
  labels: labels,
  font: File.expand_path('../../assets/fonts/overpass/Overpass-Regular.ttf', __FILE__),
  logo: File.expand_path('../logo.png', __FILE__),
  file_name: 'promo.pdf',
  page_size: :a4
)

Before the final release I wrote a little background post on my blog.

Try it out and let me know what you think!

Discussion

pic
Editor guide