创建 PDF 发票 - 是否有任何模板解决方案?

发布于 2024-07-08 16:27:54 字数 1511 浏览 8 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(22

陌若浮生 2024-07-15 16:27:54

试试这个...用Word(或任何你想要的)创建一张空白发票并将其另存为PDF。

然后使用 PDF 库修改 PDF(在特定坐标处插入文本)。 我们在微软世界里这样做是非常容易的。

最大的好处是我们可以使用自己的工具来创建和修改模板。 如果我们想添加一些静态文本,我们只需打开 Word,进行更改并将其保存到 PDF 文件(用作模板)。

对于 Microsoft,我们使用 iTextSharp,它实际上是原始 Java 版本的 iText


另外...

您可以使用 Adob​​e Acrobat 在 PDF 中插入字段(地址、电话、发票号码) 、行项目 1、行项目 2 等...),然后使用 iText/iTextSharp 在运行时填充这些字段。

更详细地说,这就是我们所做的……而且非常简单。

Try this... create a blank invoice with Word (or whatever you want) and save it as a PDF.

Then use a PDF library to modify the PDF (insert the text at particular coordinates). We do this in the Microsoft world and it is extremely easy.

The biggest benefit is that we can use our own tools to create and modify the template. If we want to add some static text, we just crank open Word, make the change and save it to a PDF file (that is being used as a template).

For Microsoft, we use iTextSharp which is actually a C# port of the original Java version of iText


Additionally...

You can use Adobe Acrobat to insert fields in the PDF (address, phone, invoice number, line item 1, line item 2, etc...) and then use iText/iTextSharp to populate these fields at run time.

This is, in more detail, what we do... and it is extremely easy.

眼中杀气 2024-07-15 16:27:54

正常的方法是安装 (La)TeX(可能已经在 Linux 机器上)并运行 pdflatex 来获取 pdf。 如果您更喜欢 xslt 和 xsl-fo,您还可以使用 Apache FOP。

如果要创建的发票数量较少,您可能需要使用开放式办公室(直接或作为工具包)。

如果你想要高精度定位和低级访问,低级pdf库(我不知道iTextSharp是否可以与mono一起使用)可能就是你想要的。

我会首先尝试 LaTeX,因为它可以让您以最少的努力获得结果。

The normal way is to install (La)TeX (probably already on the linux box) and run pdflatex to get the pdfs. You can also use Apache FOP, if you prefer xslt and xsl-fo.

If the number of invoices to create is low you might want to use open-office (directly or as a toolkit).

If you want high-precision positioning and low-level access, a low-level pdf library (I don't know if iTextSharp works with mono) might be what you want.

I would try out LaTeX first, because it allows you to get results with the least effort.

余生一个溪 2024-07-15 16:27:54

我之前通过模板化 PostScript 文件来生成发票,然后使用 Ghostscript 的 ps2pdf 将其转换为 PDF。

I've previously produced invoices by templating a PostScript file, and then using Ghostscript's ps2pdf to convert those into PDFs.

半衾梦 2024-07-15 16:27:54

我们将 Reportlab 与 Python 结合使用。 如果您环顾四周,就会发现大量现成的表格/发票/等。

We use Reportlab with Python. If you look around there are a load of ready-made forms/invoices/etc.

坦然微笑 2024-07-15 16:27:54

有多种 OSS 报告引擎(Jasper ReportsPentahoBIRT 仅举三个)您可以像以前使用 Crystal Reports 一样使用它。 其他海报之一提到 ReportLab,这是如果您使用 Python 或者可以在应用程序中嵌入 Python 运行时,则可以选择此选项。

There are several OSS reporting engines (Jasper Reports, Pentaho and BIRT to name three) that you could use in much the same way as you have historically used Crystal Reports. One of the other posters mentions ReportLab, which is an option if you're using Python or can embed a Python runtime in your application.

¢蛋碎的人ぎ生 2024-07-15 16:27:54

也许最灵活的解决方案是使用发票数据创建 XML,然后使用 XSLT 将其转换为 PDF、HTMls 等......

Probably the most flexible solution is to create XMLs with invoice data and then by using XSLTs transform the, into PDFs, HTMls, whatever...

夏了南城 2024-07-15 16:27:54

这取决于您的环境。 如果您可以访问 Java,您可以查看 iText (http://www.lowagie.com/iText/ ),一个允许您即时生成 PDF 文件的库。

It depends on your environment. If you have access to Java, you might look at iText (http://www.lowagie.com/iText/), a library that allows you to generate PDF files on the fly.

对不⑦ 2024-07-15 16:27:54

如果我理解正确的话,有两个步骤:
1) 创建带有占位符的 PDF 模板,以编程方式填充数据
2) 在运行时以编程方式填充 PDF 模板

对于#1,OpenOffice 允许创建 PDF 模板,然后可以以编程方式填充。 创建简单的发票就足够了,可能不涉及数据网格/表格之类的东西。

对于#2,您已经在这里找到了答案 - iText、iTextSharp。

希望这可以帮助!

There are two steps, if i understood correctly:
1) Creation of PDF template with placeholders to populate data programmatically
2) Populating the PDF template programmatically during run time

