Usage of html_safe attribute in Prawn PDF syntax - ruby-on-rails

I'm rendering the PDF data from the output of CK editor (What you see is what you get editor).
The output from that editor would be included with all the HTML, CSS tags in the content. For that I had used 'html_safe' attribute in the show page. But when I try to use the same attribute in the PDF prawn syntax its not working. Can someone please guide me how to get the pure content without all the HTML tags in Prawn PDF?
Thanks in advance.

After a long a Google search I finally got an answer which I wish to share with you.
As html_safe is the action view method in rails, It can not be used in ruby syntax of Prawn pdf.
So for that we can use:
ActionView::Base.full_sanitizer.sanitize(#string)
http://api.rubyonrails.org/classes/ActionView/Helpers/SanitizeHelper.html#method-i-strip_tags

Related

How to fill a fillable PDF Form with Rails?

i would like to fill a pdf with data from a form/database (like this https://www.youtube.com/watch?v=SJNCc2GwREA&t=190s but i didn't see any gem for that is this even possible ?
i dont want to create html page and generate a pdf like prawn or wicked PDF.
Do u have any ideas ?
It looks like this gem would do the trick - https://github.com/tcocca/active_pdftk
Let me know if this helps you

Generating pdf, getting text from ckeditor in rails admin

I've created a form with several fields, and many of them use ckeditor, I know that separately I can generate a pdf of each field, but I have normal fields (string, date), and I wanted them to be in pdf. I tried with the prawn but it does not render the ckeditor html tags. How to generate a pdf with these fields, those of the ckeditor rendering the html tags, and the others appearing normally?
Use the following command to process the following html tags present in the ckeditor for prawn to understand:
ActionView::Base.full_sanitizer.sanitize(#string)

How do I use sanitize to add links in plaintext?

So I want to be able to add links in the body of a post (and not show it as plaintext). However, I do not want to allow any other HTML tags. Right now I have:
sanitize #post.body, tags: %w(a), attributes: %w(href)
but this does not seem to work.
I've also tried
simple_format(#post.body).gsub(URI.regexp, '\0').html_safe
but that allows other HTML tags, which I do not want.
Any ideas how to fix this? Thanks!
Ruby/Rails will not just identify a link in a string because it has http or www somwhere in it. Assuming you are getting the body of #post via a form, you need to wrap the input in some kind of WYSIWYG editor such as tinymce. Then, if the WYSIWYG editor saves the serialized input:
click to see this link about google.ca
to the database, you can whitelist the <a> tag and href attribute so it actually generates a link
Ended up using the auto_link gem: auto_link(#comment.body)

Creating a text area that accepts html as input in ruby on rails

I am new to rails.I want to create a text area that will accepts html as input and can process them as well.
I dont know how to do this .I am using formtastic gem for my form.
Please help me out.
thanks in advance.
If you type any valid html on your text area, save, and then show the string with html_safe method, it should parse the html as usual.
Example: "<b>Hello bold</b>".html_safe should render Hello bold on the screen.

HTML with Prawn

Im trying to use prawn to generate a PDF of a log entry, then entries are stored in bbcode ([b]bold[/b] etc...) and is converted to html on display.
Is there any way to display the html in prawn?
It sounds like prawn-format might be what you're looking for, but you'll need to use an older version of prawn if you want to try it out.
You'll probably get the best results if you use a lexical analyser such as 'Syntax' by Jamis Buck (http://syntax.rubyforge.org/) and parse the interesting parts of the HTML chunk and render those parts to PDF.
You can use http://www.princexml.com/ to convert html docs to css, or use the princely plugin to render a pdf as one of the accepted formats of your view. See http://jimneath.org/2009/02/16/creating-pdf-documents-in-ruby-on-rails/
If you are wanting to use prawn directly I don't think there is a way to just use html directly to convert to pdf.

Resources