【问题标题】:ROR: Image not getting rendered in wicked_pdf's pdf错误:图像未在 wicked pdf pdf 中呈现
【发布时间】:2021-05-11 10:41:14
【问题描述】:

这里我不是在谈论带有 wicked_pdf_image_tag 的图像。那些运作良好。但是当我下载 pdf 时,它不会呈现图像。

它像一个小盒子一样渲染。 Click here

文件.html.haml

%img{src: "/assets/#{CONFIG[$skey]['main_logo_path']}"}

文件.pdf.erb

<%= wicked_pdf_image_tag(CONFIG[$skey]['main_logo_path'],alt: "Logo", class: "mt-md mb-md")  %>

使用的宝石:

wicked_pdf (2.1.0)
wkhtmltopdf-binary (0.12.6.5)

请帮忙!

【问题讨论】:

    标签: ruby-on-rails wkhtmltopdf wicked-pdf


    【解决方案1】:

    如果有人仍在寻找此问题的解决方案。答案如下:

    <%= image_tag wicked_pdf_asset_base64("logo.png") %>
    

    对存在于 assest/images 文件夹中的图像使用 image_tag wicked_pdf_asset_base64。

    【讨论】:

    • 在电子邮件中附加 pdf 时它对我有用。通常,我在浏览器中查看或下载 pdf 时使用的是 wicked_pdf_image_tag asset_url('logo.png'),但它在电子邮件附件中不起作用。
    【解决方案2】:

    我正在查看wicked_pdf_image_taghttps://github.com/mileszs/wicked_pdf/blob/2.1.0/lib/wicked_pdf/wicked_pdf_helper.rb#L21 的实现,它试图在/public/images/img 处选择图像,但您的图像位于/assets

    改用image_tag "file:///#{WickedPdf::WickedPdfHelper.root_path.join('assets', CONFIG[$skey]['main_logo_path'])}", alt: "Logo", class: "mt-md mb-md")

    【讨论】:

    • 现在它显示错误uninitialized constant ActionView::CompiledTemplates::WickedPdfHelper
    • 我更新了,需要使用限定名WickedPdf ::WickedPdfHelper
    • 它给了我错误uninitialized constant WickedPdfHelper。我有什么遗漏的吗?
    • 如果你照原样复制,::前面有无意的空格,我更新了
    • 我也试过不给空间。但是图像仍然没有显示。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-05
    • 2022-10-20
    • 2016-01-23
    • 2015-07-18
    • 1970-01-01
    • 2012-01-28
    • 2015-11-17
    相关资源
    最近更新 更多