Blazor Server vs. WebAssembly: Karşılaştırma
IronPDF, Blazor Server ve Blazor WebAssembly (WASM) desteği sağlıyor mu?
IronPDF, Blazor Sunucuyu destekliyor ancak Blazor WebAssembly (WASM) için desteklemiyor.
Blazor Server'da bir PDF kaydetmek için, PDF belge akışını bir bayt dizisine dönüştürmeniz gerekir, bu da indirmeyi kolaylaştırmak için bir JavaScript fonksiyonuna aktarılır.
Bir Blazor Sunucu uygulamasında bir PDF dokümanı byte dizisine nasıl dönüştürüp JavaScript kullanarak indirimi başlatabi
@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
Aşağıda, PDF indirmesini işlemek için eşlik eden JavaScript fonksiyonu bulunmaktadır. Bunu _Host.cshtml veya index.html dosyanıza eklediğinizden emin olun:
<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>
Ana Noktalar:
- Blazor Server, sunucu tarafı işlemlerine izin verir ve C# kodunu doğrudan sunucuda çalıştırabilir.
- Blazor WebAssembly istemci tarafında çalışır ve IronPDF gibi sunucu tarafı kaynaklarına doğrudan erişime sahip değildir.
Web sitemizde tam bir Blazor Server öğreticisi görebilirsiniz: Blazor Server Eğitimi

