// 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 두 패키지는 함께 작동하여 뷰(View)를 PDF로 렌더링할 수 있게 합니다. IronPdf.Extensions.Mvc.Core 패키지는 IronPdf의 확장 기능으로, 뷰(View)를 PDF로 렌더링할 수 있게 해줍니다.
뷰를 PDF로 렌더링할 때는 RenderRazorViewToPdf 메서드를 사용하십시오. 이 방법에는 IRazorViewRenderer, ".cshtml" 파일의 경로, 그리고 ".cshtml" 파일에 표시할 데이터가 필요합니다. 자세한 내용은 ASP.NET Core MVC에서 뷰를 PDF로 변환하는 방법 안내 문서를 참조하십시오.
또한 이 작업을 통해 RenderingOptions 클래스가 제공하는 모든 기능을 활용할 수 있습니다. 예를 들어 IronPDF를 사용하여 PDF에 페이지 번호를 적용하거나, 텍스트 및 HTML 머리글과 바닥글을 추가하거나, PDF 용지 크기를 사용자 지정하는 등의 작업이 가능합니다. 생성된 PDF 문서는 필요에 따라 추가로 편집하거나 내보낼 수 있습니다.