Wicked pdf gem 未在 rails 生产服务器上创建正确的 pdf 数据

Wicked pdf gem not creating correct data in pdf on rails production server

我正在使用 Wicked pdf gem 创建 pdf。它在我的本地绝对工作正常。但在生产中它给出了严重的问题。 pdf 已生成,但尽管生成了单个页面,但它会生成 14-15 页,其中包含如下数据:

")),this.$.write(e),this.$.close()},find:function(e){return new CKEDITOR.dom.nodeList(this.$.querySelectorAll(e))},findOne:function(e){return(e=this.$.querySelector(e))?new CKEDITOR.dom.element(e):null},_getHtml5ShivFrag:function(){var e=this.getCustomData("html5ShivFrag");return e|| (e=this.$.createDocumentFragment(),CKEDITOR.tools.enableHtml5Elements(e,!0),this.setCustomData("html5ShivFrag",e)),e}}),CKEDITOR.dom.nodeList=function(e){this.$=e},CKEDITOR.dom.nodeList.prototype={count:function(){return this.$.length},getItem:function(e){return 0>e||e>=this.$.length?null:(e=this.$[e])?new CKEDITOR.dom.node(e):null}},CKEDITOR.dom.element=function(e,t){"string"==typeof e&&(e=(t?t.$:document).createElement(e)),CKEDITOR.dom.domObject.call(this,e)},CKEDITOR.dom.element.get=function(e){return(e="string"==typeof e? document.getElementById(e)||document.getElementsByName(e)[0]:e)&&(e.$?e:new CKEDITOR.dom.element(e))},CKEDITOR.dom.element.prototype=new CKEDITOR.dom.node,CKEDITOR.dom.element.createFromHtml=function(e,t){var n=new CKEDITOR.dom.element("div",t);return n.setHtml(e),n.getFirst().remove()},CKEDITOR.dom.element.setMarker=function(e,t,n,i){var r=t.getCustomData("list_marker_id")||t.setCustomData("list_marker_id",CKEDITOR.tools.getNextNumber()).getCustomData("list_marker_id"),o=t.getCustomData("list_marker_names")||t.setCustomData("list_marker_names",{}).getCustomData("list_marker_names");return e[r]=t,o[n]=1,t.setCustomData(n,i)},CKEDITOR.dom.element.clearAllMarkers=function(e){for(var t in e)CKEDITOR.dom.element.clearMarkers(e,e[t],1)},CKEDITOR.dom.element.clearMarkers=function(e,t,n){var i,r=t.getCustomData("list_marker_names"),o=t.getCustomData("list_marker_id");for(i in r)t.removeCustomData(i);t.removeCustomData("list_marker_names"),n&&(t.removeCustomData("list_marker_id"),delete e[o])},function(){function e(e,t){return-1<(" "+e+" ").replace(o," ").indexOf(" "+t+" ")}function t(e){var t=!0;return e.$.id||(e.$.id="cke_tmp_"+CKEDITOR.tools.getNextNumber(),t=!1),function(){t||e.removeAttribute("id")}}function n(e,t){var n=CKEDITOR.tools.escapeCss(e.$.id);return"#"+n+" "+t.split(/,\s*/).join(", #"+n+" ")}function i(e){for(var t=0,n=0,i=a[e].length;i>n;n++)t+=parseInt(this.getComputedStyle(a[e][n])||0,10)||0;return t}var r=document.createElement("_").classList,r="undefined"!=typeof r&&null!==String(r.add).match(/[Native code]/gi),o=/[\n\t\r]/g;CKEDITOR.tools.extend(CKEDITOR.dom.element.prototype, {type:CKEDITOR.NODE_ELEMENT,addClass:r?function(e){return this.$.classList.add(e),this}:function(t){var n=this.$.className;return n&&(e(n,t)||(n+=" "+t)),this.$.className=n||t,this},removeClass:r?function(e){var t=this.$;retur

整个14-15页都是这样的。

这是创建pdf的方法。

def generate_supplier_commission_pdf
  @start_date = params[:start_date].to_date.strftime('%d/%m/%Y')
  @end_date = params[:end_date].to_date.strftime('%d/%m/%Y')    
  if params[:sec_filter].present?
    sec_filter = true
  else
    sec_filter = false
  end

  results = get_report_results_by_type(params[:report_type], @start_date, @end_date, sec_filter)
  @results = JSON.parse(results)
  @type = params[:report_type].to_i

  respond_to do |format|
    format.html
    format.pdf do
      render  pdf:  "report",
        layout:              'pdf_layout',
        template:            'reports/generate_supplier_commission_pdf.html.erb',
        encoding:            'UTF8',
        print_media_type:    true,
        disposition:         'attachment',
        page_size:           'letter',
        orientation:         'landscape',
        lowquality:          'false',
        debug:                true
    end
  end    
end

诸如 wkhtml 路径之类的所有内容或任何可以在代码中处理的内容都可以。我看到的唯一区别是在日志中,即在这一行之后

***************WICKED***************
    Rendered reports/generate_supplier_commission_pdf.html.erb within layouts/pdf_layout (5.2ms)

服务器日志中不存在以下行。

"***************[\"/usr/bin/wkhtmltopdf\", \"-q\", \"--orientation\", \"landscape\", \"--page-size\", \"letter\", \"--encoding\", \"UTF8\", \"--lowquality\", \"--print-media-type\", \"file:///tmp/wicked_pdf20160903-24256-1v1ay70.html\", \"/tmp/wicked_pdf_generated_file20160903-24256-1da8k68.pdf\"]***************"

如果有人能指出这种情况下出了什么问题,我将不胜感激。提前致谢。

我通过在 config/environments/production.rb

中评论这一行设法解决了这个问题
# config.assets.js_compressor = :uglifier

并在原处添加这一行:

config.assets.compress = true