首页 文章

wicked_pdf / wkhtmltopdf忽略Twitter Bootstrap css

提问于
浏览
3

我在使用来自以下来源的wicked_pdf / wkhtmltopdf在Ruby中生成pdf文档时遇到问题:

respond_to do |format|
  format.js
  format.pdf {
    render :pdf => pdf_filename(@invoice,false),
        :template => "invoices/generate",
        :layout => "document",
        :show_as_html => params[:debug]
  }
end
<style type='text/css'>/*!
  * Bootstrap v2.1.1
  ...
  */
    .clearfix{*zoom:1;}.clearfix:before,.clearfix:after{display:table;content:"";line-height:0;}
    .clearfix:after{clear:both;}
   /*.... and so on twitter bootstrap css is definitely included here ..... */
  </style>
</head>
<body>
<div class="container">

  <div class="row">
   <div id="left" class="span6">
     <!-- any text here -->
   </div>
   <div id="right" class="span6">
     <!-- any other text here -->
   </div>
  </div>
</div>
</body>
</html>

生成的PDF确实完全忽略了bootstraps css(意味着文档的整个布局被扰乱) . 但它完全加载到“风格”部分 .

当我尝试调试(generate.pdf?debug = 1)输出html时,我确实得到了正确的格式,因为我想要它(#left是页面左侧的一列,#right是右边的一列) .

wkhtmltopdf是否能够呈现twitter bootstrap css?

我使用最新的wicked_pdf gem和wkhtmltopdf 0.11.0 rc1 .

谢谢你对此的任何暗示!

2 回答

  • 0

    在您的布局中,您必须在CSS include标签中提供绝对路径或使用提供的帮助程序:

    wicked_pdf_stylesheet_link_tag 'application'
    
  • 4

    没关系 !!

    更新到最新的Bootstrap 2.2.1版修复了它(之前有2.1.1) . 不要问我为什么,但它一定是Bootstrap中的一个问题,我并不怀疑 .

相关问题