// PM > Install-Package IronPdf.Extensions.Mvc.Core
public async Task<IActionResult> Persons()
{
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 (_httpContextAccessor.HttpContext.Request.Method == HttpMethod.Post.Method)
{
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Render View to PDF document
PdfDocument pdf = renderer.RenderRazorViewToPdf(_viewRenderService, "Views/Home/Persons.cshtml", persons);
Response.Headers.Add("Content-Disposition", "inline");
// Output PDF document
return File(pdf.BinaryData, "application/pdf", "viewToPdfMVCCore.pdf");
}
return View(persons);
}
' PM > Install-Package IronPdf.Extensions.Mvc.Core
Public Async Function Persons() As Task(Of IActionResult)
'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 _httpContextAccessor.HttpContext.Request.Method = HttpMethod.Post.Method Then
Dim renderer As New ChromePdfRenderer()
' Render View to PDF document
Dim pdf As PdfDocument = renderer.RenderRazorViewToPdf(_viewRenderService, "Views/Home/Persons.cshtml", persons_Conflict)
Response.Headers.Add("Content-Disposition", "inline")
' Output PDF document
Return File(pdf.BinaryData, "application/pdf", "viewToPdfMVCCore.pdf")
End If
Return View(persons_Conflict)
End Function
Install-Package IronPdf
CSHTML을 PDF로 변환(MVC 코어)
이 코드 예제는 뷰를 PDF로 변환하는 과정을 보여줍니다.
두 패키지, IronPdf.Extensions.Mvc.Core와 IronPdf,는 뷰를 PDF로 렌더링할 수 있도록 함께 작동합니다. IronPdf.Extensions.Mvc.Core 패키지는 IronPdf에 대한 확장 기능으로서 뷰를 PDF로 렌더링할 수 있게 합니다.
뷰를 PDF로 렌더링하려면 RenderRazorViewToPdf 메서드를 사용하세요. 이 메서드에는 IRazorViewRenderer, ".cshtml" 파일 경로 및 ".cshtml" 파일에 표시할 데이터가 필요합니다. 더 많은 정보를 얻기 위해 ASP.NET Core MVC에서 뷰를 PDF로 변환하는 방법 문서를 방문하십시오.