PrawnPDF 翻转整个PDF
PrawnPDF Flip Entire PDF
我正在使用 Prawn PDF 创建一个标签,然后将其发送到标签打印机,但标签打印颠倒了。这很重要,因为我们使用的运输标签上已经有一些印刷品。我正在使用的设置(iPad 通过 Lantronix xPrintServer 到 Zebra 打印机)不允许我使用驱动程序翻转它。
所以我想知道是否有一种方法可以使用 Prawn(或者甚至只是 Rails)来翻转整个文档(包含 2+ 页)以便在标签上正确打印出来。页面的顺序不是必需的。
您可以将 pdf 保存到文件,然后使用 awesome pdftk
旋转保存的 pdf,然后发送修改后的版本。
https://www.pdflabs.com/docs/pdftk-cli-examples/
编辑 - pdftk 不是 library/plugin/gem,也不是任何类型的 Ruby。这是一个命令行工具,您可以像这样在您的控制器中使用它,替换您当前的 "generate and send 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"
我最近没有使用 Prawn,但我很确定使用 rotate
method at the top of your code will work. You'll just need to either set the origin to the center of the page, or use translate
to reposition the content after rotation. Page 29 in the manual (PDF) 有一些示例代码。
我正在使用 Prawn PDF 创建一个标签,然后将其发送到标签打印机,但标签打印颠倒了。这很重要,因为我们使用的运输标签上已经有一些印刷品。我正在使用的设置(iPad 通过 Lantronix xPrintServer 到 Zebra 打印机)不允许我使用驱动程序翻转它。
所以我想知道是否有一种方法可以使用 Prawn(或者甚至只是 Rails)来翻转整个文档(包含 2+ 页)以便在标签上正确打印出来。页面的顺序不是必需的。
您可以将 pdf 保存到文件,然后使用 awesome pdftk
旋转保存的 pdf,然后发送修改后的版本。
https://www.pdflabs.com/docs/pdftk-cli-examples/
编辑 - pdftk 不是 library/plugin/gem,也不是任何类型的 Ruby。这是一个命令行工具,您可以像这样在您的控制器中使用它,替换您当前的 "generate and send 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"
我最近没有使用 Prawn,但我很确定使用 rotate
method at the top of your code will work. You'll just need to either set the origin to the center of the page, or use translate
to reposition the content after rotation. Page 29 in the manual (PDF) 有一些示例代码。