Question

I'm creating a Facebook app using Rails and hosted on Heroku and I'm having a bit of trouble finding the ideal way to solve a problem. I want the user to be able to move their photos around on the screen, position them, and then download that as either a PDF or a PNG file to be emailed or printed. I have the app getting the user's facebook photos and they can drag them on to a HTML5 Canvas element to position them. Taking this canvas, however, and converting it into something printable is where I'm hitting a dead end.

Basically I have a few ideas I have tried:

Convert the Canvas to a PNG using toDataURL() - Would work perfectly but since the photos are external, the canvas is "dirty" and will throw up a security issue. I've thought about trying to copy the pixels of each image to a pixel array but I've heard this may not work either due to security issues. Since the app is dealing with people's facebook images I really don't want to store them on the app's server.

Use PDFKit/wkhtmltopdf to create a PDF using Rails - I've tried this, but since the app is a Sinatra app (I think), it's confusing me a lot. It's throwing errors with the to_pdf call saying 'Command Failed'. I've tried adding a config.middleware.use line but I'm not 100% sure where to put it and everywhere seems to be failing saying "config" is an undefined variable. Also installing wkhtmltopdf seems to fail on Heroku once I test it outside localhost.

Use Prawn to create a PDF using Rails - I've tried prawn but it seems to have a similar problem to PDFKit and I get confused about what goes where on a Sinatra app. I'm sure I read as well that people were having problems with it too.

Have I missed any obvious solutions to this, or is there something I'm not thinking of? All I want to do is create some kind of easily printable file with positioning intact that can be easily downloaded and printed by the user but I've come across so many problems that I don't know where to go next and I'm going round in circles.

If anyone had any advice for me about how I could get around this problem I'd really appreciate it.

Was it helpful?

Solution

if prawn is giving you grief just use one of the jquery plugins to print your div content. You could even configure a pdf printer and print the document instead of hard copy if you so wish/need images in pdf format.

I use http://archive.plugins.jquery.com/project/jqPrint plugin in one of my projects and it works like a charm.

OTHER TIPS

It sounds like many of your issues relate to the necessary PDF binaries not being accessible on Heroku. In following with the twelve factor approach to dependency isolation Heroku purposely provides a very bare system.

If you need to run a custom binary on Heroku I'd suggest looking at a tool called Vulcan which can compile a binary that's compatible with the Heroku runtime.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top