Blazor Server와 WebAssembly 비교
IronPDF Blazor Server 및 Blazor WebAssembly(WASM)를 지원합니까?
IronPDF Blazor Server는 지원하지만 Blazor WebAssembly(WASM)는 지원하지 않습니다.
Blazor Server에 PDF를 저장하려면 PDF 문서 스트림을 바이트 배열로 변환한 다음, 이 배열을 JavaScript 함수에 전달하여 다운로드를 수행해야 합니다.
다음은 Blazor Server 애플리케이션에서 PDF 문서를 바이트 배열로 변환한 다음 JavaScript 사용하여 다운로드를 트리거하는 방법의 예입니다.
@page "/pdfdownload"
@inject IJSRuntime JSRuntime
@* A button to download the PDF *@
<button @onclick="DownloadPDF">Download PDF</button>
@code {
private async Task DownloadPDF()
{
// Create a PDF document using IronPDF (this is hypothetical code)
var renderer = new IronPdf.HtmlToPdf();
var pdfDocument = renderer.RenderHtmlAsPdf("<h1>Hello, World!</h1>");
// Convert PDF document to a byte array
byte[] pdfBytes = pdfDocument.BinaryData;
// Call the JavaScript function to download the PDF
await JSRuntime.InvokeVoidAsync("downloadFile", pdfBytes, "example.pdf");
}
}
@page "/pdfdownload"
@inject IJSRuntime JSRuntime
@* A button to download the PDF *@
<button @onclick="DownloadPDF">Download PDF</button>
@code {
private async Task DownloadPDF()
{
// Create a PDF document using IronPDF (this is hypothetical code)
var renderer = new IronPdf.HtmlToPdf();
var pdfDocument = renderer.RenderHtmlAsPdf("<h1>Hello, World!</h1>");
// Convert PDF document to a byte array
byte[] pdfBytes = pdfDocument.BinaryData;
// Call the JavaScript function to download the PDF
await JSRuntime.InvokeVoidAsync("downloadFile", pdfBytes, "example.pdf");
}
}
'INSTANT VB TODO TASK: The following line could not be converted:
page "/pdfdownload" inject IJSRuntime JSRuntime * A button [to] download the PDF * <button onclick="DownloadPDF"> Download PDF</button> code
If True Then
'INSTANT VB TODO TASK: Local functions are not converted by Instant VB:
' private async Task DownloadPDF()
' {
' ' Create a PDF document using IronPDF (this is hypothetical code)
' var renderer = New IronPdf.HtmlToPdf();
' var pdfDocument = renderer.RenderHtmlAsPdf("<h1>Hello, World!</h1>");
'
' ' Convert PDF document to a byte array
' byte[] pdfBytes = pdfDocument.BinaryData;
'
' ' Call the JavaScript function to download the PDF
' await JSRuntime.InvokeVoidAsync("downloadFile", pdfBytes, "example.pdf");
' }
End If
다음은 PDF 다운로드를 처리하는 JavaScript 함수입니다. 이것을 _Host.cshtml 또는 index.html 파일에 반드시 포함하세요:
<script>
// Function to download a file from a byte array in JavaScript
function downloadFile(fileBytes, fileName) {
// Convert byte array to a Blob
const blob = new Blob([fileBytes], { type: 'application/pdf' });
// Create a link element for downloading the file
const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = fileName;
// Append the link to the body, trigger it, and remove it afterwards
document.body.appendChild(link); // Required for Firefox
link.click();
document.body.removeChild(link);
}
</script>
<script>
// Function to download a file from a byte array in JavaScript
function downloadFile(fileBytes, fileName) {
// Convert byte array to a Blob
const blob = new Blob([fileBytes], { type: 'application/pdf' });
// Create a link element for downloading the file
const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = fileName;
// Append the link to the body, trigger it, and remove it afterwards
document.body.appendChild(link); // Required for Firefox
link.click();
document.body.removeChild(link);
}
</script>
핵심 요점:
- Blazor Server는 서버 측 작업을 허용하며 C# 코드를 서버에서 직접 실행할 수 있습니다.
- Blazor WebAssembly는 클라이언트 측에서 실행되며 IronPDF 와 같은 서버 측 리소스에 직접 접근할 수 없습니다.
저희 웹사이트에서 Blazor 서버 전체 튜토리얼을 보실 수 있습니다: Blazor 서버 튜토리얼

