How to add templates to rails-latex? - ruby-on-rails

I have recently started working with rails-latex on my Rails application. I would like to use a template when generating a pdf, but don't see any way to do so mentioned in the Github readme. Is there some sort of directory or method to adding LaTeX templates?

You're looking for the LatexToPdf.generate_pdf method.
It takes in two arguments:
latex content
a configuration hash
...and returns the pdf binary, which you'll need to write to a file.
Regarding the tex content, I have a directory with latex templates and would read in them using the File class, then pass in the content as an argument.
I suggest reading through the source to if you need to add configuration.
Note that under the hood, the rails-latex (LatexToPdf) gem still depends on a TeX extension (which you'll need to download) to generate the pdf. The default is pdflatex, and I've personally used xelatex.

Related

Nesting pdfs - Prawn

Some context: I have some html.erb files I use to create a pdf using WickedPdf that I can make their own pdf or I can render in another pdf, but I'm switching to Prawn because Prawn::Table is more predictable with page breaks than WickedPdf.
I've got a few POROs that inherit from a BasePdf class that handles all the boilerplate pdf stuff like our company's header, font size, and access to the #document etc. Is it possible to have a Prawn pdf PORO that can be a pdf on its own like the rest of my Prawn pdfs but also be included in another pdf in the middle of a page (as opposed to starting a new page).
Not sure about prawn, but here https://github.com/igorkasyanchuk/rails_pdf/blob/master/docs/report_4.png an example of PDF with a table.
Also on the second page of PDF, it will contain table header which is good.
We use extensively Prawn with plain Ruby or Rails to build complex business reports.
You can use all Ruby goodness to build reports like modules, class inheritance and custom methods. I thing this is one of Prawn's best part!
Each one of them can print/redner a part of a page or used as some kind of utility method. You actually right plain ruby that renders to pdf.
So you can have a base class with your company's lay out and custom modules which print some part of every specific report. Each module can take a hash with all required parameters for that module to render. This way you can also decouple reports from the rest of the app (that is db access etc.) and use or test them independently.

Forbid printing on generated PDFs (via prawn + combine_pdf)

I need to take a template (a pdf file) and add elements in it. I used prawn gem to generate a pdf with the elements and combine_pdf gem to combine this prawn pdf and the template. It works fine!
Now I need to add permissions to disable printing options. Prawn has an option for that but if I add it, I can't use combine_pdf to combine my template and this prawn pdf. Prawn can't start with an existing pdf (template system has been removed a long time ago...).
So I'm pretty stuck here, I looked everywhere in the web for a solution but couldn't find anything!
instead of combine_pdf gem you can use pdf-toolkit. it supports templating, combine pdf and set permissions. the manual can be found from here.

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

handling wiki links with markdown in ruby

I'm building a simple app with Rails using Markdown for storing content. My question is how to build internal [[wiki]] style links? Either by pre-processing before they get to markdown or some markdown derivative? I release I could probably preprocess using regex, but I'm guessing there are others with ready built solutions.
For example I know Instiki uses both markdown and [[wiki|Wiki]] links and I've looked but couldn't figure out how they're handling it.
Any tips?
If you are using the redcarpet gem you can either use a preprocessor or you can modifiy the generated HTML output.
Have a look at How to extend Redcarpet to support a media library. This article shows how to convert image references to custom HTML and also how to replace boilerplate identifiers with the actual content.
I guess both approaches could be adapted for your specific problem:
The renderer approach directly manipulates the generated HTML code from the markdown code. (This is more elegant as you are not messing with Markdown code)
The preprocess approach manipulates the code by using regular expressions (as you already mentioned) (This is more flexible, but also a little bit messy)

Pdf generation with latex in rails 3

is there a way to generate pdf documents from latex in rails 3? We've been using rtex (http://rtex.rubyforge.org/) in a rails 2 application, however it doesen't seem to work with rails 3.
Our rails application generates invoices using a latex template which we also use to create invoices by hand. Hence we would have to maintain two templates if we had to find a different solution for the pdf generation in rails 3.
Best I found to do such things was to create the .tex files on the server, then call a rake task that ran a "pdflatex" system command.
It is pretty poor in performances I guess, but it's designed for a single admin and works fine for me, on my local machine, and I can use the same latex templates for my letters
Old question, but I'm sure this'll help anyone coming to this page now.
Take a look at the rails-latex (LatexToPdf) gem.
The LatexToPdf.generate_pdf method takes in two arguments:
tex content
a configuration hash
...and returns the pdf binary, which you'll have to write to a file.
I suggest reading through the source to if you need to add configuration.
Note that under the hood, the rails-latex gem still depends on a TeX extension (which you'll need to download) to generate the pdf. The default is pdflatex, and I've personally used xelatex.
As of the writing of this answer, this gem is described as a renderer for rails 3; though it now includes support for rails 4 and 5.

Resources