gpt4 book ai didi

ruby-on-rails - 邪恶的 PDF 标题没有显示

转载 作者:行者123 更新时间:2023-12-04 03:50:55 25 4
gpt4 key购买 nike

在检查 Rails Gem 存储库中是否存在类似问题以及 Stack Overflow 之后,我找不到问题的答案。

我正在尝试在 Rails Controller 中使用 wicked_pdf 渲染 pdf,但无论我做什么或我遵循的类似问题的推荐解决方案,标题都没有显示。

首先,这里是开发控制台输出:

***************WICKED***************
Rendering biddings/show.pdf.html.haml within layouts/pdf
Rendered biddings/show.pdf.html.haml within layouts/pdf (0.7ms)
Rendering biddings/header_pdf.html.haml within layouts/pdf_header
Rendered biddings/header_pdf.html.haml within layouts/pdf_header (1.9ms)
"***************[\"/home/tommy/.rvm/gems/ruby-
2.5.1@igalbids/bin/wkhtmltopdf\", \"-q\", \"--encoding\", \"UTF-8\",
\"--javascript-delay\", \"500\",
\"--disable-internal-links\", \"--disable-external-links\",
\"--orientation\", \"Portrait\", \"--margin-top\",
\"50\", \"--margin-bottom\", \"25\", \"--header-html\",
\"file:////tmp/wicked_header_pdf20180801-27285-b8y5sg.html\",
\"--footer-right\", \"Página [page] de [topage]\",
\"file:////tmp/wicked_pdf20180801-27285-1jfgdd7.html\",
\"/tmp/wicked_pdf_generated_file20180801-27285-1bkrvhx.pdf\"]***************"
Rendering text template
Rendered text template (0.1ms)
Sent data Licitación_2524.pdf (0.6ms)
Completed 200 OK in 2334ms (Views: 0.5ms | ActiveRecord: 64.4ms)

如您所见,标题布局及其内容都被渲染和处理,但是它们并没有生成最终的输出 PDF,我不知道为什么!看:

PDF Output

所以,这是我的 Controller 代码:
class Api::V1::Biddings::PdfBiddingsController < PdfController
# JWT Authentication enforced
before_action :authenticate_user!

# GET /biddings/:id/pdf
def show
@bidding = scoped_collection.find(params[:id])

authorize [:biddings, :pdf, @bidding]
respond_to do |format|
format.pdf do
render(
pdf: "#{Bidding.model_name.human}_#{@bidding.code}",
disposition: "inline",
orientation: "Portrait",
template: 'biddings/show.pdf.html.haml',
header: {
html: {
template: "biddings/header_pdf.html.haml",
handlers: [:haml],
layout: "pdf_header",
formats: [:haml, :html]
}
},
footer: {
html: {
handlers: [:haml],
layout: "pdf",
formats: [:haml, :html],
encoding: 'UTF-8'
},
right: "#{I18n.t('pdf.page')} [page] #{I18n.t('pdf.of')} [topage]"
},
margin: { :top => 50, :bottom => 25},
handlers: [:haml],
layout: "pdf",
javascript_delay: 500,
encoding: 'UTF-8',
show_as_html: false,
disable_internal_links: true,
disable_external_links: true) and return
end
end
end

protected
def self.model
Bidding
end

private
def scoped_collection
policy_scope([:biddings, :pdf, Bidding]).includes(:bidding_type, :client, :payment_condition, :price_list, :real_payment_condition, :sales_man, :user)
end

def records_per_page
params[:per_page] || 10
end
end

没什么特别的,在那里你可以看到所有的配置选项,非常标准。不用说,带有页码的页脚工作正常(截图太长,无法显示,但请相信我)。不能对标题说同样的话。

这是 PDF 标题布局文件:

pdf_header.html.haml:
!!! 5
%html
%head
%meta{:content => "text/html; charset=utf-8", "http-equiv" => "content-type"}/
= wicked_pdf_stylesheet_link_tag "bidding_pdf", media: :all
= csrf_meta_tags
%body.pdf
= yield

这里是标题“内容”本身的内容:

header_pdf.html.haml:
Test text

只是纯文本。我有一个 Linux 16.04 x64 操作系统,wicked_pdf (1.1.0),wkhtmltopdf-binary (0.12.4)。我该如何调试?

最佳答案

对于遇到此问题的任何人,由于 OP 的回答不太准确,对我来说,工作是在页眉/页脚中包含一个 DOCTYPE HTML 标记。从不可见的标题(带有可以使用搜索工具找到的文本)到完全呈现。

关于ruby-on-rails - 邪恶的 PDF 标题没有显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51638021/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com