PDFkit does not display pdf images

Rails 2, PDFkit 0.5.0

Im creating a PDF file from a view in Rails 2 using PDFkit and everything works fine. The only thing that does not work is the display of pdf images.

When I look at the view in the browser, the image is there, but it is not in the PDF file. In PDF, there is only a placeholder.

image_tag looks like this:

<%= image_tag('plus.gif') %> 

I also tried to implement it using a css file, but it does not work either.

Any ideas?

+7
source share
2 answers

Due to how wkhtmltopdf works, you need to specify the full path to any assets (JS, CSS, images, etc.), including the domain name.

This will not work:

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

This will:

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

The workaround is to install an explicit resource node, even if it runs on the same server your application is running on (see the AssetTagHelper documentation for details). Another would be to specify the host name in image_tag .

+13
source

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

 <base href="http://mydomain.com" target="_blank" /> 
0
source

All Articles