For #1, OpenOffice allows creation of PDF templates, which can then be populated programmatically. It's good enough to create simple invoices that doesn't probably involve datagrid/table kind of stuff.

For #2, you already have the answers here - iText, iTextSharp.

Hope this helps!

我只土不豪 2024-07-15 16:27:54

不确定你的目标是什么,但是有一个名为 fpdf 的开源 php 库,它还有一个扩展,可以将预制的 pdf 作为布局,然后用更多内容填充它,并使用该信息生成新的 PDF。

但是,我会寻求一种可以很好地集成到您正在构建的平台中的解决方案,但我不会采用 HTML->PDF 解决方案,因为您不知道什么适合一块关于这种环境中尺寸的纸张,这意味着您不知道何时应该将内容拆分为两个单独的模板。

Not sure what your goal is here, but there is an opensource php-library called fpdf, which also has an extension for taking a pre-made pdf as layout and then populate it with more content, generating a new PDF with that info.

However, I would go for a solution that you can integrate nicely into the plattform you're building, but I wouldn't go in a HTML->PDF solution since you won't have any clue about what would fit on a piece of paper regarding sizes in that kind of enviroment, meaning you won't know when you should split the content into two separate templates.

爱冒险 2024-07-15 16:27:54

您也可以尝试使用 XSL:FO。 XSL:FO 是描述页面布局的记录标准: http://www.w3 .org/TR/xsl/#fo-section

我在两个项目上取得了成功,通过创建定义“PDF”内容的 XML 模式来创建文档。 然后,我使用 XSD 工具(来自 Microsoft)生成表示该文档的类。 然后,我将数据映射到该结构中,将填充的类序列化为 XML,以及定义如何将数据映射到 FO 的 XSL 样式表,并将其传递给 FO 格式化程序。 对于格式化程序,我已成功使用 Alt-Soft 的 Xml2Pdf。 还有其他一些。 有一些工具可帮助创建 XSL 到 FO 样式表(即 stylusstudio 和 XmlSpy),但我建议学习 FO 构造,因为这些工具似乎会生成臃肿的样式表。 FO 与 HTML 相当(其中 P 标记是 FO 中的 BLOCK 标记),但可能比较棘手。 FO 的一个好处是,某些格式化程序支持转换为其他格式,例如 Word、HTML 等。

