Ruby/Rails Javascript (flot) renderizar pdf con Wickedpdf

¿Wickedpdf representa gráficos de javascript?

Ruby 1.8.7

Rieles - 2.3.8

Mi código funciona bien, la vista sale bien: flot traza el gráfico de la manera que quiero ..., pero cuando miro el archivo pdf, está todo en blanco.

¿Alguien más se ha encontrado con un problema similar?

Controlador:

 def graph
 @now=Time.now

 @graph = [0,0] / some sort of dataset /

 pdf = render_to_string :pdf => "graphs", :orientation => 'Landscape', :font_size => 11
 save_path = Rails.root.join('pdfs', @now.to_date.to_s+'_graphs.pdf')

 File.open(save_path, 'wb') do |file|

 file << pdf
 end

Vista

<script language="javascript" type="text/javascript" src="/javascripts/jquery.js"></script>
<script language="javascript" type="text/javascript" src="/javascripts/jquery.flot.js"></script>
<script language="javascript" type="text/javascript" src="/javascripts/jquery.flot.navigate.js"></script>

<%= wicked_pdf_stylesheet_link_tag "pdf" -%>
<%= wicked_pdf_javascript_src_tag "jquery" %>
<%= wicked_pdf_javascript_src_tag "jquery.flot" %>
<%= wicked_pdf_javascript_src_tag "jquery.flot.navigate" %>
<script type="text/javascript">

$(function () {

var options = {
    lines: { show: true },
    points: { show: true },
    xaxis: { mode: "time",  timeformat: "%m/%y",   minTickSize: [1, "day"], tickSize: [1, "month"]}
    };

    var graph = <%= @graph.to_json %>;
    $.plot(placeholder,graph.data,options);
    }

  <div id="placeholder" style="width:1000;height:500px"></div>  

Ayudante:

    module WickedPdfHelper
  def wicked_pdf_stylesheet_link_tag(*sources)
    css_dir = Rails.root.join('public','stylesheets')
    sources.collect { |source|
      "<style type='text/css'>#{File.read(css_dir.join(source+'.css'))}</style>"
    }.join("\n").html_safe
  end

  def wicked_pdf_image_tag(img, options={})
    image_tag "file:///#{Rails.root.join('public', 'images', img)}", options
  end

  def wicked_pdf_javascript_src_tag(jsfile, options={})
    javascript_src_tag jsfile, options
  end

  def wicked_pdf_javascript_include_tag(*sources)
    sources.collect{ |source| wicked_pdf_javascript_src_tag(source, {}) }.join("\n").html_safe
  end

  module Assets
    def wicked_pdf_stylesheet_link_tag(*sources)
      sources.collect { |source|
        "<style type='text/css'>#{read_asset(source+".css")}</style>"
      }.join("\n").html_safe
    end

    def wicked_pdf_image_tag(img, options={})
      image_tag "file://#{asset_pathname(img).to_s}", options
    end

    def wicked_pdf_javascript_src_tag(jsfile, options={})
      javascript_include_tag jsfile, options
    end

    def wicked_pdf_javascript_include_tag(*sources)
      sources.collect { |source|
        "<script type='text/javascript'>#{read_asset(source+".js")}</script>"
      }.join("\n").html_safe
    end

    private

    def asset_pathname(source)
      if Rails.configuration.assets.compile == false
        File.join(Rails.public_path, asset_path(source))
      else
        Rails.application.assets.find_asset(source).pathname
      end
    end

    def read_asset(source)
      if Rails.configuration.assets.compile == false
        IO.read(asset_pathname(source))
      else
        Rails.application.assets.find_asset(source).to_s
      end
    end
  end
  end

preguntado el 04 de julio de 12 a las 01:07

1 Respuestas

Probablemente no tenga un intérprete js completo. Intenta renderizar un jpg. Gruff hará esto, pero no se ve tan bien, especialmente para las gráficas de tiempo.

Respondido 10 Jul 12, 08:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.