IronPDF 故障排除 Blazor 服务器 / WebAssembly (WASM) Blazor Server 與 WebAssembly:對比 Curtis Chau 更新:2025年6月1日 下載 IronPDF NuGet 下載 DLL 下載 Windows Installer 開始免費試用 LLM副本 LLM副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在 Grok 中打開 向 Grok 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 This article was translated from English: Does it need improvement? Translated View the article in English IronPDF是否支援Blazor Server 和Blazor WebAssembly (WASM)? IronPDF支援Blazor Server,但不支援Blazor WebAssembly (WASM)。 要在Blazor Server 中儲存 PDF,需要將 PDF 文件流轉換為位元組數組,然後將其傳遞給JavaScript函數以方便下載。 以下範例展示如何在Blazor伺服器應用程式中將 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"); } } $vbLabelText $csharpLabel 以下是用於處理 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> JAVASCRIPT 要點: Blazor Server允許伺服器端操作,可以直接在伺服器上執行 C# 程式碼。 Blazor WebAssembly在客戶端執行,無法直接存取IronPDF等伺服器端資源。 您可以在我們的網站上查看完整的Blazor伺服器教學: Blazor伺服器教學 Curtis Chau 立即與工程團隊聊天 技術作家 Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。 準備好開始了嗎? Nuget 下載 17,803,474 | 版本: 2026.3 剛剛發布 開始免費試用 免費 NuGet 下載 總下載量:17,803,474 查看許可證 還在滾動嗎? 想快速取得證據? PM > Install-Package IronPdf 運行範例看著你的HTML程式碼變成PDF檔。 免費 NuGet 下載 總下載量:17,803,474 查看許可證