RAILS 5上的邪恶PDF忽略了bootstrap 4网格系统

时间:2018-10-11 06:43:59

标签: bootstrap-4 ruby-on-rails-5 wicked-pdf

我在RAILS 5系统中使用Wicked PDF,它可以工作-我在浏览器中得到一个PDF页面-但似乎它忽略了bootstrap 4网格系统,并且字体比预期的要小得多。

控制器代码

respond_to do |format|
  format.html
  format.pdf do
    render(pdf: "carrier_out_file",
           viewport_size: '1280x1024',
           template: 'carriers/order_now_as_pdf')
  end

查看代码

    <!doctype html>
    <html>
     <head>
     <meta charset='utf-8'/>
     <%= wicked_pdf_stylesheet_link_tag "https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" %>
     <%= wicked_pdf_javascript_include_tag "https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" %>
     <!--    <!-- Latest compiled and minified CSS -->
     <%=  wicked_pdf_javascript_include_tag "number_pages" %>

     </head>
      <body onload='number_pages'>

       <div id="content">
       ....

1 个答案:

答案 0 :(得分:1)

众所周知,wkpdftohtml使用旧版本的Qt WebKit,因此对基于Flexbox的网格系统的支持有限。一种选择是尝试将wkpdftohtml版本切换到最新的边缘版本 gem 'wkhtmltopdf-binary-edge'。另一个选择是重写HTML的一部分以使用基于表的系统,甚至恢复为基于浮动的网格系统。

有关更多信息,请参见:https://github.com/wkhtmltopdf/wkhtmltopdf/issues/1522

关于字体问题,您可以考虑将wicked_pdf.rb配置设置为包括disable_smart_shrinking: true,希望对您有所帮助!