CSHTML 轉換為 PDF (MVC Core)

此程式碼範例示範了將視圖轉換為 PDF 的過程。

兩個軟體包 IronPdf.Extensions.Mvc.CoreIronPdf 協同工作,以實現將視圖渲染為 PDF。 IronPdf.Extensions.Mvc.Core 套件是 IronPdf 的擴展,能夠將視圖渲染為 PDF。

Use the RenderRazorViewToPdf method to render Views to PDFs. This method requires an IRazorViewRenderer, the path to the ".cshtml" file, and the data required to display on the ".cshtml" file. Please visit the How to Convert View to PDF in ASP.NET Core MVC how-to article to learn more.

This action also enables you to access the full range of features provided by the RenderingOptions class, such as applying page numbers in PDFs with IronPDF, adding text and HTML headers and footers with IronPDF, and customizing PDF paper size. The resulting PDF document can be further edited or exported as needed.

學習如何在ASP.NET MVC Core 中將 CSHTML 視圖轉換為 PDF。

準備好開始了嗎?
Nuget 下載 17,803,474 | 版本: 2026.3 剛剛發布
Still Scrolling Icon

還在滾動嗎?

想快速取得證據? PM > Install-Package IronPdf
運行範例看著你的HTML程式碼變成PDF檔。