|
Post by lothcor on Jul 13, 2017 3:07:21 GMT
Hi all, for anyone interested in PDF table generation and have realized the included version of PDFWriter in rhodes won't work due to a mutex issue (happens in rails as well), I have taken the ypdf-writer from zdavatz/ypdf-writer (rails compatibility version) and got it working with rhodes. It can be found github.com/lothcor/ypdf-writerJust replace the files in rhodes/lib/extensions/pdf-writer/pdf with that found in ypdf-writer/lib/pdf With this i was able to generate a table in a PDF to turn this: into this:
|
|
|
Post by egghead on Jul 13, 2017 4:11:24 GMT
Great! Sample code please?
|
|
|
Post by lothcor on Jul 13, 2017 4:56:54 GMT
Here I am using SQL data that is fetched elsewhere in $duetocalve, Table columns need to match the SQL field order
You must add the necessary extensions to build.yml as noted in the documentation for PDF generation, then add a couple of require statements in.
build.yml -- extensions: - pdf-writer
- thread
- digest-md5
- rhoxml
controller -- require 'pdf/writer'
require 'pdf/simpletable'
example data -- [{"source_id"=>40004, "object"=>"", "Cows_HIONo"=>"3814", "Cows_DueCalve"=>"17/06/2017", "Cows_DueDay"=>-26, "Cows_DueSire"=>"CBGOODWHONE"}, {"source_id"=>40004, "object"=>"", "Cows_HIONo"=>"3856", "Cows_DueCalve"=>"17/06/2017", "Cows_DueDay"=>-26, "Cows_DueSire"=>"CBGOODWHONE"}]
def print_calving
pdf = PDF::Writer.new
pdf.select_font "Times-Roman"
table = PDF::SimpleTable.new
i0 = pdf.image Rho::RhoApplication::get_user_path()+"/public/images/logo.png", :justification => :left, :resize => 0.75
table.title = "Due To Calve"
table.column_order.push(*%w(Cows_HIONo Cows_DueCalve Cows_DueDay Cows_DueSire))
table.columns["Cows_HIONo"] = PDF::SimpleTable::Column.new("Cows_HIONo")
table.columns["Cows_HIONo"].heading = "Cow"
table.columns["Cows_DueCalve"] = PDF::SimpleTable::Column.new("Cows_DueCalve")
table.columns["Cows_DueCalve"].heading = "Due Date"
table.columns["Cows_DueDay"] = PDF::SimpleTable::Column.new("Cows_DueDay")
table.columns["Cows_DueDay"].heading = "Days"
table.columns["Cows_DueSire"] = PDF::SimpleTable::Column.new("Cows_DueSire")
table.columns["Cows_DueSire"].heading = "Due Sire"
table.show_lines = :all
table.show_headings = true
table.orientation = :center
table.position = :center
data = Rho::JSON.parse($duecalve.to_json)
table.data.replace data
table.render_on(pdf)
fileNameW = File.join(Rho::RhoApplication::get_user_path(), 'demo.pdf')
pdf.save_as(fileNameW)
end
|
|
|
Post by egghead on Jul 13, 2017 5:33:54 GMT
OK. Thanks
|
|