Can wicked_pdf or wkhtmltopdf generate a protected pdf? - ruby-on-rails

So, I have wicked_pdf up and running, now I am wondering if I can password protect the pdf being generated so it is not easily editable. Is this possible? Perhaps a better question is can wkhtmltopdf generate a protected pdf?
If not, is there a great rails pdf gem or similar that can take an existing pdf and protect it?
Thanks!

Let me check the usage for wkhtmltopdf (v0.10.0 rc2).
Nope, at least not according to it's usage dump. And wicked_pdf just wraps wkhtmltopdf, so you're out of luck.
There are any number of OSS PDF projects floating around out there that could encrypt your PDF output in a second pass.

Related

Is there an upgrade gem to prawn to covert odf (.odt)?

I've been using the awesome prawn gem in my last few project, but this time I have to covert a odt file (in odf format) to PDF.
I know that there are many gems that can do this, for example docsplit and others, but since I am already using prawn to generate other PDFs in the same app I would really like to know if I could get a way without adding yet another pdf creator type gem...
Does anyone know any resources that could help? Or at least a (really) simple gem that coverts odt to PDF (without possibly having to install anything)?
Thanks in advance...
No, Prawn can't do that. Prawn is just a library for programmatically generating PDF documents.
Best way would be using LibreOffice in a head-less fashion to convert ODF files into PDF.

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

Rails: How to print model's details to A4 PDF page?

In my Job Management application I would like to prepare an A4 page receipt to customer.
Thus, I need to print somehow Job model's details to a single A4 PDF page.
Are the any built-in tools in Rails for this purpose ?
If no, what would be the best way to go ?
Basically there is two options: (any PDF creation requires a gem - no default PDF creation for rails).
Create a pure PDF using Prawn, You have to do all the formatting using the Prawn API
Create a HTML version of your receipt and convert it to PDF, One of the better gems to do this is PDFkit. which uses a web-kit powered browser engine.
They both work good, For one page documents I usually use PDFkit to convert HTML and for larger documents that are going have lots of pages I use Prawn because it gives you a smaller file size and handles multiple pages better.
My suggestion would be to make a HTML receipt and display it on the screen and give the user an option to save a PDF version using PDFkit.
EDIT: windows install. (not tested - windows and I have parted company.)
Download the windows installer for wkhtmltopdf: win-wkhtmltopdf
now create an initializer file, e.g. config/intializers/pdfkit_config.rb
in pdfkit_config.rb set the absolute path to wkhtmltopdf on your local machine:
PDFKit.configure do |config|
if RAILS_ENV == 'development'
config.wkhtmltopdf = 'D:\path\to\your\wkhtmltopdf' #this bit i'm not sure about
else
config.wkhtmltopdf = "#{RAILS_ROOT}/lib/wkhtmltopdf"
end
end
for your production ENV you can actually just have a copy of wkhtmltopdf in you repo, a unix version of course. (remember to chmod +x it before you git add it)
Theres a gem called prawn that helps with PDF generation. Here is a tutorial using it for some ideas:
http://railstips.org/blog/archives/2008/10/13/how-to-generate-pdfs-in-rails-with-prawn/

Prawn gem: How to create the .pdf from an *existing* file (.xls)

Can anybody show me (maybe copy/paste a simple code example) how to create the .pdf file from an existing (.xls) file, using the Prawn gem? (Basically, I'd need the command that "opens" the existing file.)
(I'm asking because the Prawn documentation (http://prawn.majesticseacreature.com/docs/) seems to be gone since quite a while - it's not even usable via Google cache...)
Thanks a lot for any help with this!
Tom
I'd suggest that you break the problem down.
Can you read xls with Ruby? Possibly, but it's flaky at best. However, you can easily read csv, and xls exports nicely to that format.
Can you write a 'table' of values to a prawn pdf? Yes
So, (almost) all you need is a little program that can parse a csv file into a prawn-friendly table-structure and then hand it off to Prawn for generation.
Turns out the Prawn gem cannot handle existing files...
Prawn can be used to render content on top of a PDF. You're talking about .xls, a completely different format.

Resources