Rails Prawn Pdf gem suggestions needed - ruby-on-rails

I have been using wkhtmltoppdf in my application for generating pdf's.Since now I have observed it's not supporting files over 1000+ pages. I am interested to give try to prawn pdf, as it seems faster than other gems.
Could anyone tell, anyway we have in prawn gem to convert html to pdf?
If not like pdfkit andd wkhtmltopdf do, then any way to debug pdf generated by prawn for styling like we have way for wkhtmltopdf?

Could anyone tell, anyway we have in prawn gem to convert html to pdf?
Prawn is not a html to pdf generator, they point this at official site http://prawnpdf.org/api-docs/2.0/
"One thing Prawn is not, and will never be, is an HTML to PDF
generator. For those needs, consider looking into FlyingSaucer via
JRuby, or one of the webkit based tools, like Wicked or PDFKit. We do
have basic support for inline styling but it is limited to a very
small subset of functionality and is not suitable for rendering rich
HTML documents."
If not like pdfkit andd wkhtmltopdf do, then any way to debug pdf
generated by prawn for styling like we have way for wkhtmltopdf?
To debug Prawn generated pdf I think the easiest way is to generate a new pdf or make your controller respond with your pdf:
Prawn::Document.generate("path/to/pdf/example.pdf") do
pdf.text "Hello"
end
Controller respond the pdf:
format.pdf do
pdf = PdfGenerator.new(#invoice)
send_data pdf.render,
filename: "pdf_test",
type: 'application/pdf',
disposition: 'inline'
end
And refresh your page every time that you make a change.
To test your generated pdf, pdf-inspector gem is good.
These tutorials may help you:
https://grzegorowski.com/using-prawn-gem-for-generating-pdfs-in-rails-5/
https://rubyplus.com/articles/3891-PDFs-with-Prawn-in-Rails-5

Related

Forbid printing on generated PDFs (via prawn + combine_pdf)

I need to take a template (a pdf file) and add elements in it. I used prawn gem to generate a pdf with the elements and combine_pdf gem to combine this prawn pdf and the template. It works fine!
Now I need to add permissions to disable printing options. Prawn has an option for that but if I add it, I can't use combine_pdf to combine my template and this prawn pdf. Prawn can't start with an existing pdf (template system has been removed a long time ago...).
So I'm pretty stuck here, I looked everywhere in the web for a solution but couldn't find anything!
instead of combine_pdf gem you can use pdf-toolkit. it supports templating, combine pdf and set permissions. the manual can be found from here.

How do I add to existing PDF template with Wicked_PDF?

I have an existing PDF template that I'd like to fill out within a Rails application and save to a new PDF. Is there a way to do this using Wicked PDF or is there another tool or gem better suited to the task?
Wicked PDF is used for converting HTML to PDF. Not for filling out existing PDF forms or templates.
A quick google search returned HexaPDF or Origami as potential options for editing PDF files with Ruby.
wicked pdf is not for filling existing pre created pdf. you may need to look at prawn, prawn-form for that. Its DSL based pdf library for ruby and ruby on rails.
A quick search got me into this issue.
please take a look, wicked pdf issues github

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!

generate PDF from html document in Rails

anyone knows about some gem or app in rails to create pdf docs from html5 and css3 with some client side programming??
Thanks ;)
Thank you for your responses. I need this for a possible project wich will use jquery for box positioning and then, will export the resultant html to pdf. Roughly, ¿is this possible?
PDFKit and WickedPDF for Client side generation, as suggested by Raphael and jcadam
Flying Saucer with JRuby: http://xhtmlrenderer.java.net
Personally, I got more accomplished by using Prawn PDF generator. It's capabilities are much more extensive, IMHO.
Prawn for Ruby PDF generation: https://github.com/prawnpdf/prawn
WickedPDF: https://github.com/mileszs/wicked_pdf
I'm using it now and rather like it:
"Wicked PDF uses the shell utility wkhtmltopdf to serve a PDF file to a user from HTML. In other words, rather than dealing with a PDF generation DSL of some sort, you simply write an HTML view as you would normally, then let Wicked take care of the hard stuff."
If you need more control, also check out Prawn: https://github.com/prawnpdf/prawn. Though Prawn is not an HTML -> PDF converter and is more useful for creating PDFs from scratch.
I'm using both Prawn and WickedPDF on my current project: WickedPDF to generate 'printable' versions of web pages, and Prawn for generating detailed PDF reports.
I believe the PDFKit gem may be what you're looking for.
https://github.com/pdfkit/PDFKit
There's also IMGKit if you want images instead of PDFs.
https://github.com/csquared/IMGKit

Prawnto won't display pdf inline

I'm trying to use prawn and prawnto (both installed via gems) in order to generate pdf's for my app. I want the pdf to display in the browser, but it won't, it automatically downloads instead.
I have the following prawnto options in my controller:
prawnto :inline => true, :filename => "results.pdf", :prawn => {:top_margin => 75}
The filename and margin arguments both work, but the document won't display inline. I'm pretty sure this is a prawnto issue and not a prawn issue. The prawn gem seems pretty old. Someone has created a new gem (prawnto_2) to update for rails 3.1, but I'm still using rails 3.0.7.
Has anyone else had this issue? How can I get prawnto to show the pdf inline (ideally in a new tab or window)?
The :inline option uses the Content-Disposition HTTP header, which relies on a browser plugin to interpret the content.
This means that the results can vary depending on the browser/OS combination you're using, Linux especially doesn't seem very good at handling this.
#benoit
Linux / Mozilla and Opera both open all pdfs on websites I visit - except on my site using this method. I get "open in application" or "save" as the only choices - it will not render inline.

Resources