Module: InvoicePrinter
- Defined in:
- lib/invoice_printer.rb,
lib/invoice_printer/version.rb,
lib/invoice_printer/document.rb,
lib/invoice_printer/pdf_document.rb,
lib/invoice_printer/document/item.rb
Overview
Create PDF versions of invoices or receipts using Prawn
Example:
invoice = InvoicePrinter::Document.new(...)
InvoicePrinter.print(
document: invoice,
font: 'path-to-font-file.ttf',
stamp: 'stamp.jpg',
logo: 'logo.jpg',
file_name: 'invoice.pdf'
)
Defined Under Namespace
Classes: Document, PDFDocument
Constant Summary collapse
- VERSION =
'1.0.0'
Class Method Summary collapse
- .labels ⇒ Object
-
.labels=(labels) ⇒ Object
Override default English labels with a given hash.
-
.print(document:, file_name:, labels: {}, font: nil, stamp: nil, logo: nil, background: nil) ⇒ Object
Print the given InvoicePrinter::Document to PDF file named
file_name
. -
.render(document:, labels: {}, font: nil, stamp: nil, logo: nil, background: nil) ⇒ Object
Render the PDF document InvoicePrinter::Document to PDF directly.
Class Method Details
.labels ⇒ Object
53 54 55 |
# File 'lib/invoice_printer.rb', line 53 def self.labels PDFDocument.labels end |
.labels=(labels) ⇒ Object
Override default English labels with a given hash
Example:
InvoicePrinter.labels = {
name: 'Invoice',
number: '201604030001'
provider: 'Provider',
purchaser: 'Purchaser',
payment: 'Payment',
payment_by_transfer: 'Payment by bank transfer on the account below:',
payment_in_cash: 'Payment in cash',
account_number: 'Account NO:',
swift: 'SWIFT:',
iban: 'IBAN:',
issue_date: 'Issue date:',
due_date: 'Due date:',
item: 'Item',
quantity: 'Quantity',
unit: 'Unit',
price_per_item: 'Price per item',
amount: 'Amount'
}
You can denote the details or translations of labels by using sublabels. To set a sublabel for a label, just assign it under sublabels
e.g.
InvoicePrinter.labels = {
...
sublabels: { tax: 'Daň', amount: 'Celkem' }
}
49 50 51 |
# File 'lib/invoice_printer.rb', line 49 def self.labels=(labels) PDFDocument.labels = labels end |
.print(document:, file_name:, labels: {}, font: nil, stamp: nil, logo: nil, background: nil) ⇒ Object
Print the given InvoicePrinter::Document to PDF file named file_name
document - InvoicePrinter::Document object file_name - output file labels - labels to override font - font file to use stamp - stamp & signature (image) logo - logotype (image)
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/invoice_printer.rb', line 65 def self.print(document:, file_name:, labels: {}, font: nil, stamp: nil, logo: nil, background: nil) PDFDocument.new( document: document, labels: labels, font: font, stamp: stamp, logo: logo, background: background ).print(file_name) end |
.render(document:, labels: {}, font: nil, stamp: nil, logo: nil, background: nil) ⇒ Object
Render the PDF document InvoicePrinter::Document to PDF directly
document - InvoicePrinter::Document object labels - labels to override font - font file to use stamp - stamp & signature (image) logo - logotype (image)
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/invoice_printer.rb', line 83 def self.render(document:, labels: {}, font: nil, stamp: nil, logo: nil, background: nil) PDFDocument.new( document: document, labels: labels, font: font, stamp: stamp, logo: logo, background: background ).render end |