标签: wicked-pdf

WickedPDF缺少布局

我有一个像这样的控制器:

def show
    @professor = Professor.find(params[:id])
    respond_to do |format|
      format.html
      format.pdf do
        render :pdf => "file_name"
      end
    end
  end
Run Code Online (Sandbox Code Playgroud)

这样一个简单的视图:

<p>Professor: <%= @professor.first_name %></p>
<p>Email: <%= @professor.email if @professor.email %></p>
Run Code Online (Sandbox Code Playgroud)

我还有一个'application.html.erb'布局;

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><%= content_for?(:title) ? yield(:title) : "Myapp" %></title>
    <meta name="description" content="">
    <meta name="author" content="">
    <%= stylesheet_link_tag    "application", :media => "all" %>
    <%= javascript_include_tag "application" %>
    <%= csrf_meta_tags %>
    <%= yield(:head) %>
  </head>
  <body>
    <header class="navbar navbar-fixed-top">
      <nav …
Run Code Online (Sandbox Code Playgroud)

gem wkhtmltopdf ruby-on-rails-3 wicked-pdf

5
推荐指数
1
解决办法
4052
查看次数

wicked_pdf:ActionView :: Template :: Error(找不到文件“ twitter / bootstrap”

我们有一些PDF生成代码可以在开发环境中正常工作,但是Rails在尝试在生产环境中渲染时显示错误:

***************WICKED***************
  Rendered invoices/show.pdf.haml within layouts/invoices_pdf.pdf (8.8ms)
Completed 500 Internal Server Error in 73ms

ActionView::Template::Error (couldn't find file 'twitter/bootstrap'
Run Code Online (Sandbox Code Playgroud)

尝试将application.css资产包括在以下内容中失败:

!!!
%html
  %head
    %meta{"http-equiv"=>"content-type", :content=>"text/html; charset=utf-8"}
    = wicked_pdf_stylesheet_link_tag "application"

  %body
    .container
      = yield
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails sprockets asset-pipeline wicked-pdf

5
推荐指数
1
解决办法
1954
查看次数

发送带有附件的电子邮件

我有一封邮件,如下所示:

class Payments::LateNoticesMailer < AsyncMailer
  def notice(payment_id)
    @payment = PaymentDecorator.find(payment_id)
    @invoice = @payment.invoice
    template = "payments/invoices/#{@payment.made_with_type.downcase}/show"

    attachments["#{@payment.invoice_filename}.pdf"] =
      WickedPdf.new.pdf_from_string( render_to_string( pdf:      @payment.invoice_filename,
                                                       formats:  [:pdf],
                                                       template: template,
                                                       layout:   "layouts/pdf.html"))

    mail to:      @payment.payer_email,
         from:    '"RentingSmart" <no-reply@rentingsmart.com>',
         cc:      @payment.landlord_email,
         subject: "*** Your rent payment of #{@payment.amount_due} is overdue ***"
  end
end
Run Code Online (Sandbox Code Playgroud)

我使用SendGrid发送。这是我的问题,如果我通过Gmail打开电子邮件,则一切正常,电子邮件文本在那里,并且附件已附上。但是,如果我使用OSX的Mail.app或在iPhone上打开它,则会得到以下信息:

这是MIME格式的多部分消息...

有人有提示吗?我认为我正确地遵循了Rails指南。

这是我打的电话 Payments::LateNoticesMailer.notice(payment.id).deliver

ruby-on-rails actionmailer email-attachments sendgrid wicked-pdf

5
推荐指数
1
解决办法
2916
查看次数

WickedPDF头部渲染

我用户mac osx并通过wickedpdf尝试我的html文件到pdf文件.我想在我的pdf文件的每一页都放一个字符串,但是我有一个关于不渲染的标题的问题.

我的wickedpdf方法是,

format.pdf do
        render :pdf => '#{@examination.name}.pdf',
               :disposition => 'inline',
               :layout => 'examination_session_pdf.html.erb',
               :no_background => true,
               :header =>{:html =>{:template=>'shared/pdf/header.pdf.erb'}}
      end
Run Code Online (Sandbox Code Playgroud)

并且头文件只包含"hello"字符串或什么都没有.但是,每次我看到这个错误,

can't convert nil into String
Run Code Online (Sandbox Code Playgroud)

问题行是":header => {:html => {:template =>'shared/pdf/header.pdf.erb'".另外,我看不到有关在控制台上呈现标题页的任何日志.

我该如何解决?

wicked-pdf ruby-on-rails-3.2

5
推荐指数
1
解决办法
3047
查看次数

使用 wicked_pdf 生成 pdf 时进行分页

示例.erb.html

<p>Page 1</p1>

<p>Page 2</p2>
Run Code Online (Sandbox Code Playgroud)

因此,“第 1 页”之后的所有内容我都想打印在第 2 页上。

我怎样才能做到这一点?

SO中有一种解决方案,但对我不起作用。

例如,在 Prawn 的情况下,它有一个很好的功能叫做start_new_page

pdf-generation wicked-pdf ruby-on-rails-4

5
推荐指数
1
解决办法
6777
查看次数

运行时错误(无法执行)无法使用 wkhtmltopdf-binary 生成 wicked_pdf

我在 stackoverflow 上寻找其他解决方案,但似乎没有一个合适的答案。所以我会尽量做到具体。

我们在 Ruby 2.0 和 Rails 4 上的 Ruby on Rails 应用程序中使用 wicked_pdf (0.9.7) 和 wkhtmltopdf-binary (0.9.9.1)

当我们克隆存储库并启动服务器时,我们的代码在本地运行,但是当我们推送到生产(4 个节点)时,它偶尔会起作用。

这是我们得到的错误:

INFO: ***************WICKED***************
Rendered application/index.pdf.haml within layouts/pdf (209.2ms)
Rendered application/_header.pdf.haml within layouts/pdf (1.5ms)
Completed 500 Internal Server Error in 3406ms
FATAL: RuntimeError(Failed to execute:\n"/opt/application/releases/5405db831e02eb2987cc06b243333776ce9c34b8ab6db3e58e93f39c3f933621/vendor/bundle/ruby/2.0.0/bin/wkhtmltopdf" -q  --header-html "file:////tmp/wicked_header_pdf20131031-15836-12qkok6.html" --footer-right "[page] of [topage]" --footer-font-size 9    --margin-top 50  --encoding "UTF-8"   "file:////tmp/wicked_pdf20131031-15836-b874ab.html" "/tmp/wicked_pdf_generated_file20131031-15836-1ibji4k.pdf" \nError: PDF could not be generated!\n Command Error: /usr/bin/env: ruby: No such file or directory\n)
 vendor/bundle/ruby/2.0.0/gems/wicked_pdf-0.9.7/lib/wicked_pdf.rb:69:in `rescue in …
Run Code Online (Sandbox Code Playgroud)

ruby pdf ruby-on-rails wkhtmltopdf wicked-pdf

5
推荐指数
1
解决办法
3803
查看次数

Rails 4 wicked_pdf在模型中的服务器上保存pdf

我想在这样的模型中保存pdf:

def save_invoice
    pdf = WickedPdf.new.pdf_from_string(
        render_to_string(:pdf => "invoice",:template => 'documents/show.pdf.erb')
    )
    save_path = Rails.root.join('pdfs','filename.pdf')
    File.open(save_path, 'wb') do |file|
      file << pdf
    end
  end
Run Code Online (Sandbox Code Playgroud)

保存我的Payment对象后,我在payment.rb模型中完成了.

得到一个错误:

undefined method `render_to_string' for <Payment object>
Run Code Online (Sandbox Code Playgroud)

之前它在控制器中没有问题

def show
    @user = @payment.user
    #sprawdza czy faktura nalezy do danego uzytkownika
    # [nie mozna podejrzec po wpisaniu id dowolnej faktury]
    if current_user != @user
      flash[:error] = I18n.t 'errors.invoice_forbidden'
      redirect_to '/' and return
    end
    respond_to do |format|
      format.html do
        render :layout => false
      end
      format.pdf do
        render …
Run Code Online (Sandbox Code Playgroud)

pdf ruby-on-rails wicked-pdf

5
推荐指数
1
解决办法
4050
查看次数

邪恶的pdf没有渲染页眉/页脚

我正在使用wicked_pdfpdfhtml我的rails项目生成.它正在渲染,template但我无法打印header/footer部分.下面是我的代码,只打印template部分

render pdf: "pdf_name",
               layout: 'application',
               template: 'reports/show',
               formats: [:html],
               margin: { top: 10, bottom: 10, left: 10, right: 10 },
               disable_javascript: true,
               show_as_html: params[:debug],
               header: {
                 html: { template: 'shared/header' },
                 spacing: 10
               },
               footer: {
                 html: { template: 'shared/footer' },
                 spacing: 30,
                 line: true
               }
Run Code Online (Sandbox Code Playgroud)

如果我尝试使用WickedPdf.new.pdf_from_string render_to_string它显示Failed to load PDF document错误甚至简单WickedPdf.new.pdf_from_string('<html><body><h1>Hello There!</h1></body></html>')不起作用.

我试过用render_to_string_with_wicked_pdf, render_with_wicked_pdf但没有成功.我的Rails版本是3.2.19,wicked_pdf宝石版本1.1.0 …

html pdf-generation wkhtmltopdf ruby-on-rails-3 wicked-pdf

5
推荐指数
1
解决办法
1815
查看次数

如何从rest api返回pdf文件?

我在 ruby​​ on rails 应用程序中设置了一个 rest API,我现在需要生成一个 PDF 并从 get 请求中返回这个 PDF。我正在寻找有关如何实现此功能的一些建议。

我的一些要求如下: 我无法保存文件并向最终用户提供文件链接,因为文件中的数据可以随时更新。我将该应用程序用作微服务,因此没有可用于显示文件的前端。

所以这是我的想法,我希望能得到一些有关如何实现此功能的建议。

我想向应用程序中的特定端点发出获取请求。我希望返回一个 PDF 文件,然后我可以将其显示给最终用户。

我目前正在使用 WickedPdf gem 来生成一个临时的 PDF 文件,但我真的在为响应的外观而苦苦挣扎。

任何建议将不胜感激。

ruby api rest ruby-on-rails wicked-pdf

5
推荐指数
2
解决办法
2万
查看次数

无法在生产服务器中使用邪恶的pdf gem生成pdf

我正在使用邪恶的pdf生成pdf。它在本地服务器上工作正常,但是在生产模式下,我遇到以下错误:

执行失败.pdf“]错误:无法生成PDF!命令错误:

我在Alpine容器上运行我的应用程序。

ruby wkhtmltopdf wicked-pdf ruby-on-rails-5

5
推荐指数
0
解决办法
81
查看次数