Rails 3 和 PDFKit,如何将 HTML 文件转换为横向 PDF?
我可以很好地将 HTML 页面转换为 PDF 文档。问题是,我不知道如何将 HTML 文件转换为横向 PDF。有没有办法在控制器中设置它?
从控制器...
def pdf_customer_shipments
@customer = Customer.find(params[:id])
@shipments = Shipment.where("customer_id = ? AND status = 'Open'", @customer.id)
render :layout => 'pdf'
end
I can convert HTML pages into PDF documents well. The problem is, I don't know how to convert the HTML file into a landscape orientation PDF. Is there a way to set that in the controller?
From the controller...
def pdf_customer_shipments
@customer = Customer.find(params[:id])
@shipments = Shipment.where("customer_id = ? AND status = 'Open'", @customer.id)
render :layout => 'pdf'
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果这有帮助,我正在使用 PDFKit 并且可以使用横向渲染 pdf:
我从这里获得了方向部分: https: //github.com/pdfkit/pdfkit/issues/12
In case this helps, I am using PDFKit and can render the pdf in landscape using:
I got the orientation part from here: https://github.com/pdfkit/pdfkit/issues/12
您的 html 文件中需要一个元标记:
那么 PDF 就是横向的。
You need a meta tag in you html file:
Then the PDF is in landscape orientation.
PDFKit 应该接受 wkhtmltopdf 的选项,因此您应该能够使用以下命令在横向模式下渲染:
PDFKit should accept options for wkhtmltopdf, so you should be able to render in landscape mode by using this: