Ruby on Rails & Prawn PDF - ruby-on-rails

Im creating a PDF Document on my Website.
All works just fine, but when i try to add a Image into the PDF i get
"We're sorry, but something went wrong.
We've been notified about this issue and we'll take a look at it shortly."
So something fails with Prawn.
This is how i try
"image 'logo.png"
i tryed so many ways, all found in the internet, nothing seemed to work.
One was with the BASEDIR, how do i know where BASEDIR is?
Anyway im using OSX Server 10.6 and id be very thankfull to anwser me those questions
-Where is the Prawn Logfile?
-How does one add a Image
Thanks very much,
Greetings!

You'll need to refer to the full path to the file.
We usually refer to our images used in PDFs using the RAILS_ROOT as the starting point. So we use something like:
pdf.image "#{RAILS_ROOT}/public/images/logo-header.png"
Assuming pdf is a Prawn::Document object.

Related

Issue printing leaflet map and imagery layer using wkhtmltopdf

currently we are working on a web tool using Ruby on Rails and one of their functions is generate a PDF report based in HTML template, that template has a map built with leaflet-0.7.3 and we are using a gem called pdfkit v0.8.2, wkhtmltopdf-binary v0.9.9.3 to generate PDFs, but right now we are facing an issue with that report, when It generates that report it is splitting the map and layers like this:
PDF error
It is supposed to look like this
Expected result
Any suggestions what's going on? or what should we do?
Any help would be great for us! thank you guys
I was facing a similar issue with my HTML template when It was generated, so, I solved it replacing my leaflet stylesheet with the last version, which is
http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css
please, replace your current stylesheet and share me what was your result.

Prawn + WickedPDF: Using Prawn on wkhtmltopdf/WickedPDF generated PDF's

I am working on a Rails project with both WickedPDF and Prawn. I am using WickedPDF to convert some HTML into a PDF and then using Prawn to add content to that PDF.
When I add content to an uploaded PDF (one that I do not create), Prawn is able to add content without any issues. When I create a PDF using WickedPDF, Prawn has issues when it adds content to the the new WickedPDF generated PDF. It adds the content, but the content seems to be scaled down... a lot (it's barely visible). If I open that same PDF from another program (Gimp, LibreDraw, etc.) and export as PDF, the new PDF works on Prawn as well. So I'm positive it has something to do with the formatting of the WickedPDF generated PDF's. I need Prawn to edit the PDF's that are being generated by WickedPDF, or to be able to generate PDF's that are editable by Prawn.
I searched for other solutions, and found Prawnto (no longer exists), PDFKit (gem installers did nothing), PDFcrowd (I can't pay for it), and am now running out of ideas. I'll be looking through the wkhtmltopdf source code to see if I can further understand the underlying issue (I doubt it, don't know enough about PDF file structure/formatting), but would be very happy if someone has encountered this and has any other ideas.
EDIT 1: Same results occur after creating a PDF from wkhtmltopdf. The issue is not with WickedPDF but with the library it uses. Still haven't found the cause.
EDIT 2: Another interesting result. The text is not only getting scaled down. I just multiplied the font size of the text that Prawn is inserting by 128 so I could see the text. Turns out it is also being flipped upside-down (about the x-axis). Something sinister is happening.
I've just started looking into PDF generators. On this forum, one post mentions that he had scaling issues while using gems that relied on wkhtmltopdf, but didn't experience the problems if he called that library directly.
Hope this helps! I'll update this answer once I get started if I have the same issue but am able to resolve it. Cheers!

Rails 3, Wicked_pdf not picking up styles, print media type, or separate template

So I've been banging my head on this all day yesterday trying to get PDF rendering to work properly. After trying Prawn and PDFKit, I found that the problem with at least getting it to work at all had to do with wkhtmltopdf on Mac OS 10.7, but now the problem is that it completely ignores any styles I add targeting the pdf, the print media type, and any special templates.
Here is a pastebin of where I'm at now: http://pastebin.com/LW16RYjW
Trying all of these and several others didn't work for me:
http://www.snikt.net/blog/2012/04/26/wicked-pdf/
WickedPDF missing layout
http://akabhilash.wordpress.com/2010/11/27/pdf-generation-with-wicked-pdf-in-rails/
I finally got to this setup:
https://github.com/mileszs/wicked_pdf/issues/87
Not knowing what else to do, I physically copied pdf_helper.rb into my lib/ directory (I don't know why it wasn't there before, or even whether it should've been upon bundling(?))
Can anyone tell me why it doesn't seem to be picking up any of the rendering options in the controller, and how I can get the styles to register without affecting the screen (html) version? Any help would be greatly appreciated. Thanks in advance for your time.
Turn off the middleware, or add the route you are trying to customize in the middleware call as documented in the README.

Creating PDF from photos on a Facebook Rails app

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.
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.
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.

Actual best pdf generator for Rails 3.1

I need a pdf generator for Rails 3.1 application.Which one can you suggest.
I've tried Prawn but it seems me quite not easy for a beginner like me while PdfKit gives me several errors :|
I don't know if it is the best fit for you, but I've heard good things about Wicked PDF/wkhtmltopdf.
I've tried both Wicked Pdf and PdfKit but in Development mode they are extremely slows :( Any other suggestions?
Another (maybe dummy) question: using PdfKit for example, I've seen that it make and open pdf file into web browser,but is there a way to download file into my desktop?

Resources