我正在使用令人敬畏的wicked_pdf gem来生成PDF,但我无法弄清楚如何更改页脚中的某些样式.
我有一个HAML模板的页脚大致看起来像这样:
!!!
%html
%head
%meta{:charset => "utf-8"}
= wicked_pdf_stylesheet_link_tag "pdf"
%body
.footer
%p Line 1
%p Line 2
%p Line 3
Run Code Online (Sandbox Code Playgroud)
还有一些款式:
.footer {
padding-top: 1em;
border-top: 1px solid #ccc;
}
Run Code Online (Sandbox Code Playgroud)
样式应用得很好,但由于页脚的高度很小,只有第一行可见.我试图通过CSS设置高度,但到目前为止没有骰子.如果我使用例如center,attributes或right直接提供文本设置页脚,换行符会导致页脚按预期"增长".
有关如何修改页脚高度的任何想法?
render :pdf => "file_name",
:layout => 'pdf.html.erb',
:template => 'transactions/show.pdf.erb',
:wkhtmltopdf => WICKED_PDF_BIN,
:show_as_html => true,
:layout => 'pdf.html.erb',
:header => {:html => { :template => 'shared/header.pdf.erb'}}
Run Code Online (Sandbox Code Playgroud)
PDF生成正常,遗憾的是我没有看到标题.我可以在主要布局中粘贴标题,它也可以正常工作.在我看来,上面的标题行没有被处理.文件名'header.pdf.erb'似乎并不重要.我可以将它指向一个不存在的文件,它不会抛出任何错误.
这是Mac OS,Rails 3.2.1,ruby 1.9
我wkhtmltopdf在Rails应用程序中使用v0.11.0 rc1 wicked_pdf(我知道wicked_pdf不支持新的命令行参数表示法,我正在使用我自己的gem分支).我认为不适合页面的内容应该自动溢出到下一个,但事实并非如此 - 我看到文本被切断,有时在一行中间.
我知道我可以使用布局我的页面page-break-after:always,但这看起来像脏硬编码,而且HTML来自ERB模板,因此并不总是很明显在哪里放置分页符.
可以做些什么来自动插入分页符吗?我错过了一些关于它如何工作的东西吗?
这是生成的命令行的样子
\"c:/program files (x86)/wkhtmltopdf/wkhtmltopdf.exe\"
--header-html \"file:///C:Users/bleak/AppData/Local/Temp/campaign_report.header.pdf_pdf_1580_0.html\"
--footer-html \"file:///C:/Users/bleak/AppData/Local/Temp/campaign_report.footer.pdf_pdf_1580_0.html\"
--margin-top 20 --margin-bottom 15 --margin-left 5 --margin-right 40
--page-size \"A4\"
page \"file:///C:/Users/bleak/AppData/Local/Temp/campaign_report_cover.pdf_pdf_1580_0.html\" --disable-javascript
toc --xsl-style-sheet \"c:/work/morizo/admoney/app/views/layouts/campaign_report.xsl\" - -
Run Code Online (Sandbox Code Playgroud) 是否可以访问主要内容体中的"topage"变量?
我知道你可以在页眉和页脚中做到这一点,但在这个特定的用例中,我需要在正文中添加一句话:
"本文件包含XX页".
对于我的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) 我正在使用'rails', '4.2.5'和wicked_pdfgem生成和下载PDF,但在Heroku上,它不包括使用wicked_pdf_stylesheet_link_tag标签的CSS .
Heroku错误日志:
ActionView::Template::Error (undefined method 'find_asset' for nil:NilClass)
Run Code Online (Sandbox Code Playgroud)
我在这里错过了任何配置吗?
在我的发票系统中,我想要一个备份功能,将所有发票一次性下载到一个 zip 文件中。该系统在 heroku 上运行 - 因此只能临时保存 pdf。
我已经安装了 rubyzip 和 wicked_pdf gem。
我在控制器中的当前代码:
def zip_all_bills
@bill = Bill.all
if @bill.count > 0
t = Tempfile.new("bill_tmp_#{Time.now}")
Zip::ZipOutputStream.open(t.path) do |z|
@bill.each do |bill|
@bills = bill
@customer = @bills.customer
@customer_name = @customer.name_company_id
t = WickedPdf.new.pdf_from_string(
render :template => '/bills/printing.html.erb',
:disposition => "attachment",
:margin => { :bottom => 23 },
:footer => { :html => { :template => 'pdf/footer.pdf.erb' } }
)
z.puts("invoice_#{bill.id}")
z.print IO.read(t.path)
end
end
send_file t.path, :type => "application/zip", …Run Code Online (Sandbox Code Playgroud) 环境: - Ruby - 1.9.3,Rails - 4.0.0
我使用wicked_pdf gem生成pdf.
为此,我在我的控制器中使用了以下代码: -
respond_to do |format|
format.html
format.pdf do
render :pdf => 'contractors_data',
:javascript_delay => 5000,
:disposition => 'attachment',
:template => 'tiles/templates/pdf/contractors.pdf.erb',
:header => { :right => 'Page [page] of [topage]' }
end
Run Code Online (Sandbox Code Playgroud)
在这个pdf中,我使用$.plotjavascript/jquery方法生成图形.所以我想等待pdf生成器等到$.plot没有响应,而不是在pdf上绘制图形.
我确信并确认javascript和jquery正在这个页面上工作,因为我使用了wicked_pdf_javascript_link_tag.
现在我:javascript_delay => 5000在respond_to格式选项中使用了.但是在正常工作的同时,它会产生错误:redirect_delay => 5000.
我也在cmd提示符下尝试这个.我在cmd上遇到类似于GUI工作的错误.
请回答好的解决方案.如果可能,请提供代码以供参考.
我正在生成PDF文件,我的链接如下所示:
<%= link_to 'Invoice', display_invoice_path(invoice.id), :format => :pdf %>
Run Code Online (Sandbox Code Playgroud)
当我点击它时,它将我带到/ display_invoice/123456789(这是一个HTML版本).
在控制器中,操作如下:
def display_invoice
if params[:invoice_number]
@invoice = ...
respond_to do |format|
format.html
format.pdf do
#render pdf: '123', # file name
render pdf: params[:invoice_number],
layout: 'layouts/application.pdf.erb'#, # layout used
#show_as_html: params[:debug].present? # allow debuging
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
并在路线:
get '/display_invoice/:invoice_number', to: 'invoices#display_invoice', :as => 'display_invoice'
Run Code Online (Sandbox Code Playgroud)
点击链接后,我想要在网址/display_invoice/INVOICE_NUMBER.pdf中显示 - 目前只有/ display_invoice/INVOICE_NUMBER.
如何用".pdf"后缀打开它?
谢谢.
我被困在 gem wicked_pdf 上。
在 wicked_pdf 文档中,据说我可以使用wicked_pdf_stylesheet_pack_tag并wicked_pdf_javascript_pack_tag包含来自 webpack 的样式表和 javascript,但没有任何效果。
这是来自控制器的代码:
format.pdf do
render template: "pdf_reports/show",
layout: "wicked_layout",
pdf: "report"
end
Run Code Online (Sandbox Code Playgroud)
这是布局中的代码:
<!DOCTYPE html>
<html>
<head>
<%= csrf_meta_tags %>
<%= wicked_pdf_javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= wicked_pdf_stylesheet_pack_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= wicked_pdf_stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<%= yield %>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是视图 pdf.erb 中的代码:
<h1 class="text-red-base">Test pdf</h1>
<h2 class="test-wicked">mldgmdjgfd</h2>
Run Code Online (Sandbox Code Playgroud)
它适用于 wicked_pdf_stylesheet_link_tag(test-wicked …
wicked-pdf ×10
pdf ×4
ruby ×4
wkhtmltopdf ×3
heroku ×2
flot ×1
javascript ×1
jquery ×1
rubyzip ×1
webpack ×1