0

In my rails application, I am looking to generate a PDF report dynamically. The layout would be static and given to me by a designer who has made it on Adobe Illustrator/InDesign. It contains a few pie charts and bar graphs.

I need to use the layout and just update the values based on user input, export to PDF and let the user download the PDF file

Could you please suggest the best way to accomplish this?

ganeshran
  • 3,512
  • 7
  • 41
  • 69

1 Answers1

1

This may be what you want,prawn https://github.com/prawnpdf/prawn

require "prawn"

Prawn::Document.generate("hello.pdf") do
  text "Hello World!"
end

you put your template in your app, then use this gem to fill out it.

About the pie chart,prawn-graph may help. https://github.com/HHRy/prawn-graph/, it is a extension of for prawn in chart. The code may like:

require 'rubygems'
require 'prawn/core'
require 'prawn/graph'

data = [ ['A', 10], ['B', 11], ['C' 12] ]

Prawn::Document.generate('test.pdf') do
  test 'Graph Example'
  bar_graph data at => [10,10]
end
Chuanpin Zhu
  • 2,226
  • 1
  • 21
  • 21
  • Hi @Chuanpin Any idea if Prawn supports more advanced layouts. I am looking to substitute values in a graphic heavy layout designed in Illustrator/Indesign. Is there any intermediate format which Prawn can talk to? – ganeshran Mar 26 '14 at 19:32
  • 1
    Hi Ganeshran, I am afraid this extension gem only supports column, bar and pie charts. – Chuanpin Zhu Mar 26 '14 at 19:49
  • Hi Ganeshran, you should consider using [PDFlib]:http://www.pdflib.com/en/download/pdflib-familie/. it's not OSS though, but it has a nice and powerful API and ruby support – ulf_t Jun 18 '14 at 13:56