ThinreportsRails is constructed by Rails Template Handler ThinReports the PDF.
Oldname: thinreports-handler
- Ruby 1.9.3, 2.0.X, 2.1.X, 2.2.X, 2.3.X
- Rails 3.X, 4.X
- ThinReports 0.9.1 later
Add this line to your application's Gemfile:
gem 'thinreports-rails'
And then execute:
$ bundle
Or install it yourself as:
$ gem install thinreports-rails
class OrdersController < ApplicationController
def index
@orders = Order.all
end
end
app/views/orders/index.pdf.thinreports
report.start_new_page
report.page.values printed_at: Time.now
@orders.each do |order|
report.page.list(:list).add_row do |row|
row.item(:col1).value order.name
row.item(:col2).value order.num
end
end
class OrdersController < ApplicationController
def index
@orders = Order.all
respond_to do |format|
format.pdf {
send_data render_to_string, filename: 'foo.pdf', type: 'application/pdf', disposition: 'attachment'
}
end
end
end
Example of using the app/views/reports/index.tlf
.
Write code like this to index.pdf.thinreports
.
:layout_options
is an option ThinReports::Report::Base#use_layout
method.
report.set_layout tlf: 'reports/index', layout_options: { default: true }
report.generate_options(security: {
user_password: 'foo',
owner_password: 'bar',
permissions: {
print_document: false,
modify_contents: false,
copy_contents: false
}
})
For exsample to use, app/views/orders/_header.pdf.thinreports
.
title
is local variable in _header.pdf.thinreports
.
report.partial! 'header', title: title
- TwitterID: @takeshinoda
- Blog: http://d.hatena.ne.jp/takeshinoda/
m(__)m, send me pull request.
Copyright (c) 2012 Takeshi Shinoda.