其他选项:

  1. iTextSharp(iText 的 C# 端口)。 刚刚开始阅读有关此内容的内容。 开源且免费。 我认为这不支持任何“模板”,但我的想法可能是错误的。

  2. SQL Server 报告服务。 假设您的发票数据采用或可以采用可由报告服务(SQL Server、Web 服务等)读取的格式,在 SSRS 中定义布局,然后发布到报告服务器。 使用 SSRS Web 服务或查询参数执行来执行报表并将其输出为 PDF。

You might also try using XSL:FO. XSL:FO is a documented standard for describing page layout: http://www.w3.org/TR/xsl/#fo-section.

I've had success on two projects creating documents by creating an XML schema that defines the content of the "PDF". I then use the XSD tool (from Microsoft) to generate a class representing this document. I then map my data into that structure, serialize the populated class to XML, along with an XSL stylesheet that defines how that data should be mapped into FO, and pass it to an FO formatter. For formatters, I have use Alt-Soft's Xml2Pdf with success. There are a few others out there. There are some tools available to help create the XSL to FO stylesheet (i.e. stylusstudio and XmlSpy), but I recommend learning the FO constructs as the tools seem to produce bloated stylesheets. FO is comparable to HTML (where a P tag is a BLOCK tag in FO), but can be tricky. This nice thing about FO, is that some formatter support conversion to other formats, such as Word, HTML, etc.

Other options:

  1. iTextSharp (C# port of iText). Just started reading about this. Open source and free. I don't think there is any "templating" supported with this, but I could be wrong about that.

  2. SQL Server Reporting Services. Assuming your invoice data is in, or can be put in, a format that can be read by reporting services (SQL Server, Web Service, etc), define the layout in SSRS and then publish to reporting server. Use SSRS Web Services or query parameter execution to execute the report and have it output as PDF.

猥︴琐丶欲为 2024-07-15 16:27:54

这个 html-2-pdf 网站可能是一个有用的起点:http://maarten.lippmann.us /?p=101

我的一个朋友建立的一个网站也使用脚本将 HTML 页面转换为可打印的 PDF - http ://philambdaupsilon.org。 不确定具体的细节,但他是一个 SO 用户,我也会把这个问题发送给他。

This html-2-pdf site may be a helpful starting point: http://maarten.lippmann.us/?p=101

A site a friend of mine built uses a script to churn HTML pages into printable PDFs, too - http://philambdaupsilon.org. Not sure on the exact details of it, but he is an SO user, and I'll send this question to him, too.

吐个泡泡 2024-07-15 16:27:54

不幸的是,(目前)市场上最好的系统正在通过 HTML 和 HTML 格式。 CSS 到 ColdFusion 服务器并返回渲染的 PDF。 因此,如果资金不是一个大问题,那么这是部署最快的解决方案,可以带来最佳结果。

我非常努力地获取 FPDF、TCPDF、R&OS pdf 类,甚至 CodeIgniter 的推荐 可以工作,但除了最基本/平淡的 HTML 文件之外,没有任何稳定的输出。

老实说,如果 ColdFusion 解决方案不可行,我会使用 html2ps,然后使用 ps2pdf 将文件转换为 PDF。

(这一切都假设您不想花时间使用 PHP 中的本机 PDF 创建器代码来设计每个 PDF。这就是 SugarCRM 等系统所使用的。虽然它的功能非常强大且结果稳定,但每个 PDF 的实际创建PDF生成文件是一个最痛苦的过程)

Unfortunately, the best system on the market (at present) is passing the HTML & CSS to a ColdFusion server and have that return the rendered PDF. So if money isn't a big concern, this is the quickest to deploy solution that'll render the best results.

I've tried very hard to get FPDF, TCPDF, the R&OS pdf class, and even CodeIgniter's recommendation to work, but nothing with stable output for anything beyond the most basic/bland HTML files.

Honestly, if the ColdFusion solution isn't viable, I'd use html2ps, and then ps2pdf to convert your files into a PDF.

(This is all assuming that you don't want to take the time and design each PDF using the native PDF-creator code in PHP. This is what systems like SugarCRM use. Though its very functional with stable results, the actual creation of each PDF-generator file is a most painful process)

不一样的天空 2024-07-15 16:27:54

我们之前使用过 Jasper Reports。 这不是您所说的用户友好型,但它会直接与您的数据库对话。

We have used Jasper Reports before. It's not what you'd call user-friendly, but it will talk directly to your database.

温柔一刀 2024-07-15 16:27:54

html2pdf 效果很好。 您可以使用它从同一来源生成 HTML 和 PDF 报告。

html2pdf works very well. You can use this to generate both HTML and PDF reports from the same source.

红尘作伴 2024-07-15 16:27:54

我现在正在摆弄Black Sheep Invoices,一开始很棒,但现在我实际渲染 PDF 时遇到困难。 安装有很多困难——在您自己的服务器上可能会容易得多,但我在共享主机上安装它。 HTML 输出和数据管理部分做得很好,这是您仅创建 Postscript 模板无法摆脱的。 我希望找到一个拥有活跃开发团队的库的参考(Black Sheep 目前尚未更新)。

I'm fiddling with Black Sheep Invoices right now, which is great at first but now I'm having trouble actually getting it to render the PDFs. Lots of installation difficulties--probably a lot easier on your own server but i'm up on a shared host with it. The HTML output and data management portions are well done though, which is something you won't get out of just creating a postscript template. I was hoping to find a reference to a library that has an active development team though (Black Sheep is not being updated at this time).

×纯※雪 2024-07-15 16:27:54

如果您希望将浏览器完美的 HTML 转换为 PDF,请尝试 commandlineprint

您需要在 Linux 上安装 Firefox发行版,禁用所有 Firefox 警报,然后通过虚拟显示器运行它。 检查此线程以获取更多详细信息。

运行良好确实令人恼火,但确实为您提供了我见过的 HTML 到 PDF 转换的最佳结果。

If you want browser perfect HTML converted to PDF then try commandlineprint

You'll need to install firefox on a linux distro, disable all firefox alerts and then run it through a virtual display. Check this thread for more details.

It's infuriating to get running well but does give you the best results for HTML to PDF conversion I've seen.

小忆控 2024-07-15 16:27:54

好的,搜索 Google Code 项目后发现了 Simple Invoices,它非常棒,而且维护得很好。

OK, a search of Google Code projects turned up Simple Invoices, which is awesome and well maintained.

[旋木] 2024-07-15 16:27:54

我使用 TROFF 作为我的发票,因为它的文本编码极其简单。 逻辑是几行 Perl 代码。 保持简单。

I use TROFF for my invoices because of its extremely simple textual encoding. The logic is a few lines of Perl. Keeping it simple.

从来不烧饼 2024-07-15 16:27:54

对于 Ruby 解决方案,请尝试 Prawn:http://prawn.majesticeacreature.com/

For a Ruby solution, try Prawn: http://prawn.majesticseacreature.com/

不即不离 2024-07-15 16:27:54

我在服务器上使用 open office,然后生成文档的 XML(只需解压缩文档并破解)

I use open office on the server and then generate the XML for the document (just unzip the document and hack away)

稀香 2024-07-15 16:27:54

有些人可以使用 Dhek 模板编辑器为现有 PDF 定义区域/占位符,而不更改现有文档,然后填充它以生成最终文档(例如使用表单中的用户值): https://github.com/applicius/dhek

Some can use Dhek template editor to define area/placeholder for existing PDF, without altering existing document, and then populate it to generate final doc (e.g. with user values from a form): https://github.com/applicius/dhek .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文