ASP.NET MVCでビューをPDFに変換する方法 (C# 使用)
IronPDFを使用すると、ChromePdfRenderer.RenderView() メソッドを使用して、わずか数行のコードでASP.NET MVCビューをPDFドキュメントに変換できます。 IronPdf.Extensions.Mvc.Framework パッケージは、CSHTMLビューをPDFとしてレンダリングするためのASP.NET MVCプロジェクトとの簡単な統合を提供します。
ビューは、ウェブアプリケーションでHTMLマークアップを生成するために使用されるASP.NETフレームワークのコンポーネントです。 これは、ASP.NET MVCおよびASP.NET Core MVCアプリケーションで一般的に使用されているModel-View-Controller(MVC)パターンの一部です。 ビューは、動的にHTMLコンテンツをレンダリングすることでユーザーにデータを提示する責任を負います。 IronPDFの Chrome PDF Rendering Engine の力により、ビューはピクセル単位で正確にレンダリングされ、すべてのスタイリング、レイアウト、インタラクティブな要素が確保されます。
ASP.NET Web アプリケーション (.NET Framework) MVC は、Microsoft が提供する Web アプリケーションフレームワークです。 これは、Model-View-Controller (MVC) として知られる構造化されたアーキテクチャパターンを利用して、ウェブアプリケーションの開発を整理し簡素化します。
- モデル: データ、ビジネス ロジック、およびデータ整合性を管理します。
- ビュー: ユーザーインターフェイスを提示し、情報をレンダリングします。
- コントローラ: ユーザーの入力を処理し、リクエストを処理し、モデルとビュー間のインタラクションを編成します。
IronPDF は、ASP.NET MVC プロジェクト内でビューから PDF ファイルを作成するプロセスを簡素化します。 これにより、ASP.NET MVC での PDF 生成が簡単かつ直接的になります。 IronPDFは請求書やレポート、あるいはウェブビューからあらゆるドキュメントを生成する場合でも、プロフェッショナルなPDF出力に必要なツールを提供します。 包括的なセットアップガイドについては、インストール概要ページをご覧ください。
クイックスタート: ASP.NET MVC ビューを簡単に PDF に変換するIronPDF を使用して、ASP.NET MVC ビューを PDF ドキュメントにすばやく変換する方法を学びましょう。 数行のコードで CSHTML ビューを高品質なPDFにレンダリングし、アプリケーションの機能を強化できます。 IronPDF はプロセスを簡素化し、すべてのレベルの開発者が利用しやすくしています。 ASP.NET Core プロジェクトに IronPDF を統合し、ビューからPDFを簡単に生成することから始めてください。
-
1IronPDF を NuGet Package Manager でインストールします
-
2このコード スニペットをコピーして実行します。
// Install-Package IronPdf.Extensions.Mvc.Framework ChromePdfRenderer renderer = new ChromePdfRenderer(); PdfDocument pdf = renderer.RenderView(this.HttpContext, "~/Views/Home/Persons.cshtml", persons);' Install-Package IronPdf.Extensions.Mvc.Framework Dim renderer As New ChromePdfRenderer() Dim pdf As PdfDocument = renderer.RenderView(Me.HttpContext, "~/Views/Home/Persons.cshtml", persons)' Install-Package IronPdf.Extensions.Mvc.Framework Dim renderer As New ChromePdfRenderer() Dim pdf As PdfDocument = renderer.RenderView(Me.HttpContext, "~/Views/Home/Persons.cshtml", persons) -
3実際の環境でテストするためにデプロイする
今日からご自身のプロジェクトでIronPDFを使い始めるには、無料トライアルをお試しください。
最小限のワークフロー(5ステップ)
- ASP.NET MVCでビューをPDFに変換するためのC#ライブラリをダウンロード
- データ用のモデルクラスを追加する
- コントローラに "Person "アクションを作成し、
RenderViewメソッドを使用します。 - MVC 5 View Scaffoldedを使用してViewを追加
- クイックスタート用のサンプルプロジェクトをダウンロード
どの拡張パッケージが必要ですか?
なぜIronPDFには拡張パッケージが必要なのですか?
IronPdf.Extensions.Mvc.FrameworkパッケージはメインのIronPDFパッケージの拡張機能です。 ビューをASP.NET MVCでPDFドキュメントとしてレンダリングするには、IronPdf.Extensions.Mvc.Framework と IronPdf パッケージの両方が必要です。 この分離により、コアのPDFレンダリング機能を維持しながら、MVCフレームワーク特有の機能を最適化することができます。
拡張パッケージのインストール方法
NuGetでインストール
Install-Package IronPdf.Extensions.Mvc.Framework
ビューをPDFにレンダリングするにはどうすればよいですか?
どのプロジェクトタイプが必要ですか?
Views を PDF ファイルに変換するには、ASP.NET Web アプリケーション (.NET Framework) MVC プロジェクトが必要です。 IronPDFは様々なMVCバージョンに対応しており、レンダリングオプションが豊富に提供されており、要件に応じてPDF出力をカスタマイズできます。
モデルクラスを追加するにはどうすればよいですか?
モデルはどこに作成すべきですか?
- 「Models」フォルダーに移動します
- 新しいC#クラスファイルを
Personという名前で作成します。 このクラスは個々のデータを表すモデルとして機能します。 以下のコードを使用してください:
namespace ViewToPdfMVCSample.Models
{
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public string Title { get; set; }
public string Description { get; set; }
}
}namespace ViewToPdfMVCSample.Models
{
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public string Title { get; set; }
public string Description { get; set; }
}
}Namespace ViewToPdfMVCSample.Models
Public Class Person
Public Property Id() As Integer
Public Property Name() As String
Public Property Title() As String
Public Property Description() As String
End Class
End NamespaceNamespace ViewToPdfMVCSample.Models
Public Class Person
Public Property Id() As Integer
Public Property Name() As String
Public Property Title() As String
Public Property Description() As String
End Class
End Namespaceコントローラーを編集するにはどうすればよいですか?
コントローラーにどのコードを追加すべきですか?
"Controllers"フォルダーに移動して、HomeController ファイルを開きます。次のコードを使用して、Persons アクションを追加します。
提供されたコードでは、まずChromePdfRenderer クラスが作成されます。 RenderView メソッドを使用するときは、HttpContext を指定し、「Persons.cshtml」ファイルへのパスを指定し、必要なデータを含むList<Person> を提供します。 ビューをレンダリングする際に、RenderingOptions を利用して、マージンをカスタマイズしたり、カスタムテキストやHTMLヘッダー、フッターを追加したり、ページ番号をPDFドキュメントに適用できます。
File(pdf.BinaryData, "application/pdf", "viewToPdfMVC.pdf").using IronPdf;
using System.Collections.Generic;
using System.Web.Mvc;
using ViewToPdfMVCSample.Models;
namespace ViewToPdfMVCSample.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
// GET: Person
public ActionResult Persons()
{
// Create a list of Person objects
var persons = new List<Person>
{
new Person { Name = "Alice", Title = "Mrs.", Description = "Software Engineer" },
new Person { Name = "Bob", Title = "Mr.", Description = "Software Engineer" },
new Person { Name = "Charlie", Title = "Mr.", Description = "Software Engineer" }
};
if (HttpContext.Request.HttpMethod == "POST")
{
// Define the path to the View file
var viewPath = "~/Views/Home/Persons.cshtml";
// Instantiate the ChromePdfRenderer
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Render the view to a PDF document
PdfDocument pdf = renderer.RenderView(this.HttpContext, viewPath, persons);
// Set headers to view the PDF in-browser
Response.Headers.Add("Content-Disposition", "inline");
// Return the generated PDF file
return File(pdf.BinaryData, "application/pdf");
}
return View(persons);
}
public ActionResult About()
{
ViewBag.Message = "Your application description page.";
return View();
}
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
return View();
}
}
}using IronPdf;
using System.Collections.Generic;
using System.Web.Mvc;
using ViewToPdfMVCSample.Models;
namespace ViewToPdfMVCSample.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
// GET: Person
public ActionResult Persons()
{
// Create a list of Person objects
var persons = new List<Person>
{
new Person { Name = "Alice", Title = "Mrs.", Description = "Software Engineer" },
new Person { Name = "Bob", Title = "Mr.", Description = "Software Engineer" },
new Person { Name = "Charlie", Title = "Mr.", Description = "Software Engineer" }
};
if (HttpContext.Request.HttpMethod == "POST")
{
// Define the path to the View file
var viewPath = "~/Views/Home/Persons.cshtml";
// Instantiate the ChromePdfRenderer
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Render the view to a PDF document
PdfDocument pdf = renderer.RenderView(this.HttpContext, viewPath, persons);
// Set headers to view the PDF in-browser
Response.Headers.Add("Content-Disposition", "inline");
// Return the generated PDF file
return File(pdf.BinaryData, "application/pdf");
}
return View(persons);
}
public ActionResult About()
{
ViewBag.Message = "Your application description page.";
return View();
}
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
return View();
}
}
}Imports IronPdf
Imports System.Collections.Generic
Imports System.Web.Mvc
Imports ViewToPdfMVCSample.Models
Namespace ViewToPdfMVCSample.Controllers
Public Class HomeController
Inherits Controller
Public Function Index() As ActionResult
Return View()
End Function
' GET: Person
Public Function Persons() As ActionResult
' Create a list of Person objects
'INSTANT VB NOTE: The local variable persons was renamed since Visual Basic will not allow local variables with the same name as their enclosing function or property:
Dim persons_Conflict = New List(Of Person) From {
New Person With {
.Name = "Alice",
.Title = "Mrs.",
.Description = "Software Engineer"
},
New Person With {
.Name = "Bob",
.Title = "Mr.",
.Description = "Software Engineer"
},
New Person With {
.Name = "Charlie",
.Title = "Mr.",
.Description = "Software Engineer"
}
}
If HttpContext.Request.HttpMethod = "POST" Then
' Define the path to the View file
Dim viewPath = "~/Views/Home/Persons.cshtml"
' Instantiate the ChromePdfRenderer
Dim renderer As New ChromePdfRenderer()
' Render the view to a PDF document
Dim pdf As PdfDocument = renderer.RenderView(Me.HttpContext, viewPath, persons_Conflict)
' Set headers to view the PDF in-browser
Response.Headers.Add("Content-Disposition", "inline")
' Return the generated PDF file
Return File(pdf.BinaryData, "application/pdf")
End If
Return View(persons_Conflict)
End Function
Public Function About() As ActionResult
ViewBag.Message = "Your application description page."
Return View()
End Function
Public Function Contact() As ActionResult
ViewBag.Message = "Your contact page."
Return View()
End Function
End Class
End NamespaceImports IronPdf
Imports System.Collections.Generic
Imports System.Web.Mvc
Imports ViewToPdfMVCSample.Models
Namespace ViewToPdfMVCSample.Controllers
Public Class HomeController
Inherits Controller
Public Function Index() As ActionResult
Return View()
End Function
' GET: Person
Public Function Persons() As ActionResult
' Create a list of Person objects
'INSTANT VB NOTE: The local variable persons was renamed since Visual Basic will not allow local variables with the same name as their enclosing function or property:
Dim persons_Conflict = New List(Of Person) From {
New Person With {
.Name = "Alice",
.Title = "Mrs.",
.Description = "Software Engineer"
},
New Person With {
.Name = "Bob",
.Title = "Mr.",
.Description = "Software Engineer"
},
New Person With {
.Name = "Charlie",
.Title = "Mr.",
.Description = "Software Engineer"
}
}
If HttpContext.Request.HttpMethod = "POST" Then
' Define the path to the View file
Dim viewPath = "~/Views/Home/Persons.cshtml"
' Instantiate the ChromePdfRenderer
Dim renderer As New ChromePdfRenderer()
' Render the view to a PDF document
Dim pdf As PdfDocument = renderer.RenderView(Me.HttpContext, viewPath, persons_Conflict)
' Set headers to view the PDF in-browser
Response.Headers.Add("Content-Disposition", "inline")
' Return the generated PDF file
Return File(pdf.BinaryData, "application/pdf")
End If
Return View(persons_Conflict)
End Function
Public Function About() As ActionResult
ViewBag.Message = "Your application description page."
Return View()
End Function
Public Function Contact() As ActionResult
ViewBag.Message = "Your contact page."
Return View()
End Function
End Class
End NamespacePDFレンダリングオプションをどのようにカスタマイズできますか?
より高度なシナリオでは、さまざまなレンダリングオプションを使用してPDF出力をカスタマイズできます。 以下は、余白、用紙サイズ、その他の設定をカスタマイズした例です:
// Advanced rendering with custom options
public ActionResult PersonsAdvanced()
{
var persons = GetPersonsList();
if (HttpContext.Request.HttpMethod == "POST")
{
var viewPath = "~/Views/Home/Persons.cshtml";
// Configure the renderer with custom options
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Set custom rendering options
renderer.RenderingOptions.MarginTop = 40;
renderer.RenderingOptions.MarginBottom = 40;
renderer.RenderingOptions.MarginLeft = 20;
renderer.RenderingOptions.MarginRight = 20;
// Set custom paper size
renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.A4;
renderer.RenderingOptions.PaperOrientation = IronPdf.Rendering.PdfPaperOrientation.Portrait;
// Add header and footer
renderer.RenderingOptions.TextHeader.DrawDividerLine = true;
renderer.RenderingOptions.TextHeader.CenterText = "{pdf-title}";
renderer.RenderingOptions.TextHeader.Font = IronPdf.Font.FontTypes.Helvetica;
renderer.RenderingOptions.TextHeader.FontSize = 12;
renderer.RenderingOptions.TextFooter.DrawDividerLine = true;
renderer.RenderingOptions.TextFooter.Font = IronPdf.Font.FontTypes.Arial;
renderer.RenderingOptions.TextFooter.FontSize = 10;
renderer.RenderingOptions.TextFooter.RightText = "{page} of {total-pages}";
// Enable JavaScript execution if needed
renderer.RenderingOptions.EnableJavaScript = true;
renderer.RenderingOptions.RenderDelay = 500; // Wait for JS to execute
// Render the view to PDF
PdfDocument pdf = renderer.RenderView(this.HttpContext, viewPath, persons);
// Optional: Apply compression to reduce file size
pdf.CompressImages(60);
Response.Headers.Add("Content-Disposition", "inline");
return File(pdf.BinaryData, "application/pdf");
}
return View("Persons", persons);
}// Advanced rendering with custom options
public ActionResult PersonsAdvanced()
{
var persons = GetPersonsList();
if (HttpContext.Request.HttpMethod == "POST")
{
var viewPath = "~/Views/Home/Persons.cshtml";
// Configure the renderer with custom options
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Set custom rendering options
renderer.RenderingOptions.MarginTop = 40;
renderer.RenderingOptions.MarginBottom = 40;
renderer.RenderingOptions.MarginLeft = 20;
renderer.RenderingOptions.MarginRight = 20;
// Set custom paper size
renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.A4;
renderer.RenderingOptions.PaperOrientation = IronPdf.Rendering.PdfPaperOrientation.Portrait;
// Add header and footer
renderer.RenderingOptions.TextHeader.DrawDividerLine = true;
renderer.RenderingOptions.TextHeader.CenterText = "{pdf-title}";
renderer.RenderingOptions.TextHeader.Font = IronPdf.Font.FontTypes.Helvetica;
renderer.RenderingOptions.TextHeader.FontSize = 12;
renderer.RenderingOptions.TextFooter.DrawDividerLine = true;
renderer.RenderingOptions.TextFooter.Font = IronPdf.Font.FontTypes.Arial;
renderer.RenderingOptions.TextFooter.FontSize = 10;
renderer.RenderingOptions.TextFooter.RightText = "{page} of {total-pages}";
// Enable JavaScript execution if needed
renderer.RenderingOptions.EnableJavaScript = true;
renderer.RenderingOptions.RenderDelay = 500; // Wait for JS to execute
// Render the view to PDF
PdfDocument pdf = renderer.RenderView(this.HttpContext, viewPath, persons);
// Optional: Apply compression to reduce file size
pdf.CompressImages(60);
Response.Headers.Add("Content-Disposition", "inline");
return File(pdf.BinaryData, "application/pdf");
}
return View("Persons", persons);
}' Advanced rendering with custom options
Public Function PersonsAdvanced() As ActionResult
Dim persons = GetPersonsList()
If HttpContext.Request.HttpMethod = "POST" Then
Dim viewPath = "~/Views/Home/Persons.cshtml"
' Configure the renderer with custom options
Dim renderer As New ChromePdfRenderer()
' Set custom rendering options
renderer.RenderingOptions.MarginTop = 40
renderer.RenderingOptions.MarginBottom = 40
renderer.RenderingOptions.MarginLeft = 20
renderer.RenderingOptions.MarginRight = 20
' Set custom paper size
renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.A4
renderer.RenderingOptions.PaperOrientation = IronPdf.Rendering.PdfPaperOrientation.Portrait
' Add header and footer
renderer.RenderingOptions.TextHeader.DrawDividerLine = True
renderer.RenderingOptions.TextHeader.CenterText = "{pdf-title}"
renderer.RenderingOptions.TextHeader.Font = IronPdf.Font.FontTypes.Helvetica
renderer.RenderingOptions.TextHeader.FontSize = 12
renderer.RenderingOptions.TextFooter.DrawDividerLine = True
renderer.RenderingOptions.TextFooter.Font = IronPdf.Font.FontTypes.Arial
renderer.RenderingOptions.TextFooter.FontSize = 10
renderer.RenderingOptions.TextFooter.RightText = "{page} of {total-pages}"
' Enable JavaScript execution if needed
renderer.RenderingOptions.EnableJavaScript = True
renderer.RenderingOptions.RenderDelay = 500 ' Wait for JS to execute
' Render the view to PDF
Dim pdf As PdfDocument = renderer.RenderView(Me.HttpContext, viewPath, persons)
' Optional: Apply compression to reduce file size
pdf.CompressImages(60)
Response.Headers.Add("Content-Disposition", "inline")
Return File(pdf.BinaryData, "application/pdf")
End If
Return View("Persons", persons)
End Function' Advanced rendering with custom options
Public Function PersonsAdvanced() As ActionResult
Dim persons = GetPersonsList()
If HttpContext.Request.HttpMethod = "POST" Then
Dim viewPath = "~/Views/Home/Persons.cshtml"
' Configure the renderer with custom options
Dim renderer As New ChromePdfRenderer()
' Set custom rendering options
renderer.RenderingOptions.MarginTop = 40
renderer.RenderingOptions.MarginBottom = 40
renderer.RenderingOptions.MarginLeft = 20
renderer.RenderingOptions.MarginRight = 20
' Set custom paper size
renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.A4
renderer.RenderingOptions.PaperOrientation = IronPdf.Rendering.PdfPaperOrientation.Portrait
' Add header and footer
renderer.RenderingOptions.TextHeader.DrawDividerLine = True
renderer.RenderingOptions.TextHeader.CenterText = "{pdf-title}"
renderer.RenderingOptions.TextHeader.Font = IronPdf.Font.FontTypes.Helvetica
renderer.RenderingOptions.TextHeader.FontSize = 12
renderer.RenderingOptions.TextFooter.DrawDividerLine = True
renderer.RenderingOptions.TextFooter.Font = IronPdf.Font.FontTypes.Arial
renderer.RenderingOptions.TextFooter.FontSize = 10
renderer.RenderingOptions.TextFooter.RightText = "{page} of {total-pages}"
' Enable JavaScript execution if needed
renderer.RenderingOptions.EnableJavaScript = True
renderer.RenderingOptions.RenderDelay = 500 ' Wait for JS to execute
' Render the view to PDF
Dim pdf As PdfDocument = renderer.RenderView(Me.HttpContext, viewPath, persons)
' Optional: Apply compression to reduce file size
pdf.CompressImages(60)
Response.Headers.Add("Content-Disposition", "inline")
Return File(pdf.BinaryData, "application/pdf")
End If
Return View("Persons", persons)
End Functionマージンを最適化する方法については、カスタムマージンの設定に関するガイドをご覧ください。 特定の用紙サイズで作業する必要がある場合は、カスタム用紙サイズのドキュメントを参照してください。
生成されたPDFで何ができますか?
PdfDocument オブジェクトを RenderView メソッドを通じて取得した後、それに対して様々な改善や調整を行うことができます。 PDFを PDFA または PDFUA フォーマットに変換し、作成されたPDFにデジタル署名を適用したり、PDFドキュメントを結合および分割したりすることができます。 このライブラリを使用すると、ページを回転させたり、注釈やブックマークを挿入したり、PDFファイルに異なるウォーターマークを適用したりできます。
ファイルサイズの最適化をするには、PDF圧縮テクニックの使用を検討してください。 JavaScriptを多用したコンテンツを扱う際には、カスタムレンダリング遅延の処理に関する詳しい情報を提供するJavaScriptレンダリングガイドをご参照ください。 様々なエクスポートオプションについては、PDFドキュメントの保存とエクスポートに関するガイドをご覧ください。
ビューを追加するにはどうすればよいですか?
ビューを作成するためにどのステップを踏むべきですか?
-
新しく追加されたPersonアクションを右クリックし、「ビューを追加」を選択します。

