Rails 3 中使用 Latex 生成 PDF
有没有办法从 Rails 3 中的 Latex 生成 pdf 文档?我们一直在 Rails 2 应用程序中使用 rtex (http://rtex.rubyforge.org/),但它似乎不适用于 Rails 3。 我们的 Rails 应用程序使用乳胶模板生成发票,我们也使用该模板手动创建发票。因此,如果我们必须为 Rails 3 中的 pdf 生成找到不同的解决方案,我们就必须维护两个模板。
is there a way to generate pdf documents from latex in rails 3? We've been using rtex (http://rtex.rubyforge.org/) in a rails 2 application, however it doesen't seem to work with rails 3.
Our rails application generates invoices using a latex template which we also use to create invoices by hand. Hence we would have to maintain two templates if we had to find a different solution for the pdf generation in rails 3.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现做这些事情的最好方法是在服务器上创建 .tex 文件,然后调用运行“pdflatex”系统命令的 rake 任务。
我猜它的性能相当差,但它是为单个管理员设计的,并且在我的本地计算机上对我来说工作得很好,而且我可以为我的信件使用相同的乳胶模板
Best I found to do such things was to create the .tex files on the server, then call a rake task that ran a "pdflatex" system command.
It is pretty poor in performances I guess, but it's designed for a single admin and works fine for me, on my local machine, and I can use the same latex templates for my letters
老问题,但我相信这会对现在访问此页面的任何人有所帮助。
看一下 rails-latex (LatexToPdf) gem。
LatexToPdf.generate_pdf 方法接受两个参数:
...并返回 pdf 二进制文件,您必须将其写入文件。
我建议阅读源代码 是否需要添加配置。
请注意,在底层,rails-latex gem 仍然依赖于 TeX 扩展(您需要下载)来生成 pdf。默认是pdflatex,我个人用过xelatex。
在撰写本答案时,这个 gem 被描述为 Rails 3 的渲染器;尽管它现在包括对轨 4 和 5 的支持。
Old question, but I'm sure this'll help anyone coming to this page now.
Take a look at the rails-latex (LatexToPdf) gem.
The LatexToPdf.generate_pdf method takes in two arguments:
...and returns the pdf binary, which you'll have to write to a file.
I suggest reading through the source to if you need to add configuration.
Note that under the hood, the rails-latex gem still depends on a TeX extension (which you'll need to download) to generate the pdf. The default is pdflatex, and I've personally used xelatex.
As of the writing of this answer, this gem is described as a renderer for rails 3; though it now includes support for rails 4 and 5.