简体   繁体   English

HTML + CSS现在与生成打印报告有多成熟?

[英]how mature is HTML+CSS now in relation to generating reports for printing?

I'm considering creating all the reports of a series of desktop business apps directly to html. 我正在考虑将一系列桌面业务应用程序的所有报告直接创建到html。 Most of the reports are tables (maybe compound reports), headers, footers, etc. (no images, vector graphics, etc.). 大多数报告都是表格(可能是复合报告),页眉,页脚等(没有图像,矢量图形等)。

After a search in SO, I've read lots of post regarding problems with page breaks and things like that (I don't need pixel positioning at all, but yes control at page breaks). 在SO搜索之后,我已经阅读了很多关于分页符等问题的帖子(我根本不需要像素定位,但是在分页符时是控制)。

For example, let's say I have a big table with currency values and I need the last row of the table per page to display the running totals at that point.. it is something feasible to do easily or I will run in lots of trouble? 例如,假设我有一个带有货币值的大表,我需要每页表格的最后一行显示当时的运行总计..​​这是可行的,或者我会遇到很多麻烦?

What technologies can help me here? 哪些技术可以帮助我?

  • HTML5 HTML5
  • Javascript 使用Javascript
  • CSS CSS
  • PHP Librarys PHP图书馆
  • JQuery JQuery的

Some notes: 一些说明:

  • The html will be displayed with the chrome or firefox engine embeded, so the diferences between browsers it's not a problem for me. html将与嵌入的chrome或firefox引擎一起显示,因此浏览器之间的差异对我来说不是问题。
  • I can have the php preprocessor embedded if that helps to generate more easily the reports, I'm just looking fot the best technology at hand to make the work well.. 我可以嵌入php预处理器,如果这有助于更容易地生成报告,我只是在寻找手头上最好的技术来使工作顺利进行..
  • I'm tired of report generators with "WYSIWYG" designers (Crystal Report, FastReport, ReportBuilder, etc.) 我厌倦了“WYSIWYG”设计师的报告生成器(Crystal Report,FastReport,ReportBuilder等)

Thanks! 谢谢!

We made the exact move you're thinking about almost a year ago and haven't looked back. 我们做了你差不多一年前想到的确切行动,并没有回头。 Most communication with our client is over the web, so it's been a perfect fit. 与客户的大多数沟通都是通过网络进行的,因此它非常适合。 They can view html outputs easily on our website, and can generate pdf's of the page (server side) whenever necessary. 他们可以在我们的网站上轻松查看html输出,并在必要时生成页面(服务器端)的pdf。 The program we use for pdf conversion is a free, easy-to-use, open-source project called wkhtmltopdf . 我们用于pdf转换的程序是一个免费的,易于使用的开源项目,名为wkhtmltopdf

Where we are is great, but getting here was difficult. 我们在哪里很棒,但到这里很困难。

Deciding which pdf engine to use was a long, painful process. 决定使用哪个pdf引擎是一个漫长而痛苦的过程。 The short of it is that HTML is for viewing pages on the internet, not for viewing pages on paper. 缺点是HTML用于在互联网上查看页面,而不是用于在纸上查看页面。 Page-breaks will be the bane of your existence in this game -- you literally have to measure each page and create your own clean-looking breaks for every single report (otherwise, all html-to-pdf converters out there will just keep rendering the document onto the next page as it if encountered no page-break at all). 分页符号将成为您在此游戏中存在的祸根 - 您必须衡量每个页面并为每个报告创建自己干净的休息时间(否则,所有html-to-pdf转换器都将继续呈现将文档放到下一页上,如果没有遇到页面中断的话。 Further complicating the matter is that every html-to-pdf engine out there handles this sh*t differently and you'll have to write a tailored solution to test each one to see if it meets your individual needs. 使问题进一步复杂化的是,每个html-to-pdf引擎都以不同的方式处理这个问题,你必须编写一个定制的解决方案来测试每一个,看看它是否满足你的个人需求。

Now, the good news: 现在,好消息:

You can save yourself a lot of trouble by heeding my advice and going with wkhtmltopdf for your finalized reporting outputs. 通过听取我的建议并使用wkhtmltopdf来完成最终报告输出,您可以省去很多麻烦。 This little program is simply amazing -- it uses a webkit engine, renders CSS/javascript accurately, has header/footer control, optionally creates a table-of-contents page, and (most importantly) consistently produces excellent looking pdf's without having to customize your code base. 这个小程序简直太棒了 - 它使用webkit引擎,准确呈现CSS / javascript,具有页眉/页脚控件,可选地创建目录页面,并且(最重要的是)始终如一地生成出色的外观pdf而无需定制你的代码库。 It also has a variety of great command line switches, and it is very, very fast. 它还有各种出色的命令行开关, 非常非常快。 I say again: it is very, very fast. 我再说一遍: 它非常非常快。

Best of all, it's a command line tool that can be used in batch processing. 最重要的是,它是一个可用于批处理的命令行工具。 And did I mention that it's really, really fast? 我是否提到它真的非常快?

Browser support for printing is generally terrible. 浏览器对打印的支持通常很糟糕。 However, there are other tools, notably Prince (which is not free) and Flying Saucer (which is free) that can generate PDF output from XML/HTML plus CSS. 不过,也有其他的工具,特别是王子 (这是不是免费的)和飞碟 (这免费的),可以生成XML / HTML CSS加PDF输出。 Prince even supports JavaScript though I don't have any experience with it. Prince甚至支持JavaScript,虽然我对它没有任何经验。

I've got a Java back end in my current application, so for me Flying Saucer works fine for simple reports. 我目前的应用程序中有一个Java后端,所以对我来说,Flying Saucer适用于简单的报告。 I pre-process an HTML template with FreeMarker and then run the result through Flying Saucer. 我使用FreeMarker预处理HTML模板,然后通过Flying Saucer运行结果。 It's got a surprisingly smart rendering engine. 它有一个令人惊讶的智能渲染引擎。

The CSS3 Paged Media spec (well, proposed spec) has all sorts of cool stuff in it but they're almost totally unimplemented in the browsers. CSS3分页媒体规范(好的,提议的规范)中有各种很酷的东西,但它们在浏览器中几乎完全没有实现。 Even the CSS2 paged media stuff is only supported half-heartedly. 即使是CSS2分页媒体也只能半心半意地支持。

Speaking of Prince, you might look into DocRaptor. 说到Prince,您可以查看DocRaptor。 DocRaptor is another HTML to PDF conversion application. DocRaptor是另一个HTML到PDF转换应用程序。 It uses Prince XML, and handles CSS better than comparable programs. 它使用Prince XML,并且比同类程序更好地处理CSS。

It isn't free, but offers a free 30 day trial for all accounts, so there's no harm in trying it out, at least. 它不是免费的,但为所有账户提供30天免费试用,所以尝试它至少没有害处。

DocRaptor DocRaptor

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM