IronPDF 开始 部署到Azure How to Run & Deploy IronPDF .NET on Azure Function Curtis Chau 已更新:八月 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 class="container-fluid"> class="row"> class="col-md-2"> 是的。 可以使用IronPDF在Azure上生成、操作和读取PDF文档。 IronPDF在包括MVC网站、Azure功能等多个Azure平台上经过了彻底测试。 class="hsg-featured-snippet"> 如何在Azure Function中将HTML转换为PDF 安装C#库以在Azure功能中转换HTML为PDF 选择Azure基本B1托管层或更高级别 发布时取消选中从包文件运行选项 按照推荐的配置说明进行操作 使用代码示例在Azure上创建PDF生成器 class="main-content__segment-title">如何教程 安装IronPdf包 Azure功能应用程序有三个不同的环境:Linux、Windows和容器。 本文解释了如何在这三种环境中设置IronPdf。 其中,推荐Azure功能应用程序容器,因为它提供了一个隔离的环境。 首先,让我们选择适当的安装包。 Azure功能应用程序容器 Azure功能应用程序容器涉及的麻烦最少,是部署IronPdf的推荐方式。 IronPdf.Linux包 data-bs-title="已复制到剪贴板"> Install-Package IronPdf.Linux 配置Docker文件 根据您正在使用的Linux发行版配置Docker文件。 有关详细说明,请参阅本文。 Azure功能应用程序(Windows) 要使用标准IronPdf包,确保取消选中从包文件运行选项。 启用此选项会将项目作为ZIP文件部署,这会干扰IronPdf的文件配置。 如果您希望启用从包文件运行选项,请安装IronPdf.Slim包。 IronPdf包 Install-Package IronPdf class="content-img-align-center"> class="center-image-wrapper"> Azure功能应用程序(Linux) 对于Azure功能应用程序(Linux),项目默认作为ZIP文件部署,且无法禁用此行为。 这类似于在Azure功能应用程序(Windows)上启用从包文件运行选项。 IronPdf.Slim包 data-bs-title="已复制到剪贴板"> Install-Package IronPdf.Slim <hr 选择正确的Azure选项 选择正确的托管层 Azure基础B1是我们最终用户渲染需求的最低托管级别。 如果您正在创建一个高吞吐量系统,可能需要进行升级。 警告注意:若未选择应用服务计划的计划类型,可能导致IronPdf无法渲染PDF文档。 class="content-img-align-center"> class="center-image-wrapper"> .NET 6的配置 微软最近从.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.AppContext.SetSwitch("System.Drawing.EnableUnixSupport", true); System.AppContext.SetSwitch("System.Drawing.EnableUnixSupport", true); System.AppContext.SetSwitch("System.Drawing.EnableUnixSupport", True) $vbLabelText $csharpLabel <hr Azure Function代码示例 此示例正在将HTML转换为PDF,并自动将日志条目输出到内置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"; // Enable logging IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.Custom; IronPdf.Logging.Logger.CustomLogger = log; // Configure IronPdf settings IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig = true; IronPdf.Installation.AutomaticallyDownloadNativeBinaries = true; IronPdf.Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Disabled; IronPdf.Installation.CustomDeploymentDirectory = "/tmp"; try { log.LogInformation("About to render PDF..."); ChromePdfRenderer renderer = new ChromePdfRenderer(); // Render PDF from a URL var pdf = renderer.RenderUrlAsPdf("https://www.google.com/"); log.LogInformation("Finished rendering PDF..."); return new FileContentResult(pdf.BinaryData, "application/pdf") { FileDownloadName = "google.pdf" }; } catch (Exception e) { log.LogError(e, "Error while rendering PDF"); return new OkObjectResult($"Error while rendering PDF: {e}"); } } [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"; // Enable logging IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.Custom; IronPdf.Logging.Logger.CustomLogger = log; // Configure IronPdf settings IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig = true; IronPdf.Installation.AutomaticallyDownloadNativeBinaries = true; IronPdf.Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Disabled; IronPdf.Installation.CustomDeploymentDirectory = "/tmp"; try { log.LogInformation("About to render PDF..."); ChromePdfRenderer renderer = new ChromePdfRenderer(); // Render PDF from a URL var pdf = renderer.RenderUrlAsPdf("https://www.google.com/"); log.LogInformation("Finished rendering PDF..."); return new FileContentResult(pdf.BinaryData, "application/pdf") { FileDownloadName = "google.pdf" }; } catch (Exception e) { log.LogError(e, "Error while rendering PDF"); return new OkObjectResult($"Error while rendering PDF: {e}"); } } <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" ' Enable logging IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.Custom IronPdf.Logging.Logger.CustomLogger = log ' Configure IronPdf settings IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig = True IronPdf.Installation.AutomaticallyDownloadNativeBinaries = True IronPdf.Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Disabled IronPdf.Installation.CustomDeploymentDirectory = "/tmp" Try log.LogInformation("About to render PDF...") Dim renderer As New ChromePdfRenderer() ' Render PDF from a URL Dim pdf = renderer.RenderUrlAsPdf("https://www.google.com/") log.LogInformation("Finished rendering PDF...") Return New FileContentResult(pdf.BinaryData, "application/pdf") With {.FileDownloadName = "google.pdf"} Catch e As Exception log.LogError(e, "Error while rendering PDF") Return New OkObjectResult($"Error while rendering PDF: {e}") End Try End Function $vbLabelText $csharpLabel 在Visual Studio中使用Azure Function模板创建项目可能导致代码略有不同。 由于这些差异,即使安装了相同的软件包,一个项目可能会工作,而另一个则不会。 如果出现这种情况,请将CustomDeploymentDirectory属性设置为"/tmp"。 了解每个安装配置 LinuxAndDockerDependenciesAutoConfig:此设置检查并尝试下载Chrome引擎所需的所有依赖项。当使用非GUI系统(如Linux)时,需要此设置。 在容器系统中,依赖项通常列在Dockerfile中;因此,您可以将此设置为false。 AutomaticallyDownloadNativeBinaries:此选项在运行时下载本地Chrome二进制文件。当使用IronPdf.Slim包时需要此选项。 CustomDeploymentDirectory:此设置适用于写入权限有限的系统。 <hr 已知问题 共享托管计划上不支持SVG字体渲染 我们发现的一个限制是Azure 托管平台不支持在其较便宜的共享web应用程序层加载SVG字体,如Google字体。 这是因为这些共享托管平台出于安全原因不允许访问Windows GDI+图形对象。 我们建议使用Windows或Linux Docker容器或可能在Azure上使用VPS,来解决在需要最佳字体渲染的问题。 Azure免费层托管速度慢 Azure的免费和共享层以及消费计划不适合PDF渲染。 我们推荐Azure B1托管/高级计划,这也是我们自己使用的。 HTML转PDF的过程对于任何计算机而言都是重要的“工作”——类似于在您自己的机器上打开和渲染网页。使用的是一个真实的浏览器引擎,因此我们需要做好相应的准备,并期望与相似性能的桌面计算机相似的渲染时间。 创建工程支持请求工单 为了创建请求工单,请参阅'如何为IronPDF提出工程支持请求'指南 常见问题解答 如何在 Azure 上托管一个 PDF 生成库? 您可以通过设置 Azure 功能或 MVC 网站来托管类似 IronPDF 的 PDF 生成库。确保您有必要的 NuGet 包安装,并根据库的要求配置您的环境。 哪些 Azure 环境与 PDF 库兼容? IronPDF 兼容多个 Azure 环境,包括 MVC 网站和 Azure Functions。它被设计为在 Azure 提供的不同平台上无缝运行。 PDF 库在 Azure 上的托管要求是什么? 为确保在 Azure 上使用 IronPDF 时的最佳性能,建议至少使用 Azure Basic B1 托管层。这可确保有足够的资源来有效呈现 PDF。 如何在 Linux 上为 Azure 功能应用设置 PDF 库? 要在 Linux 上为 Azure 功能应用设置 IronPDF,请安装 IronPdf.Slim 包。将您的项目部署为 ZIP 文件,并确保所有配置正确设置以适应Linux 环境。 .NET 6 在 Azure 上使用 PDF 库时需要哪些配置? 在 Azure 上使用 .NET 6 的 IronPDF 时,请更新项目设置以允许旧版 API 调用。将 Installation.LinuxAndDockerDependenciesAutoConfig=true 设置,并在项目文件中包含必要的配置。 为什么推荐在 Azure 上进行 PDF 呈现时使用 Docker 容器? 建议在 Azure 上进行 PDF 呈现时使用 Docker 容器,因为它提供了更受控的环境,支持更好的字体呈现,避免了共享托管计划的限制。 什么可能导致 Azure 免费层的 PDF 渲染速度缓慢? Azure 免费层的 PDF 渲染速度缓慢是由于计算资源有限。该过程需要大量计算能力,类似于渲染一个网页,使 B1 或 Premium 这样更高等级的计划更为合适。 如何排除在 Azure 功能项目中 PDF 库不起作用的问题? 如果您的 Azure 功能项目中的 IronPDF 无法运行,请检查 CustomDeploymentDirectory 属性是否设置为 '/tmp',并确保所有必要的包和配置已正确安装和设置。 在 Azure 上部署 PDF 库有哪些支持选项? 要获得在 Azure 上部署 IronPDF 的支持,请访问 IronPDF 网站上的“如何为 IronPDF 提交工程支持请求”指南以获取详细帮助。 Curtis Chau 立即与工程团队聊天 技术作家 Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。 准备开始了吗? Nuget 下载 16,154,058 | 版本: 2025.11 刚刚发布 免费 NuGet 下载 总下载量:16,154,058 查看许可证