【问题标题】:PrawnPDF Flip Entire PDFPrawnPDF 翻转整个 PDF
【发布时间】:2015-07-14 15:51:17
【问题描述】:

我正在使用 Prawn PDF 创建一个发送到标签打印机的标签,但标签打印时是上下颠倒的。这很重要,因为我们使用的运输标签上已经有一些印刷品。我正在使用的设置(iPad 通过 Lantronix xPrintServer 到 Zebra 打印机)不允许我使用驱动程序翻转它。

所以我想知道是否有一种方法可以使用 Prawn(甚至只是 Rails)来翻转整个文档(包含 2 页以上),以便在标签上正确打印出来。页面的顺序不是必需的。

【问题讨论】:

  • 空白标签可以在放入机器之前翻转吗?
  • 它们在滚动,所以翻转它们不是一种选择。

标签: ruby-on-rails pdf printing prawn


【解决方案1】:

我最近没有使用过 Prawn,但我很确定在代码顶部使用 rotate 方法会起作用。您只需将原点设置为页面中心,或使用translate 在旋转后重新定位内容。 manual (PDF) 中的第 29 页有一些示例代码。

【讨论】:

  • 这在大多数情况下都有效。当我使用多页表执行此操作时,Prawn 似乎不喜欢它,但我想我可以解决这个问题。
【解决方案2】:

您可以将 pdf 保存到文件中,然后使用很棒的 pdftk 旋转保存的 pdf,然后发送修改后的版本。

https://www.pdflabs.com/docs/pdftk-cli-examples/

编辑 - pdftk 不是库/插件/gem,也不是任何类型的 Ruby。这是一个命令行工具,您可以在控制器中像这样使用它,替换您当前的“生成并发送 pdf”代码。

#instead of sending the pdf straight to the user, save it to a file
#i'm not sure how to do this in prawn but it can't be difficult

#rotate the original to a new file
`pdftk /path/to/original.pdf cat 1-endsouth output /path/to/rotated.pdf`

#you could test whether the rotated file exists here as an error-check

#then use send_file to send the rotated one as the response. 
send_file "/path/to/rotated.pdf", :type => "application/pdf"

【讨论】:

  • 我希望使用“即时”方法。真的不想使用其他库/插件/gem。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-07-25
  • 2022-12-15
  • 2018-12-18
  • 2013-01-13
  • 1970-01-01
  • 1970-01-01
  • 2019-01-28
相关资源
最近更新 更多