Search code examples
ruby-on-railsruby-on-rails-4adobeadobe-indesignadobe-illustrator

Generating PDF in rails from an Illustrator/Indesign file


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?


Solution

  • 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