我用
<%= wicked_pdf_stylesheet_link_tag "pdf" %>
它在html中显示以下输出
<link href="/stylesheets/pdf.css?1302860585" media="screen" rel="stylesheet" type="text/css">
<link href="file:///home/likewise-open/NEXTBRIDGE/nazar.hussain/osd/development/atlantis/public/stylesheets/pdf" media="screen" rel="stylesheet" type="text/css">
但是在创建pdf时它没有任何风格.如果我将所有css从文件复制到页面的标题,它包括所有样式.问题是什么以及如何解决.
ruby-on-rails ruby-on-rails-plugins ruby-on-rails-3 wicked-pdf
这是我使用Wicked_pdf将我的html.erb页面转换为的结果pdf.
问题:看起来table的tr已分裂成两页.
我没有成功的尝试:
table,tr,td,th,tbody,thead,tfoot {page-break-inside:avoid!important; }
另一种选择:将每个tr放在自己的tbody中,然后将peage break css规则应用于tbody.表支持多个tbodys.一点额外的标记,但对我来说效果不错.
我正在使用Ruby on Rails 4.2.6,Wicked_pdf最新版本,bootstrap.
问:我怎样才能让table的tr不分割成两页.
我正在使用Ubuntu 11.04在Ruby on Rails中开发应用程序.在应用程序中,我需要生成pdf文档.所以我使用的是wicked_pdf和wkhtmltopdf-binary gems.
在我的系统的开发环境中,一切正常.但是一旦我使用Phusion Passenger在CentOS 5.6上部署应用程序,当我尝试动态生成pdfs时,它会给我以下错误:
RuntimeError(wkhtmltopdf的位置未知)
我使用的是Ruby1.9.2.p136 Rails 3.1.1
任何帮助将不胜感激....谢谢.
的Gemfile
gem "wicked_pdf"
gem "wkhtmltopdf-binary"
Run Code Online (Sandbox Code Playgroud)
错误:
RuntimeError in CarsController#show
Failed to execute:
/usr/bin/wkhtmltopdf --print-media-type -q - -
Error: PDF could not be generated!
Rails.root: /u/apps/zeepauto/autozeep_update
Run Code Online (Sandbox Code Playgroud)
cars_controller
def show
@class_showcar = true
@class_admin = true
@car = Car.find(params[:id])
@search = Car.search(params[:search])
@cars_see_special = Car.where(:special => "1").order('rand()').limit(3)
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @car }
format.pdf do
render :pdf => "#{@car.carname.name}",
:print_media_type => true
end
end
end
Run Code Online (Sandbox Code Playgroud)
show.html.erb
<p class="show_links"><%= link_to url_for(request.params.merge(:format => :pdf)) do %>
<%= …Run Code Online (Sandbox Code Playgroud) 当我尝试提交表单时,我收到此错误(PDF应该使用Wicked PDF gem生成,表单提交时) -
NameError in PostsController#create
uninitialized constant Mime::PDF
Rails.root: /Users/fkhalid2008/littlechits
Application Trace | Framework Trace | Full Trace
app/controllers/posts_controller.rb:42:in `create'
app/controllers/posts_controller.rb:39:in `create'
Run Code Online (Sandbox Code Playgroud)
我该如何解决???相关代码如下.
POSTS控制器
def create
@post = Post.new(params[:post])
@post.user = current_user
respond_to do |format|
if verify_recaptcha && @post.save
format.html { redirect_to :action=> "index"}
format.pdf do
render :pdf => "file_name"
end
else
format.html { render :action => "new" }
format.json { render :json => @post.errors, :status => :unprocessable_entity }
end
end
end
Run Code Online (Sandbox Code Playgroud)
配置/初始化/ WICKED_PDF.RB
# config/initializers/wicked_pdf.rb
WickedPdf.config = …Run Code Online (Sandbox Code Playgroud) 嗨我使用wicked_pdf生成图像后我保存图像生成pdf并使用此标签显示图像这样
<%= wicked_pdf_image_tag(@image.snap.url(:original)) unless @image.blank? %>
Run Code Online (Sandbox Code Playgroud)
它给了我这个未知的错误
ActionView::Template::Error (undefined method `pathname' for nil:NilClass):
Run Code Online (Sandbox Code Playgroud)
而puts @ image.inspect给了我正确的路径
"/system/snaps/7/original/flake.jpg"
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮忙
谢谢....
试图使用Wicked PDF.
我在控制器中有这个代码
def pdf
pdf = WickedPdf.new.pdf_from_string(
render_to_string(
pdf: 'filename.pdf',
template: '/pages/poa.html.slim',
layout: '/layouts/pdf'),
header: {
content: render_to_string({
template: '/pdfs/poa_header.html.slim',
layout: '/layouts/pdf'
})
})
save_path = [Rails.root, '/public/pdf/', 'filename.pdf'].join
File.open(save_path, 'wb') do |file | file << pdf
end
end
Run Code Online (Sandbox Code Playgroud)
我在尝试执行上面的操作时收到此错误消息
RuntimeError (Failed to execute:
Error: "\xFE" from ASCII-8BIT to UTF-8):
Run Code Online (Sandbox Code Playgroud)
我已经尝试清空我正在渲染的模板和布局的内容但仍然出错.
我一直在使用Wicked PDF gem生成pdf.它一直很好用.
但是,我遇到了需要附加并且在第一页上看到一个大页脚而不是其他页面的情况.为了实现这一点,我在这篇文章中建议的pdf正文底部添加了一个边距,这使页脚足够可见.
这会产生不良副作用,因为它会为所有页面增加底部边距,而不仅仅是第一页.我希望只在第一页添加保证金,并保持其余页面不变.
我试图通过使用javascript和css来实现这一目标,但到目前为止还没有运气.
提前致谢
我正在尝试使用wicked_pdf(版本1.1)和wkhtmltopdf-binary宝石从html页面创建pdf .我的html页面包含一个日历表情符号,无论我使用什么字体,它都能在浏览器中很好地显示
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv='content-type' content='text/html; charset=utf-8' />
<style>
unicode {
font-family: 'OpenSansEmoji', sans-serif;
}
@font-face {
font-family: 'OpenSansEmoji';
src: url(data:font/truetype;charset=utf-8;base64,<-- encoded_font_base64_string-->) format('truetype');
}
</style>
</head>
<body>
<div><unicode>📅</unicode></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用WickedPdf.new.pdf_from_html_filerails控制台中gem 的方法生成PDF时,
File.open(File.expand_path('~/<--pdf_filename-->.pdf'), 'wb+') {|f| f.write WickedPdf.new.pdf_from_html_file('<--absolute_path_of_html_file-->')}
Run Code Online (Sandbox Code Playgroud)
我得到以下结果:
如您所见,第一个日历图标已正确显示,但是显示第二个字符,我们不知道它来自何处.
我已经通过UTF-8和UTF-16编码进行了调查,并且按照相关帖子stackoverflow_emoji_wkhtmltopdf的建议调查了代理对,并查看了这个问题wkhtmltopdf_git_issue,但仍然不能使这个角色消失!
如果您有任何线索,那就非常受欢迎了.
在此先感谢您的帮助!
编辑
根据Eric Duminil和petkov.np的评论,我可以确认 - 上面的代码在Linux上适用于我.这似乎是Linux vs MacOS问题.任何人都可以建议MacOS绑定中的核心问题以及是否可以修复它?
对于我的rails 4应用程序,我想将html和Css转换为pdf文件.我使用wkhtmltopdf和wicked_pdf gem如果我使用邪恶的帮助器它不显示css但它只渲染文本
在我的控制器中我有:
respond_to do |format|
format.html
format.pdf do
render :pdf => "#{@card.name}",
:template => 'cards/show.html.slim',
:page_size => "A4",
:disposition => 'attachment'
Run Code Online (Sandbox Code Playgroud)
并在show.html.slim
= link_to "Download PDF", :action => "show", :format => :pdf
Run Code Online (Sandbox Code Playgroud)
aplication.html.erb
<%= wicked_pdf_stylesheet_link_tag "pdf" -%>
<%= wicked_pdf_stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= wicked_pdf_javascript_include_tag "application", "data-turbolinks-track" => true %>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
Run Code Online (Sandbox Code Playgroud) wicked-pdf ×10
wkhtmltopdf ×5
ruby ×2
centos ×1
css ×1
javascript ×1
page-break ×1
pdf ×1
unicode ×1