How can you make imagemagick only output the first page as a file (PNG) if the PDF has multiple pages?
You can select the page (or pages) you want by adding [NR] to the filename. Example:
convert a.pdf[0] a.png[0]
Or with multiple pages:
convert a.pdf[0-3] a.png[0-3]
Related
I have some predefined Pdf templates which include some dynamic variable like {{firstname}}, {{lastname}}, {{email}} etc. I want to replace these text with dynamic data in pdf without affecting the pdf formatting like font size and color.
I did not find any Ruby Gem to do this. Any help would be appreciated.
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?
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)
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
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