views:

704

answers:

5

Hi there,

A Ruby on Rails app will have access to a number of images and fonts. The images are components of a visual layout which will be stored separately as a set of rules. The rules specify document dimensions along with which images are used and where. The app needs to take these rules, fetch the images, and generate a PDF that is ready for local printing or emailing.

The fonts will also be important. The user needs to customize the layout by inputting text which will be included in the PDF. The PDF must therefore also contain the desired font so that the document renders identically across different machines.

Each PDF may have many pages. Each page may have different dimensions but this is not essential. Either way, the ability to manipulate the dimensions and margins given by the PDF is essential.

The only thing that needs to be regularly changed is the text. If this is takes too much development then the app can store the layouts in 3rd party PDFs and edit the textual content directly. Eventually though, this will prove too restrictive on the apps intended functionality so I would prefer the app to generate the PDF's itself.

I have never worked with PDFs before and, for the most part, I've never had to output anything to the user outside their monitor. A printed medium could require a very different approach to get the best results. If anyone has any advice on how to model the PDF format this it would be really appreciated. The technical aspects of printing such as bleed, resolution and colour have already been factored in to the layouts and images.

I am aware that PDF is a proprietary file format and I want to use free or open source software. I have seen a number of Ruby libraries for generating PDF files but because I am new on this scene I have no way to reliably compare them and too little time to implement and test them all. I also have the option of using C to handle this feature and if this is process intensive then that might be preferred.

What should I be thinking about and how should I be planning to implement this?

+1  A: 

I worked on a project that generated some very simple PDFs a few months ago. I thought it was a total pain in the ass, but it got done thanks to: Prawn and prawnto. Prawn is a PDF library and prawnto is a handy Rails plugin.

Good luck.

theIV
"I thought it was a total pain in the ass, but it got done thanks to: Prawn and prawnto."Just reading that right now is a weight off my shoulders :)
deau
+1  A: 

Generating PDFs is a bit annoying but there are a lot of things out there doing that such as prawn or prince.

I like the second option because you can use HTML/CSS to generate your PDF but I never tested it. Prawn has proven helpful and effective.

edit: note that Prince is actually pretty expensive

marcgg
Yes I've also been looking at prince for run of the mill "view to pdf" jobs. For the task in hand though, prawn has all the necessary functionality and seems to make it simpler than i'd expected.
deau
According to the link you gave me (for example) prince passes the acid2 test. It seems like anything you've got in HTML you can have in PDF for the cost of a gem. Sweet!
deau
Yes prince looks pretty impressive :)
marcgg
@marcgg You might want to consider modifying your answer to go to the real Prince site instead of that blog entry, and mention that it costs 3800 USD per server license. Sort of a big STOP for a rails dev, usually. Thanks!
Yar
@yar true I didn't check that :\ editing right now
marcgg
+1  A: 

There are a few different Railscasts using PDF::Writer and Prawn.

Garrett
+1 for those screen casts m8, a great resource :-)
deau
A: 

Yes, prawn seem very promising. I'm gonna try that in my project today.

satya
A: 

I would also suggest using ruby to programmatically format an OpenOffice .odt file. It's easier to format odt then drawing bounding boxes in Prawn.

http://github.com/ngty/clamsy

JasonOng