-
新しいスキャフォールド アイテムには「MVC 5 ビュー」を選択します。

-
「List」テンプレートと
Personモデルクラスを選択します。
これにより、"Persons "という名前の.cshtmlファイルが作成されます。
ビューに印刷ボタンをどのように追加しますか?
- "Views"フォルダ -> "Home"フォルダ -> "Persons.cshtml"ファイルに移動します。
以下のコードを使用して、Persons アクションを呼び出すボタンを追加します:
@using (Html.BeginForm("Persons", "Home", FormMethod.Post))
{
<input type="submit" value="Print Person" />
}
トップナビゲーションバーにセクションを追加するにはどうすればよいですか?
ナビゲーションはどこで更新すべきですか?
- 「Views」フォルダーで、「Shared」フォルダー -> "_Layout.cshtml" ファイルに移動します。ナビゲーション項目「Person」を「Home」の後に配置します。
ActionLink メソッドの値が、ファイル名「Persons」と完全に一致していることを確認してください。
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-dark bg-dark">
<div class="container">
@Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
<button type="button" class="navbar-toggler" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" title="Toggle navigation" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li>@Html.ActionLink("Home", "Index", "Home", new { area = "" }, new { @class = "nav-link" })</li>
<li>@Html.ActionLink("Persons", "Persons", "Home", new { area = "" }, new { @class = "nav-link" })</li>
<li>@Html.ActionLink("About", "About", "Home", new { area = "" }, new { @class = "nav-link" })</li>
<li>@Html.ActionLink("Contact", "Contact", "Home", new { area = "" }, new { @class = "nav-link" })</li>
</ul>
</div>
</div>
</nav>
プロジェクトを実行してテストするにはどうすればいいですか?
プロジェクトを実行する
これは、プロジェクトを実行し、PDFドキュメントを生成する方法を示しています。
出力PDF
完全なプロジェクトをどこでダウンロードできますか?
サンプルプロジェクトには何が含まれていますか?
このガイドの完全なコードをダウンロードできます。ASP.NET Web Application (.NET Framework) MVCプロジェクトとしてVisual Studioで開くことができるzipファイルとして提供されます。 サンプルには、MVCアプリケーションでPDF生成をすぐに始められるように、必要な構成、モデルクラス、コントローラ、ビューがすべて含まれています。
よくある質問
ASP.NET MVCでCSHTMLビューをPDFに変換する方法を教えてください。
ASP.NETのMVCでIronPDFのChromePdfRenderer.RenderView()メソッドを使ってCSHTMLビューをPDFに変換することができます。IronPdf.Extensions.Mvc.Frameworkパッケージをインストールし、レンダリングメソッドを使用するだけで、数行のコードでビューを高品質なPDFドキュメントに変換できます。
ビューをPDFとしてレンダリングするために必要な最小限のコードは何ですか?
ビューをPDFとしてレンダリングするための最小限のコードは次の通りです: var pdf = new IronPdf.ChromePdfRenderer.RenderRazorToPdf(this.ControllerContext); IronPDFを使ったこの一行のコードで、現在のビューがPDFドキュメントに変換されます。
ASP.NET MVC PDF生成にはどの拡張パッケージが必要ですか。
ASP.NET MVCアプリケーションには、IronPdf.Extensions.Mvc.Frameworkパッケージが必要です。このエクステンションはASP.NET MVCプロジェクトとのシームレスな統合を提供し、IronPDFのメインパッケージと連携してビューからPDFへの変換機能を実現します。
ビューをPDFに変換するために使用されるレンダリングエンジンは何ですか?
IronPDFはChrome PDFレンダリングエンジンを使用しており、ビューをPDFに変換する際にピクセルパーフェクトな精度を保証します。このエンジンは元のCSHTMLビューのスタイル、レイアウト、インタラクティブ要素を最終的なPDF出力で維持します。
MVCビューから請求書やレポートを作成できますか?
IronPDFはMVCビューから請求書やレポート、その他のドキュメントを生成するのに最適です。このライブラリはProfessionalなPDF出力機能を提供し、Webアプリケーションのビューから直接ビジネス文書を作成するのに理想的です。
ビューからPDFへの変換を実装するための基本的な手順は何ですか?
基本的な実装には5つのステップがあります:1) IronPDFライブラリのダウンロードとインストール、2) データのモデルクラスの追加、3) RenderViewメソッドを使用したコントローラアクションの作成、4) MVC 5 View Scaffoldingを使用したビューの追加、5) IronPDFのレンダリングメソッドを使用した変換の実行。
PDF出力は元のビューのスタイルを維持しますか?
IronPDFのChromeレンダリングエンジンは、CSHTMLビューのすべてのCSSスタイル、レイアウト、インタラクティブ要素をPDF出力に保持します。これにより、ピクセルパーフェクトな精度を提供し、元のウェブビューの視覚的整合性を維持します。
What additional features can IronPDF offer for PDF enhancements?
IronPDF offers features like converting PDFs to PDFA or PDFUA, merging or splitting PDF documents, rotating pages, adding annotations or bookmarks, and applying watermarks.
How can I optimize PDF sizes using IronPDF?
You can optimize PDF sizes using IronPDF's compression techniques, which allow for reduced file sizes while maintaining quality.
Where can I find a sample project for PDF conversion in ASP.NET MVC?
You can download a complete sample project from the IronPDF website, which includes all necessary configurations to help you quickly start with PDF generation in ASP.NET MVC applications.
Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。