如何在PDF文件中下载WebGrid数据?

时间:2021-02-03 21:22:56

I have a Web application which implemented in MVC (Razor) environment. Inside this application, there is a page that shows data from SQL Server(using Entity Framework) with WebGrid.

我有一个在MVC(Razor)环境中实现的Web应用程序。在此应用程序中,有一个页面显示来自SQL Server(使用实体框架)和WebGrid的数据。

I want to know that how can I embed a button to download this WebGrid data as a PDF file?

我想知道如何嵌入按钮将此WebGrid数据下载为PDF文件?

Thanks in advance.

提前致谢。

1 个解决方案

#1


1  

You will need a third party component to generate the PDF since .NET doesn't natively include anything that does that. I recommend iTextSharp. Then you just obtain the data from the database and construct a PdfPTable object which you include in a Pdf document.

您将需要第三方组件来生成PDF,因为.NET本身并不包含任何内容。我推荐iTextSharp。然后,您只需从数据库中获取数据并构造一个包含在Pdf文档中的PdfPTable对象。

I have written an article that includes complete code here: http://www.mikesdotnetting.com/Article/205/Exporting-The-Razor-WebGrid-To-PDF-Using-iTextSharp

我在这里写了一篇包含完整代码的文章:http://www.mikesdotnetting.com/Article/205/Exporting-The-Razor-WebGrid-To-PDF-Using-iTextSharp

#1


1  

You will need a third party component to generate the PDF since .NET doesn't natively include anything that does that. I recommend iTextSharp. Then you just obtain the data from the database and construct a PdfPTable object which you include in a Pdf document.

您将需要第三方组件来生成PDF,因为.NET本身并不包含任何内容。我推荐iTextSharp。然后,您只需从数据库中获取数据并构造一个包含在Pdf文档中的PdfPTable对象。

I have written an article that includes complete code here: http://www.mikesdotnetting.com/Article/205/Exporting-The-Razor-WebGrid-To-PDF-Using-iTextSharp

我在这里写了一篇包含完整代码的文章:http://www.mikesdotnetting.com/Article/205/Exporting-The-Razor-WebGrid-To-PDF-Using-iTextSharp