README.md in invoice_printer-0.0.8 vs README.md in invoice_printer-0.0.9

- old
+ new

@@ -20,11 +20,11 @@ - Payment method box showing banking details including SWIFT and IBAN fields - Issue/due dates box - Configurable items' table with item description, quantity, unit, price per unit, tax and item's total amount fields - Final subtotal/tax/total info box - Page numbers -- Configurable labels +- Configurable labels & sublabels (optional little labels) - Configurable font file - Logotype (as image scaled to fit 50px of height) - Background (as image) - Stamp & signature (as image) - Note @@ -63,10 +63,15 @@ InvoicePrinter.print( document: invoice, file_name: 'invoice.pdf' ) + +# Or render PDF directly +InvoicePrinter.render( + document: invoice +) ``` Here is an full example for creating the document object: ```ruby @@ -112,10 +117,33 @@ items: [item], note: 'A note...' ) ``` +### Ruby on Rails + +If you want to use InvoicePrinter for printing PDF documents directly from Rails +actions, you can: + +```ruby +# GET /invoices/1 +def show + invoice = InvoicePrinter::Document.new(...) + + respond_to do |format| + format.pdf { + @pdf = InvoicePrinter.render( + document: invoice + ) + send_data @pdf, type: 'application/pdf', disposition: 'inline' + } + end +end +``` + +## Customization + ### Localization To localize your documents you can set both global defaults or instance overrides: @@ -164,10 +192,45 @@ subtotal: 'Subtotal' total: 'Total' } ``` +You can also use sublabels feature to provide the document in two languages: + +```ruby +labels = { + ... +} + +sublabels = { + 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' +} + +labels.merge!({ sublabels: sublabels }) + +... +``` + +Now the document will have a little sublabels next to the original labels in Czech. + ### Font To support specific characters you might need to specify a TTF font to be used: ``` ruby @@ -179,19 +242,19 @@ We recommend you DejaVuSans and Overpass fonts. ### Background -To include a background image you might need to create the file according to the size and resolution to be used (see: [examples/background.jpg](https://github.com/strzibny/invoice_printer/blob/master/examples/background.jpg)): +To include a background image you might need to create the file according to the size and resolution to be used (see: [examples/background.png](https://github.com/strzibny/invoice_printer/blob/master/examples/background.png)): ``` ruby InvoicePrinter.print( ... - background: File.expand_path('../background.jpg', __FILE__) + background: File.expand_path('../background.png', __FILE__) ) ``` ## Copyright -Copyright 2015-2016 © [Josef Strzibny](http://strzibny.name/). MIT licensed. +Copyright 2015-2017 © [Josef Strzibny](http://strzibny.name/). MIT licensed. Originally extracted from and created for an open source single-entry invoicing app [InvoiceBar](https://github.com/strzibny/invoicebar).