strzibny / invoice_printer

Super simple PDF invoicing
MIT License
960 stars 73 forks source link

how start? #14

Closed dcalixto closed 7 years ago

dcalixto commented 7 years ago

generally with praw the pdf start with

respond_to do |format|
    format.html
     format.pdf do
        pdf = InvoicePdf.new
       send_data.to_s pdf.render, filename: "invoice_#{@invoice.id}.pdf", type: 'application/pdf'
     end
  end

and on pdf

include ActionView::Helpers::NumberHelper

class InvoicePdf < Prawn::Document

  def initialize(boutique, invoice, order, buyer, product)
    super({:page_size => 'A4'})

    @invoice = invoice
    @order = order

    @product = product
    text "FATURA ##{@invoice.id}"
    move_down 10
    body
  end

but with invoice_printer did not start. thanks

strzibny commented 7 years ago

@dcalixto Sorry for late responce.

So in a controller you can do something like:

# GET /invoices/1
def show       
  respond_to do |format|
    format.pdf {
      @pdf = InvoicePDF.new(@invoice).render
      send_data @pdf, type: 'application/pdf', disposition: 'inline' 
    }
  end
end

and InvoicePDF object would then call InvoicePrinter:

require 'invoice_printer'

  class InvoicePDF
    include ActionView::Helpers::TranslationHelper
    include InvoiceBar::InvoiceBarHelper

    def initialize(invoice)
      @invoice = invoice
    end

    def render
      InvoicePrinter.render(
        document: printable_invoice
      )
    end
strzibny commented 7 years ago

I included an example to README: https://github.com/strzibny/invoice_printer#ruby-on-rails

Thanks for the feedback, closing now. Please continue if something is unclear.