CSHTMLからPDFへ(MVC Core)
このコード例は、Views を PDF に変換するプロセスを示しています。
2 つのパッケージ IronPdf.Extensions.Mvc.Core と IronPdf が連携して動作し、ビューを 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に変換する方法
- C#でCSHTMLファイルをPDFに変換するためのC#ライブラリをインストールする。
- `ChromePdfRenderer`クラスをインスタンス化します。
- レンダリングには `RenderRazorViewToPdf` メソッドを使用してください。
- メソッドに `IRazorViewRenderer` オブジェクトと CSHTML ファイルのパスを渡します。
- 完成したPDFドキュメントをデスクトップにダウンロード

