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.
Related
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
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
Essentially I'm trying to implement a way so that users can edit slim that is stored in the database.
For example they would use the form to create a new page and insert the html for that page in a text field which would be saved in the database. I want to allow them to edit that page in slim. By the way the html stored is slim not plain html.
If I store slim in the database how do I get rails to render the html properly on the client side in production? So in other words would rails automatically do this since the view is being render like so:
views/page/view.html.slim
page.header
page.content
page.footer
or would I have to figure out a way to convert on the fly? I might be making this more complicated then I should but I'm new to this
If I understand you correctly you want to convert the slim to Html and output that in your views.
This is directly from slims doc. This is how it processes slim files and outputs it.
Tilt.new['template.slim'].render(scope)
Slim::Template.new('template.slim', optional_option_hash).render(scope)
Slim::Template.new(optional_option_hash) { source }.render(scope)
so in short
Slim::Template.new(page/view.html.slim).render
put that in a module to make it prettier and I think you're good. You may want to use rails path helper to get the direct link for the view. You may also want to consider figuring out a way to catch the errors in indentation so that your output doesn't bug out in production. Some kind of validation that prevents it from saving if not properly formatted should help.
I've got an existing HTML page that I have transcribed into scalajs-react scalatags in a ReactComponentB object, but the output is slightly different from the original HTML. Is there a way I can render out the HTML from the ReactComponentB so that I can compare it with my original HTML?
Sounds like React.renderToStaticMarkup() is what you're looking for.
How do I export all my rendered view to an html file? I want to save the view to a file rather than display it to the screen. Is this possible?
Instead of render call render_to_string and save the returned string into an file.
(see: http://apidock.com/rails/AbstractController/Rendering/render_to_string)
This sort of sounds like Dynamic Page Caching. There is a Railscasts on this topic. It is rather dated, unless you subscribe (there is a revised version with subscription).
http://railscasts.com/episodes/169-dynamic-page-caching