- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 wicked_pdf 从 html 生成 pdf。现在,我想删除第一页/封面页的上边距。
这是从我的 Controller 中截取的代码:
render :pdf => @project.name,
:javascript_delay => 1000,
:disable_external_links => false,
:encoding => 'UTF-8',
:cover => "#{root_url}/projects/#{params[:id]}/pdf_cover",
:footer => {:html => { :template => 'projects/report_footer.pdf.haml' }, :spacing => 5},
:show_as_html => params[:debug].present?,
:disable_smart_shrinking => false,
:print_media_type => true,
:no_background => false,
:margin => { :top => 10, :bottom => 18 , :left => 0 , :right => 0}
正如您在上面看到的,在 Controller 操作中我将上边距设置为 10 。所以我希望上边距、页眉和页脚不显示在第一页上,而是显示在文档的其余页面上。附件区
最佳答案
我看到你也在 the Wicked PDF issue tracker 上发布了这个
页眉、页脚和边距对于创建的 PDF 是全局的,因此您不能单独调整封面。
但是,您可以创建两个 PDF,一个只是封面,另一个是其余的,然后将它们与 Ghostscript 或 PDFtk 结合。
Here's an example of how you might do that :
html_content = render_to_string
cover_pdf = WickedPdf.new.pdf_from_string(html_content, { footer: { margin: { bottom: 200 })
body_pdf = WickedPdf.new.pdf_from_string(html_content, { footer: { margin: { bottom: 10 })
cover_src_temp_file = Tempfile.new(['cover_src', '.pdf'])
cover_src_temp_file.binmode
cover_src_temp_file.write(cover_pdf)
cover_src_temp_file.rewind
cover_temp_file = Tempfile.new(cover_pdf)
`pdftk #{cover_src_temp_file} cat 1 output #{cover_temp_file.path.to_s}` # first page only
body_src_temp_file = Tempfile.new(['body_src', '.pdf'])
body_src_temp_file.binmode
body_src_temp_file.write(cover_pdf)
body_src_temp_file.rewind
body_temp_file = Tempfile.new(body_pdf)
`pdftk #{body_src_temp_file.path} cat 2-end output #{body_temp_file.path}` # everything else
output_temp_file = Tempfile.new(['output', '.pdf'])
`pdftk #{cover_temp_file.path} #{body_temp_file.path} cat output #{output_temp_file.path}`
send_file output_temp_file, disposition: 'inline'
[cover_src_temp_file, body_src_temp_file, cover_temp_file, body_temp_file, output_temp_file].each do |tf|
tf.close
tf.unlink
end
关于ruby-on-rails - 邪恶的 PDF : How to remove top margin from COVER page?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44434529/
对于线程和计时器之类的东西,我无法忍受拖放控件。这些控件只是感觉与它们存在的实际本质相去甚远。拖放一个线程?我希望拖拽者在他们这样做之前了解幕后发生的事情。 这些抽象是否离金属太远了?他们是在帮助还是
有些人似乎认为 C 的 strcpy() 函数不好或邪恶。虽然我承认通常最好使用 strncpy() 来避免缓冲区溢出,但以下(strdup() 函数的实现对于那些不幸的人来说拥有它)安全地使用 st
我一直在用 matrix = *((fxMatrix*)&d3dMatrix); 好久不见。它工作正常,直到我的屏幕变黑并在我的办公 table 上收到一桶挫败感。 fxMatrix 包含 4 个 f
这是我应该问的问题,而不是这个: Emacs evil: space as a prefix key in motion state 我想定义一堆用于移动、移动、打开和关闭窗口和缓冲区的命令,这些命令
作为 Vim 用户,我在将近二十年后尝试 Emacs+Evil。我正在将我的大部分 Vim 配置移至 Evil,但我遇到很多问题的一件事是像我在 Vim 中使用的那样设置搜索和突出显示。我想要得到的是
很难说出这里问的是什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或言辞激烈,无法以目前的形式合理回答。如需帮助澄清此问题以便可以重新打开,visit the help center . 9年前关闭
我是一名优秀的程序员,十分优秀!