使用 Ruby 打印报告和发票?
我刚刚学习 Ruby,我想知道如何生成报告和发票(带有徽标、地址字段、页脚、可变数量的发票项目(有时会导致不止一页),将支付金额从一页结转到接下来,自由浮动的 2 列文本(左右对齐)位于生成的现金信息下方)。
目前,我从操作系统(匹配打印机规格)获得一个画布进行打印和绘图,并使用一些绘图、移动、行、文本和换页 API 函数,并对文本块移动进行一些繁重的计算(a有点像 TeX)。
在 Ruby 中这将如何完成?
构建 .odt 并将其扔给 OpenOffice 或 .tex 并将其扔给 LaTeX?
或者有没有免费的库,它们可以为我做所有这些事情,所以我只需要提供相关部分,并让 Ruby 做文本格式化的事情?
编辑:
更具体地说:我想在首页(DIN-A4格式,但也可以是字母)的特定位置放置公司徽标,以及每页的页脚和第一页上的地址框。 其余的应该是自由浮动的文本块,左右对齐,文本中间有粗体字。
类似的东西
pdf.column.blocktext("Hello Mr. P\nwe have [b]good news[/b] for you. bla bla bla and so on. Please keep this text together (no page break)...");
pdf.column.floatingblock("This is another block, that should be printed, and can be broken over more than one column...");
应该在纸张上以公司字体呈现文本,对齐,并且如果到达页面底部则整齐地换行到下一列/页面。
想一想,这正是 LaTeX 的用途。
I just learn Ruby, and I wonder how to generate Reports and Invoices (with Logo, adressfield, footer, variable number of invoice-items (sometimes resulting in more than one page), carry over of the amount to pay from one page to the next, free-floating 2-column text (left-and-right-justified) below the resulting cash-informations).
Currently I get a canvas to print and draw on from the OperatingSystem (matching the printer specifications) and use some draw-, move-, line-, text- and formfeed-API-Functions and do some heavy calculations for textblock-moving (a bit TeX-like).
How will this be done in Ruby?
Building an .odt and throw it to OpenOffice or a .tex and throw it to LaTeX?
Or are there any free Libraries, thet do all this kind of things for me, so I only have to feed the relevant parts, and let Ruby do the Text-Formatting thing?
EDIT:
To be more specific: I want to put a corporation logo on the first page (DIN-A4-format, but may also be letter) on a specific position, also the footer on every page and the adress-box on the first page. all the rest should be free floating text blocks with left-right-justification, bold words in the middle of texts.
something like
pdf.column.blocktext("Hello Mr. P\nwe have [b]good news[/b] for you. bla bla bla and so on. Please keep this text together (no page break)...");
pdf.column.floatingblock("This is another block, that should be printed, and can be broken over more than one column...");
which should render the text in the corporate font on the paper, justified, and wrapping neatly to the next column/page if it reaches the bottom of the page.
Thinking about it, this is exactly, what LaTeX is for.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议你考虑PDF生成。 在 Rails 中,使用 Prawn 库非常简单。
还有一个关于此的全新 Railcast。
官方网站。
I suggest you consider PDF generation. In Rails, it's pretty simple with the Prawn library.
There is also a fresh new Railcast about that.
Official web site.
您还可以查看用于生成 PDF 的 HtmlDoc,它只接受 HTML 并从中生成 PDF。 这种方法很好,因为它可以让您轻松地重复使用屏幕和硬拷贝发票的部分内容。
http://blog .adsdevshop.com/2007/11/20/easy-pdf- Generation-with-ruby-rails-and-htmldoc/
You could also check out HtmlDoc for generating PDFs, it just takes in HTML and generates a PDF from it. This approach is nice because it lets you very easily reuse a partial for an on-screen and hard copy invoice.
http://blog.adsdevshop.com/2007/11/20/easy-pdf-generation-with-ruby-rails-and-htmldoc/
Ruport 库(Ruby Reports)使得以多种格式(包括 PDF)生成报告表变得非常容易。 还有一个 ActiveRecord 挂钩
acts_as_reportable
为您的模型提供报告界面。The Ruport library (Ruby Reports) makes it pretty easy to spit report tables out in multiple formats, including PDF. There's also a ActiveRecord hook
acts_as_reportable
that gives your models a reporting interface.