PDFkit doesn't display pictures in PDF

前端 未结 2 1046
失恋的感觉
失恋的感觉 2021-01-18 04:06

Rails 2, PDFkit 0.5.0

Im generating a PDF from a View in Rails 2 with PDFkit and everything works fine. The only thing which doesn\'t work is displaying pictures in

相关标签:
2条回答
  • 2021-01-18 04:45

    Instead of putting the full path each time, you can add a base tag to the head section.

    <base href="http://mydomain.com" target="_blank" />
    
    0 讨论(0)
  • 2021-01-18 05:02

    Because of the way that wkhtmltopdf works you need to specify the full path to any assets (JS, CSS, images etc), including the domain name.

    This won't work:

    <img src="/images/foo.png" />
    

    This will:

    <img src="http://example.com/images/foo.png" />
    

    One workaround is to set an explicit asset host, even if it's the same server as your app is running on (see the AssetTagHelper documentation for details). Another would be to specify the hostname in the image_tag.

    0 讨论(0)
提交回复
热议问题