IronPDF 操作指南 PDF生成Azure支持 How to Run HTML to PDF with .NET on Azure? Curtis Chau 更新日期:8月 20, 2025 Download IronPDF NuGet 下載 DLL 下載 Windows 安裝程式 Start Free Trial Copy for LLMs Copy for LLMs Copy page as Markdown for LLMs Open in ChatGPT Ask ChatGPT about this page Open in Gemini Ask Gemini about this page Open in Grok Ask Grok about this page Open in Perplexity Ask Perplexity about this page Share Share on Facebook Share on X (Twitter) Share on LinkedIn Copy URL Email article This article was translated from English: Does it need improvement? Translated View the article in English 是的。 IronPDF 可以用于在 Azure 上生成、操作和读取 PDF 文档。 IronPDF 已经在多个 Azure 平台上经过全面测试,包括 MVC 网站、Azure Functions 等。 如果您在 Docker 容器中运行 Azure Functions,请改为参考本 Azure Docker Linux 教程。 快速入门:在 Azure 上使用 IronPDF 进行 HTML 转 PDF 转换 使用 IronPDF 在您的 Azure 应用程序中轻松开始将 HTML 转换为 PDF。 此快速指南演示了如何使用 IronPDF 高效的 API 方法将 URL 渲染为 PDF 文档。 对于希望将 PDF 功能集成到 Azure 解决方案中的开发人员来说,这个示例展示了 IronPDF 的简单性和速度,确保您的 PDF 生成任务无缝且节省时间。 按照示例开始生成 PDF 而不丢失格式,并在短时间内让您的 Azure 项目启动并运行。 Get started making PDFs with NuGet now: Install IronPDF with NuGet Package Manager PM > Install-Package IronPdf Copy and run this code snippet. var pdf = new IronPdf.ChromePdfRenderer() .RenderHtmlAsPdf("<h1>Hello Azure!</h1>") .SaveAs("output‑azure.pdf"); Deploy to test on your live environment Start using IronPDF in your project today with a free trial Free 30 day Trial class="hsg-featured-snippet"> 最小工作流程(5 步) 安装 C# 库以在 Azure 中生成 PDF 选择 Azure 基本 B1 托管层或更高 发布时取消选中从包文件运行选项 按照推荐的配置说明进行操作 使用代码示例创建 PDF 生成器,使用 Azure class="main-content__segment-title">操作教程 设置您的项目 安装 IronPDF 以开始使用 第一步是使用 NuGet 安装 IronPDF: 在基于 Windows 的 Azure Functions 上使用IronPdf包 - Windows 的 NuGet IronPdf 包 在基于 Linux 的 Azure Functions 上使用IronPdf.Linux包 - Linux 的 NuGet IronPdf 包 Install-Package IronPdf 或者,通过使用IronPDF Azure 直接下载包链接手动安装 .dll。 选择正确的 Azure 选项 选择正确的托管等级 Azure 层 Azure Basic B1 是我们终端用户渲染需求的最低托管等级。 如果您正在创建高吞吐量系统,可能需要升级。 警告未能选择应用服务计划类型的计划可能导致 IronPdf 无法渲染 PDF 文档。 class="content-img-align-center"> class="center-image-wrapper"> "从包文件运行"复选框 在发布您的 Azure Functions 应用程序时,请确保从包文件运行未被选择。 class="content-img-align-center"> class="center-image-wrapper"> .NET 6 的配置 最近,Microsoft 从 .NET 6+ 中移除了成像库,破坏了许多旧的 API。因此,有必要配置您的项目以仍然允许这些旧 API 调用。 在 Linux 上,设置Installation.LinuxAndDockerDependenciesAutoConfig=true;以确保在机器上安装libgdiplus 将以下内容添加到您的 .NET 6 项目的 .csproj 文件中: <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> XML 在您的项目中创建一个名为runtimeconfig.template.json的文件,并使用以下内容填充它: { "configProperties": { "System.Drawing.EnableUnixSupport": true } } 最后,在您的程序开头添加以下行以启用 System.Drawing 的Unix支持: System.AppContext.SetSwitch("System.Drawing.EnableUnixSupport", true); System.AppContext.SetSwitch("System.Drawing.EnableUnixSupport", true); System.AppContext.SetSwitch("System.Drawing.EnableUnixSupport", True) $vbLabelText $csharpLabel 在 Azure 上使用 Docker 在 Azure 上获得控件、SVG 字体访问和性能控制的一种方法是从 Docker 容器中使用 IronPDF 应用程序和 Functions。 我们有一个全面的IronPDF Azure Docker 教程,适用于 Linux 和 Windows 实例,推荐阅读。 Azure Function 代码示例 此示例会自动将日志条目输出到内置的 Azure 记录器(见ILogger log): [FunctionName("PrintPdf")] public static async Task<IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log, ExecutionContext context) { log.LogInformation("Entered PrintPdf API function..."); // Apply license key IronPdf.License.LicenseKey = "IRONPDF-MYLICENSE-KEY-1EF01"; // Configure logging IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.Custom; IronPdf.Logging.Logger.CustomLogger = log; IronPdf.Logging.Logger.EnableDebugging = false; // Configure IronPdf settings Installation.LinuxAndDockerDependenciesAutoConfig = false; Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Disabled; try { log.LogInformation("About to render pdf..."); // Create a renderer and render the URL as PDF ChromePdfRenderer renderer = new ChromePdfRenderer(); var pdf = renderer.RenderUrlAsPdf("https://www.google.com/"); log.LogInformation("Finished rendering pdf..."); // Return the rendered PDF as a file download return new FileContentResult(pdf.BinaryData, "application/pdf") { FileDownloadName = "google.pdf" }; } catch (Exception e) { log.LogError(e, "Error while rendering pdf"); } return new OkObjectResult("OK"); } [FunctionName("PrintPdf")] public static async Task<IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log, ExecutionContext context) { log.LogInformation("Entered PrintPdf API function..."); // Apply license key IronPdf.License.LicenseKey = "IRONPDF-MYLICENSE-KEY-1EF01"; // Configure logging IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.Custom; IronPdf.Logging.Logger.CustomLogger = log; IronPdf.Logging.Logger.EnableDebugging = false; // Configure IronPdf settings Installation.LinuxAndDockerDependenciesAutoConfig = false; Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Disabled; try { log.LogInformation("About to render pdf..."); // Create a renderer and render the URL as PDF ChromePdfRenderer renderer = new ChromePdfRenderer(); var pdf = renderer.RenderUrlAsPdf("https://www.google.com/"); log.LogInformation("Finished rendering pdf..."); // Return the rendered PDF as a file download return new FileContentResult(pdf.BinaryData, "application/pdf") { FileDownloadName = "google.pdf" }; } catch (Exception e) { log.LogError(e, "Error while rendering pdf"); } return new OkObjectResult("OK"); } <FunctionName("PrintPdf")> Public Shared Async Function Run(<HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route := Nothing)> ByVal req As HttpRequest, ByVal log As ILogger, ByVal context As ExecutionContext) As Task(Of IActionResult) log.LogInformation("Entered PrintPdf API function...") ' Apply license key IronPdf.License.LicenseKey = "IRONPDF-MYLICENSE-KEY-1EF01" ' Configure logging IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.Custom IronPdf.Logging.Logger.CustomLogger = log IronPdf.Logging.Logger.EnableDebugging = False ' Configure IronPdf settings Installation.LinuxAndDockerDependenciesAutoConfig = False Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Disabled Try log.LogInformation("About to render pdf...") ' Create a renderer and render the URL as PDF Dim renderer As New ChromePdfRenderer() Dim pdf = renderer.RenderUrlAsPdf("https://www.google.com/") log.LogInformation("Finished rendering pdf...") ' Return the rendered PDF as a file download Return New FileContentResult(pdf.BinaryData, "application/pdf") With {.FileDownloadName = "google.pdf"} Catch e As Exception log.LogError(e, "Error while rendering pdf") End Try Return New OkObjectResult("OK") End Function $vbLabelText $csharpLabel 已知问题 SVG 字体渲染在共享托管计划中不可用 一个限制是Azure 托管平台概述不支持在其较便宜的共享 web 应用程序层上加载 SVG 字体(如 Google 字体)的服务器。 这是由于安全限制阻止了对 Windows GDI+ 图形对象的访问。 我们建议使用Windows 或 Linux Docker 容器指南用于 IronPDF或可能在 Azure 上使用 VPS,以应对此问题,在这里需要最佳字体渲染。 Azure 免费层托管很慢 Azure 免费和共享层以及消耗计划不适合 PDF 渲染。 我们推荐 Azure B1 托管/高级计划,也是我们自己使用的。 HTML 到 PDF的过程是任何计算机的重大'工作'——类似于在您自己的计算机上打开和渲染网页。使用真实的浏览器引擎,因此我们需要相应地进行规划,并期望渲染时间类似于具有类似功率的台式机。 创建工程支持请求票证 为了创建请求票证,请参考如何为 IronPDF 创建工程支持请求指南。 常見問題解答 我如何在Azure上用C#將HTML轉換為PDF? 您可以使用IronPDF通過RenderHtmlAsPdf方法在您的Azure應用中將HTML轉換為PDF。這可以讓您在生成的PDF中保持HTML內容的格式。 在Azure Functions上部署PDF生成的最佳實踐是什麼? 在使用IronPDF部署Azure Functions中的PDF生成時,請確保通過NuGet安裝庫,並在發布過程中避免選擇“從包文件運行”選項。這可以幫助防止常見的部署問題。 我可以在Azure上使用.NET 6的IronPDF嗎? 是的,您可以在Azure上使用IronPDF與.NET 6。將<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>添加到您的.csproj文件中,並創建一個將'System.Drawing.EnableUnixSupport'設置為true的runtimeconfig.template.json文件。 推薦的Azure托管級別是什麼,以獲得最佳的PDF渲染性能? 為了在Azure上使用IronPDF獲得最佳的PDF渲染性能,建議至少使用Azure Basic B1托管級別,或者為高吞吐量系統升級到更高級別。 在Azure的共享託管計劃中使用IronPDF有什麼限制嗎? 是的,在Azure的較便宜的共享托管計劃中不提供SVG字體渲染。為了獲得更好的字體渲染和性能,使用Windows或Linux Docker容器或Azure上的VPS。 如何提高Azure免費層的PDF渲染性能? 為了提高超出Azure免費層限制的PDF渲染性能,考慮升級到Azure Basic B1托管級別或更高級別。這可以緩解免費層所產生的性能瓶頸。 在Azure上使用IronPDF時已知的問題有哪些? 已知問題包括共享托管計劃中的SVG字體渲染限制和Azure的免費層托管中的性能問題。使用Docker容器可以幫助緩解這些問題。 我如何使用Docker運行Azure Functions以生成PDF? 您可以將Azure Functions部署在Docker容器內,以在使用IronPDF生成PDF時獲得更好的性能和控制。請參閱Azure Docker Linux教程以獲取更多詳細信息。 我如何尋求用於Azure上的IronPDF的技術支持? 為了在Azure上為IronPDF尋求技術支持,您可以遵循在IronPDF網站上提供的“如何為IronPDF提出工程支持請求”的指導。 當在Azure上使用Docker時,可以訪問SVG字體嗎? 是的,使用Azure上的Docker可以訪問SVG字體,這提高了使用IronPDF生成的PDF的渲染性能和質量。 Curtis Chau 立即與工程團隊聊天 技術作家 Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。 準備好開始了嗎? Nuget 下載 16,154,058 | 版本: 2025.11 剛剛發布 免費 NuGet 下載 總下載量:16,154,058 查看許可證