Generating a PDF report dynamically

57 views
Skip to first unread message

Ganesh Ranganathan

unread,
Mar 26, 2014, 2:04:50 PM3/26/14
to chen...@googlegroups.com, rubyonra...@googlegroups.com
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. I need to use the layout and just update the values, create the PDF out of it and let the user download it.

Could you please suggest the best way to accomplish this?

Thanks,
Ganesh 

masta Blasta

unread,
Mar 26, 2014, 3:34:41 PM3/26/14
to rubyonra...@googlegroups.com
Ganesh Ranganathan wrote in post #1141105:
You can use any of these excellent tools to generate PDFs from HTML

https://www.ruby-toolbox.com/categories/pdf_generation

I'm pretty certain though that there is nothing out there that will
parse an adobe illustrator file for you.

--
Posted via http://www.ruby-forum.com/.

Ganesh Ranganathan

unread,
Mar 26, 2014, 3:42:09 PM3/26/14
to rubyonra...@googlegroups.com
On Thu, Mar 27, 2014 at 1:04 AM, masta Blasta <li...@ruby-forum.com> wrote:
I'm pretty certain though that there is nothing out there that will
parse an adobe illustrator file for you.

Thanks masta. Is there any intermediate file format that both Prawn and Illustrator/Indesign can talk with. The person designing the report only knows these two tools which

masta Blasta

unread,
Mar 26, 2014, 4:21:11 PM3/26/14
to rubyonra...@googlegroups.com
Ganesh Ranganathan wrote in post #1141109:
> On Thu, Mar 27, 2014 at 1:04 AM, masta Blasta <li...@ruby-forum.com>
> wrote:
>
>> I'm pretty certain though that there is nothing out there that will
>> parse an adobe illustrator file for you.
>>
>
> Thanks masta. Is there any intermediate file format that both Prawn and
> Illustrator/Indesign can talk with. The person designing the report only
> knows these two tools which

No. It just can't work that way.

Prawn uses its own syntax (DSL) to create a PDF. It is ruby code that
has to be written from scratch.

Something like wicked_pdf, turns an HTML document into PDF. That means
you need your document to be an ERB template that you can then use the
plugin on to get a PDF.

There is no way to automate the process in the way that you want - Read
.ai, parse .ai, find my fields, plug in these values into those fields,
spit out a PDF. That is such a hugely monumental process, that I don't
even think any proprietary Adobe software does it.

Rails can do a lot of things, but not that.

You need to MANUALLY turn your illustrator file into a template.pdf.erb
file (which is the same as a .html.erb file). You will need styles,
proper HTML, the whole works.
Then you make a controller action to accept the pdf mime type
respond_to do |format|
format.pdf {}

then follow the instructions on the wicked_pdf gem for all the other
configurations. It's not a simple process because of the wkhtmltopdf
binary.

Ganesh Ranganathan

unread,
Mar 26, 2014, 4:33:11 PM3/26/14
to rubyonra...@googlegroups.com

On Thu, Mar 27, 2014 at 1:51 AM, masta Blasta <li...@ruby-forum.com> wrote:
You need to MANUALLY turn your illustrator file into a template.pdf.erb
file (which is the same as a .html.erb file). You will need styles,
proper HTML, the whole works.
Then you make a controller action to accept the pdf mime type
    respond_to do |format|
        format.pdf {}

then follow the instructions on the wicked_pdf gem for all the other
configurations. It's not a simple process because of the wkhtmltopdf
binary.

Got it!! Thanks for the explanation. Would the same process that you explained work in this way?

1) Create a layout in Indesign (not illustrator)
2) Export the layout to Html/CSS. This is a built in feature
3) Embed the HTML in the template.pdf.erb
4) Supply the values dynamically in the template
5) Generate the PDF 




Walter Lee Davis

unread,
Mar 26, 2014, 4:42:00 PM3/26/14
to rubyonra...@googlegroups.com
You beat me to it. This is what I was going to recommend. You may find that you have a lot of cleanup needed to make the InDesign HTML (and CSS) less awful. But this should get you started.

Walter

>
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CALFmRoG5DkLOqeReM1QXud-aJsA4Do1puMUSe2JaCJTz7a%3D-4g%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

Ganesh Ranganathan

unread,
Mar 26, 2014, 6:01:46 PM3/26/14
to rubyonra...@googlegroups.com

On Thu, Mar 27, 2014 at 2:12 AM, Walter Lee Davis <wa...@wdstudio.com> wrote:
You beat me to it. This is what I was going to recommend. You may find that you have a lot of cleanup needed to make the InDesign HTML (and CSS) less awful. But this should get you started.

I'm going to first try it on a simple one page report to check the feasibility. Then move on to the full featured report. Hopefully the cleanup of the markup won't be too tedious 



Walther Diechmann

unread,
Mar 27, 2014, 1:46:30 AM3/27/14
to rubyonra...@googlegroups.com
I'd try saving the Adobe Illustrator to XML (or to PDF and then have Adobe Acrobat save it to XML) and finally let flying-saucer have a chew at it and see if it will make a descent PDF out of it.

If so,

then you could take the XML, rework it in your rails app, spit out the XML back into the 'queue' and, voilá :)

But does the designer not master Adobe Dreamweaver or some HTML Designer tool? Then have him design the form in that tool and have him spit out HTML 4.1, skip the Adobe Illustrator -> PDF -> Acrobat -> XML part of the 'game' and go straight to

HTML -> flying-saucer -> PDF

works for me :)

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.

Ganesh Ranganathan

unread,
Mar 27, 2014, 3:12:37 AM3/27/14
to rubyonra...@googlegroups.com

On Thu, Mar 27, 2014 at 11:16 AM, Walther Diechmann <wal...@diechmann.net> wrote:
But does the designer not master Adobe Dreamweaver or some HTML Designer tool? Then have him design the form in that tool and have him spit out HTML 4.1, skip the Adobe Illustrator -> PDF -> Acrobat -> XML part of the 'game' and go straight to

Thanks, that's a much more simpler way because I think Dreamweaver would generate cleaner markup than Indesign. Will check with the designer.

Reply all
Reply to author
Forward
0 new messages