哪个是使用ASP.NET MVC4以pdf格式生成报告的最佳实践? [英] which is the best practice to generate report in pdf format using ASP.NET MVC4?

查看:78
本文介绍了哪个是使用ASP.NET MVC4以pdf格式生成报告的最佳实践?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要生成一份PDF报告,其中包含一些图像,服装文本信息以及我的ASP.Net MVC4应用程序的表格。请告诉我有关实施此方法的最佳方法的任何想法?

解决方案

按照以下步骤从您的网络应用程序生成实际报告:



*创建一个派生自PdfViewController的控制器。

*创建一个生成HTML的视图,该视图应转换为PDF报告。

*在控制器上创建一个动作,在PdfViewController上调用ViewPDF方法。

*创建一个链接以触发控制器上的动作。

*下面,这些步骤更详细地描述。



创建一个应转换为报告的视图。这可以是现有视图或专门用于报告的新视图。我通常会创建一个新视图,因为它可以让我控制报表的HTML标记。如前所述,报告生成器不支持所有HTML标记。在演示项目中,这是PrintDemo视图。



下面显示了演示项目中的PrintDemo视图。可以看出,这只是一个带有表和一些行的简单ASP.NET Razor视图。它使用强类型模型,但这不是必需的。尝试设计报表时的提示是为表或div添加边框。使用这些边框,在查看生成的PDF时,您可以清楚地看到报告区域的开始和结束



有关详细信息,请阅读以下内容发布:

http:// mvc- tutorials.com/how-to-create-pdf-report-in-asp-net-mvc3 [ ^ ]


您需要在服务器端生成报告并发送它作为客户的内容。从这里开始:使用ASP.NET MVC3进行PDF报告 [ ^ ]。

I need to generate a PDF report which contains some images, costume text info and a table for my ASP.Net MVC4 application. please give me any ideas on the best way to implement this?

解决方案

Follow these steps to generate an actual report from your web application:

* Create a controller that derives from PdfViewController.
* Create a view that generates the HTML which should be translated to a PDF report.
* Create an action on a controller which calls the ViewPDF method on the PdfViewController.
* Create a link to trigger the action on the controller.
* Below, these steps are described in more detail.

Create a view that should be translated to a report. This could be an existing view or a new view specially for reporting. I usually create a new view as it lets me control the HTML markup for the report. As stated earlier, the report generator does not support all the HTML markup. In the demo project, this is the PrintDemo view.

Below, the PrintDemo view from the demo project is shown. As can be seen, this is just a simple ASP.NET Razor view with a table and some rows. It uses a strongly typed model but that is not necessary. A tip when trying to design your report is to add borders to your table or div. Using these borders, when looking at the generated PDF, you can clearly see the start and end of the areas of your report

For more information,you can read the following post:
http://mvc-tutorials.com/how-to-create-pdf-report-in-asp-net-mvc3[^]


You will need to generate you report on server side and send it as content to the client. Start here: PDF reporting using ASP.NET MVC3[^].


这篇关于哪个是使用ASP.NET MVC4以pdf格式生成报告的最佳实践?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