Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 rails 3将pdf图像从html转换为pdf_Ruby On Rails 3_Image_Wicked Pdf - Fatal编程技术网

Ruby on rails 3 rails 3将pdf图像从html转换为pdf

Ruby on rails 3 rails 3将pdf图像从html转换为pdf,ruby-on-rails-3,image,wicked-pdf,Ruby On Rails 3,Image,Wicked Pdf,我在以pdf和html格式显示图像时遇到了一个问题 基本上,我想要的是使我的html视图能够以pdf格式下载。因此,我创建了一个部分的\u pdf\u view.html.haml,它(现在)看起来是这样的: 然后我简单地在download.html.haml和download.pdf.haml中呈现这部分内容。这个想法是html文件预览将要下载的pdf格式 有趣的是,这段代码将把图像很好地放在我的pdf中,而不是html中。在PDF中,需要指定完整的文件路径,但在html中,该路径将无法飞行。

我在以pdf和html格式显示图像时遇到了一个问题

基本上,我想要的是使我的html视图能够以pdf格式下载。因此,我创建了一个部分的
\u pdf\u view.html.haml
,它(现在)看起来是这样的:

然后我简单地在
download.html.haml
download.pdf.haml
中呈现这部分内容。这个想法是html文件预览将要下载的pdf格式

有趣的是,这段代码将把图像很好地放在我的pdf中,而不是html中。在PDF中,需要指定完整的文件路径,但在html中,该路径将无法飞行。如果我将路径更改为
“/vehicles/Toyota\u Echo1-1.jpg”
,则相反

除了为图像创建单独的文件或单独的代码块之外,还有其他解决方法吗


我正在使用的:rails 3.2.12、wkhtmltopdf 0.9.9、wicked_pdf 0.9.5

更改基于:格式创建的图像标记

- if params[:format] == 'pdf'
  = wicked_pdf_image_tag 'vehicles/Toyota_Echo1-1.jpg'
- else
  = image_tag 'vehicles/Toyota_Echo1-1.jpg'

更改基于:格式创建的图像标记

- if params[:format] == 'pdf'
  = wicked_pdf_image_tag 'vehicles/Toyota_Echo1-1.jpg'
- else
  = image_tag 'vehicles/Toyota_Echo1-1.jpg'

呵呵,谢谢。这很有魅力。有点傻,应该想到
if..else
语句的魔力和力量..呵呵,谢谢。这很有魅力。有点愚蠢,应该想到
if..else
语句的魔力和力量。。