开发者

How to write a simple designer for printed reports

I'm currently having a couple of reports which I print from my Forms applications. However building printed reports only with the built-in .NET printing methods is very tedious. Even just printing a simple table on a couple of pages with a little bit of formatting is a task for a couple of hours (if it should look nice).

What I need is a WYSIWYG-Designer for the layouts, so I'd like to write one. It shouldn't be for End-Users, but for me as a developer, it's just about to create the layout what the report will look like with various arrangements/fonts/images/formats and so on and not have to do that by trial & error in code (and restart the app a zillion times).

So my specific questions:

  1. What would I use as a canvas for editing and display of the report? An image-control/bitmap which开发者_高级运维 I draw upon like on the printed document? Is there a better way?

  2. Is drawing on a form comparable to drawing on a printed page? What about differences in resolution printer vs. screen?

  3. How to get real WYSIWYG? Should I get the printer settings and create my canvas with the same resolution? Is there something else to consider?

I know that there are report designers around but I think it's sometimes good to understand the basic working principles of what you use and implementing them is for me the best way to do that.

I'm aware that this is not a specific question A to which the answer is always B, but if it were that way I would find an answer in Google pretty quickly.

Thanks in advance!


I can't say much about designing a WYSIWYG editor, but I have written a few custom in-house reporting engines for use by our development team.

There's two main ways I've created reports. The first is using PDFsharp (MIT-licensed) to manually layout pages which isn't for the faint-of-heart.

The second is using Winnovative's HTML to PDF library (not free, but royalty-free) which uses the current installed version of IE to do the layout and spit out a PDF. It looks like they've recently released a new version called EVO PDF which I have never used before.*

For the HTML to PDF solution, it supports JavaScript so you can add in charts from JavaScript libraries like flot or jqplot.

*I'm not affiliated with Winnovative.


You might want to save time and use Visual Studio HTML designer as your WYSIWYG editor.

What I'm currently doing is using ASP.NET MVC 3 as a simple reporting engine. You can use the MVC pattern to really separate your reporting data source (Model) and the rendering (View) while using Visual Studio as your report designer.

From your application you can easily call your actions with the report optional parameters. For example:

http://localhost/Report/Customer/Orders/1

You simply get the returning string from a WebClient's DownloadString method and you have your report generated.

There is some down side using HTML, mainly the difficulties to know when a page would break, but by using code in your View you can calculate the amount of repeating items and add a CSS break-page and re-starting your table's header on the next page.

You can achieve anything from graphics, to table, you can even generate link to other reports.

HTH.


Printing Reports in Windows Forms http://msdn.microsoft.com/en-us/library/ms996472.aspx

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