WickedPDF和Wkhtmltopdf取决于文本挂在Rails中

出于某种原因,Rails似乎与WickedPDF挂在一起。如果我从/ tmp /目录中复制HTML文件并运行与Rails完全相同的命令,那么它将正常工作。我不明白为什么,但是有时候当我调整文字时,它会起作用,有时却不会。我还无法确切指出任何事情。

这是挂起时在Rails控制台中输出的底部外观:

  Rendered [obfuscated].html.erb (39815.3ms)
  Rendered [obfuscated].html.erb (41037.4ms)
  Rendering layouts/report_header.html.erb
  Rendered layouts/report_header.html.erb (12.0ms)
  Rendering layouts/report_footer.html.erb
  Rendered layouts/report_footer.html.erb (0.4ms)
[wicked_pdf]: ["/root/myapp/bin/wicked_pdf","--page-size","Letter","--margin-top","25","--margin-bottom","17","--margin-left","10","--margin-right","--header-html","file:////tmp/wicked_header_pdf20191205-6854-1k3i748.html","--footer-html","file:////tmp/wicked_footer_pdf20191205-6854-cc6ntg.html","file:////tmp/wicked_pdf20191205-6854-19958ts.html","/tmp/wicked_pdf_generated_file20191205-6854-133sa6i.pdf"]
^CCompleted 500 Internal Server Error in 295092ms (activeRecord: 6927.8ms)



RuntimeError (Failed to execute:
["/root/myapp/bin/wicked_pdf","/tmp/wicked_pdf_generated_file20191205-6854-133sa6i.pdf"]
Error: PDF could not be generated!
 Command Error: ):

app/controllers/[obfuscated]/reports_controller.rb:96:in `block (2 levels) in generate_pdf'
app/controllers/[obfuscated]reports_controller.rb:48:in `generate_pdf'
- Gracefully stopping,waiting for requests to finish
=== puma shutdown: 12/05/2019 10:13 ===
- Goodbye!
Exiting

以下是/root/myapp/bin/wickedpdf的内容:

#!/bin/bash
xvfb-run -- /usr/local/bin/wkhtmltopdf "$0"

正如您在上面看到的那样,我不得不从中删除它,因为它不起作用。它只是在那里挂了几分钟。我是在做错什么,还是在Rails上遇到某种奇怪的限制?

EDIT

我已经确认,通过注释掉exe_path文件中的config/initializers/wicked_pdf.rb,一切都会好起来的。我不太确定为什么要注释掉初始化程序才能使其正常工作。我在另一个线程中找到了。

这绝对不是永久性的解决方案,因为使用初始化器和xvfb-run的目的是在PDF中生成JavaScript图表。

EDIT

这是初始化程序:

# WickedPDF Global Configuration
#
# Use this to set up shared configuration options for your entire application.
# Any of the configuration options shown here can also be applied to single
# models by passing arguments to the `render :pdf` call.
#
# To learn more,check out the README:
#
# https://github.com/mileszs/wicked_pdf/blob/master/README.md

WickedPdf.config = {
  # Path to the wkhtmltopdf executable: This usually isn't needed if using
  # one of the wkhtmltopdf-binary family of gems.
  # exe_path: '/usr/local/bin/wkhtmltopdf',#   or
  # exe_path: Gem.bin_path('wkhtmltopdf-binary','wkhtmltopdf')
  exe_path: Rails.root.join("bin","wicked_pdf").to_s

  # Layout file to be used for all PDFs
  # (but can be overridden in `render :pdf` calls)
  # layout: 'pdf.html',}

youngerb 回答:WickedPDF和Wkhtmltopdf取决于文本挂在Rails中

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2965462.html

大家都在问