开发者

Printing from web pages (reports especially) with greater precision

开发者 https://www.devze.com 2022-12-24 09:13 出处:网络
I am re-engineering a windows application to be ported to web. One area that has been worrying is \'printing\'.

I am re-engineering a windows application to be ported to web. One area that has been worrying is 'printing'.

The application is data intensive and complex reports need to be generated. The erstwhile windows application takes advantage of printer APIs and extends sophisticated control to the users. It supports functions like page break, avoiding printing on printed parts of the sheet (like letterhead), choice of layouts and orientation, etc. Please note that these setting are not done only while printing, they are part of report definition sometimes.

From what I know, we cannot have this kind of control while printing web pages. I am in a process of identifying options at my disposal. While I prefer to first look into something that will help me print from raw web pages, following are other thoughts:

  1. Since reports can also be exported to .xls & .pdf versions, let user download one and print directly. This however limits my solution to the area of application that have export feature.
  2. Use Silverlight (4.0) for report layout definition and print. I think Silverlight 4.0 (in beta right now) provides adequate control over the printer. I have so far been avoiding the need of any RIA plugin.
  3. Meticulously generate reports on web with fixed dimensions. I am not sure how far this will go.

Please share practices that can be applied easily in my 开发者_Python百科scenario.


For reporting in the past on the web, using .NET, I like to generate PDF, Excel, Word or CSV files. I really like iTextSharp which allows for creating of PDF's.

Word can accept HTML, so that is usually quote easy. For more control you can get into the Word interops http://nishantrana.wordpress.com/2007/11/03/creating-word-document-using-c/, but they left me frustrated. Not for implementation, but I felt the clean up was poor.

CSV are great for raw data dumps and that is it.

For HTML, you can get nice control using a style sheet targeted to print media. There are just certain things you cannot control, like browser header and footer.


Flash also has better print controls than plain HTML, though you might not know it since these features are rarely used by flash developers. Almost everyone should have Flash installed these days, so it's not like Silverlight where there's a good chance of someone needing to install a plugin (doubly so for a beta version). I am not sure how the Flash printer APIs compare to Silverlight's printer APIs and if they give you the level of control you need, but their documentation is public so you can look into it.

Also I think exporting to PDF is a good idea. I don't see why you can't extend this to cover all places that would need to print a report. Basically instead of printing directly from the windows app running on their desktop, the same exact code runs on your server and generates a PDF that they can then print themselves.


I don't think you're going to have much luck trying to do it with raw HTML unfortunately. For one of our clients, we went with the "generate PDF" route and it worked out quite well. PDFs have the additional advantage that you don't have to print them out: you can just email them to the boss/accountant/whatever saving a bit of paper.


PDF is the way to go, if you want absolute control over printed output. As bonus, you can also provide the option to download PDFs in your application.

With HTML, you are at the mercy of user's browser settings for page size, margin and how page breaks will be handled.

0

精彩评论

暂无评论...
验证码 换一张
取 消