Instantiate Prawn PDF Document from document render - ruby-on-rails

I'm using PrawnPDF to create a PDF file and then using CombinePDF to append other files and render out the PDF for download. But I need to add anchors from the table content to the files that are appended afterwards so I want to be able to re-instantiate a Prawn::Document from the final rendered content, is there any way to do this? Or maybe someone can guide me to a better solution than the one I have in mind?

Related

Why does an Action Text attachment render out an "action-text-attachment" tag when rendered as HTML?

I understand that Action Text attachments are store in the DB in a compressed form that appears as an "action-text-attachment" tag. However when rendered using to_trix_html this tag is not rendered as I suppose it would mess with Trix's internal model.
I cannot understand why this tag is required when Rich Text is rendered as HTML (for example in a show action). I'd really appreciate if someone could explain why this has been designed this way.
its need to be there as an identifier and its saved like that inside the database
the tag contain 5 attributes content-type
url
filename
filesize and sgid
sgid is Signed Global IDs its unique to each file the function is as an anti-tamper and identifier about the attached file
as for the .to_trix_html giving different tag yes its need to be like that
because we want different way to handle the attachment inside the trix editor and when it outside the trix editor.
and if you want to know more about how the attachments works in action_text you could check this blog post

Generate Text (.txt) file for Data displayed in GSP

I have a Grails app developed in 2.3.6
There's a GSP file with HTML and CSS elements in it, and that displays data in multiple tables with headers.
I want this data to be saved into a text file and save it. So basically what i want to do is, there will be a Export button in this GSP page, and when user clicks on it, it will download the text file with all the data from that GSP.
What i tried so far?
def textFile = {
response.setHeader('Content-Disposition', 'Attachment;Filename="textFile.txt"')
render view: 'textFile', contentType: 'text/plain'
}
The problem with above is, it saves not just data, but also HTML & CSS elements.
I don't want any HTML or CSS in the text file. Only data from GSP is needed.
Is there a simple way of doing it.
the answer is simple - you need another view withouth the html and css parts.
The rest of your code looks good. But Grails itself does not convert your view, it just sends the content type to the browser and the browser tries to diesplay the data according to the content type.
If you don't want to write a new view (in most cases, writing the new view is dead simple), you could write your own converter (something which strips the HTML and CSS from your file) by creating an afterView-Filter: http://grails.github.io/grails-doc/2.4.0/guide/single.html#filters
Hope that helps

How export render view to HTML file

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

Capture HTML output from the view in RAILS and save to DB

Is there a way to capture the output of my view file after it is rendered?
I basically want to save the full HTML output into a database after the page renders.
You could use render_to_string, then stick it in the db and send the string containing the rendering to the browser. See RoR render_to_string doc.
What I ended up using is the following:
after_filter :save_if_necessary
and what I stored was
self.response.body

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