从 PHP Web 应用程序打印客户端报告

发布于 2024-07-12 22:39:43 字数 441 浏览 7 评论 0原文

我一直在寻找一种从基于 PHP Web 的应用程序客户端打印报告和预格式化表单的解决方案。 请注意,这些不是 HTML 页面的打印。 相当好的对齐固定格式的收据、订单、分类帐等。

我想到的东西。

使用 PDF:是否有一种简单的一键式方式从客户端打印报告? 显而易见的选择是在窗口中打开 PDF,然后选择“文件”->“文件”。 打印似乎太麻烦了。

使用Flash:我看到一些网站提供通过Flash 单击打印的功能。 不确定后台正在运行什么。 关于这方面的任何见解都会有所帮助。

Active-X/Silverlight(?):我不想限制我的用户只能使用 IE。 但这种一键打印的要求是如此严格,如果可以实现任务,我宁愿切换到仅限 MS 的平台。

请注意,单击一次即可弹出打印对话框,用户再次单击即可进行打印。 但比这更复杂的是一个缺点。

I was looking for a solution for client side printing of reports and pre formatted forms from a PHP web based app. Note that these are not printing of HTML pages. Rather nicely aligned fixed formated Receipts, Order Forms, Ledger etc.

Something that I have though of.

Using PDF: Is there a simple one click way to print the report from client side? The obvious choice of opening the PDF in a window, then select File -> Print seems too cumbersome.

Using Flash: I saw some site providing single click printing through flash. Not sure what's working in the background. Any insight on this regard will be helpful.

Active-X/Silverlight(?): I won’t want to constraint my users on IE only. But this one-click printing requirement is so rigid that I would rather switch to MS only platforms if it achieves the task.

Note that it’s ok for the single click to bring up the print dialog box and user clicking a second time for printing. But any more complexity than that is a disadvantage.

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

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

发布评论

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

评论(3

蓝梦月影 2024-07-19 22:39:43

如果格式如此严格,您需要 PDF 等格式。 HTML/CSS 变化很大,您永远不会在所有浏览器上得到相同的结果。 Plug Web 页面没有真正的页面概念(尽管有一些对 CSS 打印媒体样式等内容的支持)。

而且并非所有人都真正拥有打印机。 试图强制打印某些内容确实是错误的做法,通常会让一些客户望而却步。

最简单的解决方案是使用 emdia 打印 CSS 创建一个收据页面,使其在大多数情况下显得负责任。

如果这还不够,您需要使用 PDF。 不幸的是,这变得很难,正如这个关于 HTML+CSS 到 PDF 转换的问题所说明的那样PrinceXML 在这种转换方面做得非常出色,但它并不便宜。 Html2PDF 是开源中最好的,但存在问题(有关更多详细信息,请参阅该答案) 。 我在 Java 领域也遇到了同样的问题,发票最终使用 贾斯珀报告。 不过,我还没有真正见过适用于 PHP 的等效报告解决方案。 Python 有 reportlab,它似乎也适合做这种工作。

也许您最好的选择是直接生成 PDF。 虽然有点乏味,但它避免了 HTML 到 PDF 转换的许多陷阱。 本教程 (< a href="http://devzone.zend.com/article/1255-PDF-Generation-Using-Only-PHP---Part-2" rel="nofollow noreferrer">第 2 部分)解释了如何。

If the format is so rigid you need a format like PDF. HTML/CSS is so variable you'll never get it the same on all browsers. Plug Web pages have no real concept of pages (although there is some support for things like CSS print media styling).

Also not all people actually have a printer. Trying to force something to be printed is really the wrong approach and will generally put some of your customers off.

The minimal solution is to create a receipt page with the emdia print CSS to make it appear responable most of the time.

If that's not enough you need to go PDF. Unfortunately that then becomes hard as this question regarding HTML+CSS to PDF conversion illustrates. PrinceXML does an outstanding job at this conversion but it's not cheap. Html2PDF is the best of the open source bunch but has issues (see that answer for more detail). I've had this same problem in the Java space and for invoices there ending up using Jasper Reports. I haven't really seen an equivalent reporting solution for PHP though. Python has reportlab, which seems a likely candidate for doing that kind of job too.

Perhaps your best option is to generate the PDF directly. It's a bit more tedious but it avoids the many pitfalls of HTML to PDF conversion. This tutorial (Part 2) explains how.

甜味拾荒者 2024-07-19 22:39:43
<a href = "#" onclick = "window.print(); return false;">Print!</a>
<a href = "#" onclick = "window.print(); return false;">Print!</a>
我的黑色迷你裙 2024-07-19 22:39:43

进一步到 Nelson LaQuet,您可以将 window.print() 放在 body 标记的 onload 属性中,以便在页面加载时弹出打印对话框,

(或使用 jquery 的 document.ready() 来实现相同的效果,或任何其他 JS框架提供)

Furter to Nelson LaQuet, you could put window.print() in the onload attribute of the body tag so that the print dialog pops up at page load,

(or use jquery's document.ready() to achieve the same, or whatever other JS frameworks offer)

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