#3 ✓hold
Hans-Jürgen Husel

render_to_string with rtex

Reported by Hans-Jürgen Husel | June 26th, 2008 @ 02:34 PM

There is no render_to_string with tex templates. It is not possible to do something like

a = render_to_string :template => 'projects/index.pdf.rtex'
send_data a, :type => 'application/pdf', :disposition => 'inline'

A possible solution is this new function in lib/rtex/framework/rails.rb

def render_to_string_with_rtex(options=nil, *args, &block)
  @internal_rtex_call = true
  result = render_to_string_without_rtex(options, *args, &block)
  @internal_rtex_call = nil
  if result.is_a?(String) && @template.template_format == :pdf
    options ||= {}
    ::RTeX::Document.new(result, options.merge(:processed => true)).to_pdf

But this is not enough. render_to_string and send_data both call render to do the real work and render is mapped to render_with_rtex. And render_with_rtex will always generate a PDF if the template format is pdf. So the first if statement in render_with_rtex must be modified.

Old condition

if result.is_a?(String) && @template.template_format == :pdf

New condition

if result.is_a?(String) && @template.template_format == :pdf && @internal_rtex_call != true && result[0,5] != '%PDF-'

The modified version of lib/rtex/framework/rails.rb is attached to this ticket.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

RTeX is a Ruby library (and web framework plugin) used to generate PDF documents on-the-fly using the LaTeX typesetting system.


Referenced by