Ruby on Rails download pdf link - ruby-on-rails

I was wondering if there is a helper method, which can create a link to download a pdf file?
Thank you,

If you are looking to generate a PDF you will need to use something like Prawn or PDFKit. If you simply need to link to an existing PDF, just use link_to.

Related

Rails - Embed XML in PDF

I need to attach a XML file within a PDF file to be PDF/A3 compliant.
I am using rails and so far I had no issues to generate my PDF (using Prawn gem) and my XML separately but I do not know how to "combine" them.
Any ideas ?
Cheers
We have got similar problem and finally decided to follow the below approach
Generate the pdf file using wkhtmltopdf
Use pdftk (https://www.pdflabs.com/tools/pdftk-server/) to attach XML file with pdf

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

Generate pdf file on RoR

How would I be able to generate a pdf file when a button is clicked?
I have a user profile page and when I hit print, it should generate a pdf file containing the data of that user.
Thanks in advance.
There are a lot of difference PDF generation ruby libraries but I would recommend prawn. For example:
require 'prawn'
Prawn::Document.generate('hello.pdf') do |pdf|
pdf.text("Hello Prawn!")
end
Here is an excellent railscast that goes through the basics which should get you on the right track.

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

Resources