本指南涵盖了在Azure Functions容器内部署IronPDF for Java所需的所有内容,并从无服务器HTTP端点按需生成PDF。 由于IronPDF带有本地Chromium渲染引擎,因此必须将其打包为Docker镜像——标准的Azure Functions Zip部署无法在运行时执行IronPDF依赖的二进制文件。按照本指南,可以使一个工作中的Azure Function接受URL作为查询参数并返回一个完全渲染的PDF作为可下载的文件。

这种方法使用Microsoft推荐的Linux Azure Functions自定义容器工作流。 Maven项目提供函数代码和依赖管理。 Docker构建容器镜像,该镜像被推到注册表并由Azure Function App引用。部署后,冷启动时间是主要的性能考虑因素——随后的调用速度快且一致。

在开始之前,请确保Azure CLI、Docker Desktop、Maven 3.8+和JDK 11或JDK 17已在本地安装。 还需要一个活跃的Azure订阅,并拥有创建Function App和存储账户的权限。

快速启动:在Azure Functions上部署IronPDF for Java

下面的代码展示了完整的 RenderPdf Azure Function。 它接受 url 查询参数,并返回 PDF 字节流。 在后续章节完成 Maven 依赖项配置后,请将此内容添加到 Function.java 中。

//:path=/static-assets/pdf/content-code-examples/tutorials/azure/RenderPdf.java
import com.microsoft.azure.functions.*;
import com.ironsoftware.ironpdf.PdfDocument;
import java.util.Optional;

public class Function {

    /**
     * HTTP-triggered Azure Function: accepts a URL, renders it as a PDF,
     * and returns the PDF bytes as a downloadable attachment.
     */
    @FunctionName("RenderPdf")
    public HttpResponseMessage renderPdf(
            @HttpTrigger(
                    name = "req",
                    methods = {HttpMethod.GET, HttpMethod.POST},
                    authLevel = AuthorizationLevel.ANONYMOUS)
            HttpRequestMessage<Optional<String>> request,
            final ExecutionContext context) {

        context.getLogger().info("RenderPdf function triggered.");

        // Read the target URL from the query string
        final String url = request.getQueryParameters().get("url");

        if (url == null) {
            return request.createResponseBuilder(HttpStatus.BAD_REQUEST)
                    .body("Provide a 'url' query parameter.")
                    .build();
        }

        try {
            context.getLogger().info("Rendering URL as PDF: " + url);

            // IronPDF renders the full page including JavaScript
            PdfDocument pdf = PdfDocument.renderUrlAsPdf(url);
            byte[] pdfBytes = pdf.getBinaryData();

            return request.createResponseBuilder(HttpStatus.OK)
                    .body(pdfBytes)
                    .header("Content-Disposition", "attachment; filename=output.pdf")
                    .header("Content-Type", "application/pdf")
                    .build();

        } catch (Exception ex) {
            context.getLogger().severe("PDF rendering failed: " + ex.getMessage());
            return request.createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR)
                    .body("PDF rendering failed. Check function logs for details.")
                    .build();
        }
    }
}
//:path=/static-assets/pdf/content-code-examples/tutorials/azure/RenderPdf.java
import com.microsoft.azure.functions.*;
import com.ironsoftware.ironpdf.PdfDocument;
import java.util.Optional;

public class Function {

    /**
     * HTTP-triggered Azure Function: accepts a URL, renders it as a PDF,
     * and returns the PDF bytes as a downloadable attachment.
     */
    @FunctionName("RenderPdf")
    public HttpResponseMessage renderPdf(
            @HttpTrigger(
                    name = "req",
                    methods = {HttpMethod.GET, HttpMethod.POST},
                    authLevel = AuthorizationLevel.ANONYMOUS)
            HttpRequestMessage<Optional<String>> request,
            final ExecutionContext context) {

        context.getLogger().info("RenderPdf function triggered.");

        // Read the target URL from the query string
        final String url = request.getQueryParameters().get("url");

        if (url == null) {
            return request.createResponseBuilder(HttpStatus.BAD_REQUEST)
                    .body("Provide a 'url' query parameter.")
                    .build();
        }

        try {
            context.getLogger().info("Rendering URL as PDF: " + url);

            // IronPDF renders the full page including JavaScript
            PdfDocument pdf = PdfDocument.renderUrlAsPdf(url);
            byte[] pdfBytes = pdf.getBinaryData();

            return request.createResponseBuilder(HttpStatus.OK)
                    .body(pdfBytes)
                    .header("Content-Disposition", "attachment; filename=output.pdf")
                    .header("Content-Type", "application/pdf")
                    .build();

        } catch (Exception ex) {
            context.getLogger().severe("PDF rendering failed: " + ex.getMessage());
            return request.createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR)
                    .body("PDF rendering failed. Check function logs for details.")
                    .build();
        }
    }
}
JAVA

今天在您的项目中使用 IronPDF,免费试用。

第一步:
green arrow pointer

目录

需求条件是什么? {#prerequisites}

开始前,请确认所有必需的工具已安装,并且一个Azure订阅是活跃的。跳过这些检查常常会导致部署过程中的构建失败。

所需的本地工具

所需的Azure资源

  • 一个活跃的Azure订阅
  • 创建资源组、存储账户和Function App计划的权限
  • 一个Docker Hub账户(或者Azure容器注册表)用来托管构建的镜像

重要IronPDF for Java 在任何 Docker 容器内运行时需要 ironpdf-engine-linux-x64 构建产物。 在Azure Functions上标准的Zip部署无法执行IronPDF的本地二进制文件——Docker是唯一支持的部署方法。)}]

在继续阅读下一节之前,请运行 az login 来验证 Azure CLI 的身份。

如何设置Azure Function项目? {#set-up-project}

Microsoft指南使用自定义镜像在Linux上创建一个函数包含了完整的脚手架过程。 按照这些步骤进行,其中一个重要选择:在询问编程语言时选择Java

完成教程直到脚手架项目构建完毕,并使用Azure Functions Core Tools本地运行占位符函数。 通过以下方法进行验证:

//:path=/static-assets/pdf/content-code-examples/tutorials/azure/local-run.sh
mvn clean package
func start
//:path=/static-assets/pdf/content-code-examples/tutorials/azure/local-run.sh
mvn clean package
func start
SHELL

一旦占位符响应本地HTTP请求,项目结构即正确且准备好进行IronPDF集成。 关键文件包括 pom.xml(Maven 配置)、Function.java(函数代码)和 Dockerfile(容器定义)。

请注意Azure Functions Maven 原型会生成 host.jsonlocal.settings.json,以及 pom.xmllocal.settings.json 文件用于存储本地开发的环境变量——该文件默认不纳入源代码控制,且绝不能提交。)}]

如何将IronPDF依赖项添加到Maven项目中? {#add-IronPDF-dependencies}

IronPDF for Java通过Maven Central分发。 需要两个构建产物:提供 Java API 的核心 ironpdf 库,以及 ironpdf-engine-linux-x64(该产物打包了针对 Linux x86-64 编译的原生 Chromium 引擎)。正是引擎构建产物使得 Docker 部署成为必要——它包含必须在运行时执行的二进制文件。

打开 pom.xml,并在 <dependencies> 代码块内添加以下内容。 请将 LATEST_VERSION 替换为 Maven Central 上当前可用的版本号:

//:path=/static-assets/pdf/content-code-examples/tutorials/azure/pom.xml
<dependencies>

    <dependency>
        <groupId>com.ironsoftware</groupId>
        <artifactId>ironpdf</artifactId>
        <version>LATEST_VERSION</version>
    </dependency>

    <dependency>
        <groupId>com.ironsoftware</groupId>
        <artifactId>ironpdf-engine-linux-x64</artifactId>
        <version>LATEST_VERSION</version>
    </dependency>
</dependencies>
//:path=/static-assets/pdf/content-code-examples/tutorials/azure/pom.xml
<dependencies>

    <dependency>
        <groupId>com.ironsoftware</groupId>
        <artifactId>ironpdf</artifactId>
        <version>LATEST_VERSION</version>
    </dependency>

    <dependency>
        <groupId>com.ironsoftware</groupId>
        <artifactId>ironpdf-engine-linux-x64</artifactId>
        <version>LATEST_VERSION</version>
    </dependency>
</dependencies>
XML

两个工件必须使用同一个版本号。 ironpdfironpdf-engine-linux-x64 之间的版本不匹配,会在函数首次尝试渲染 PDF 时引发运行时异常。

在更新 pom.xml 后,请运行 mvn dependency:resolve 以验证 Maven 能否从 Central 下载这两个构建产物,再投入时间构建 Docker 镜像。

{t:(检查IronPDF for Java发行说明以获取最新的稳定版本。 使用最新的发行版可确保与最新的Chromium渲染引擎兼容,且避免已知的错误。)}]

如何编写RenderPdf函数? {#write-renderpdf-function}

RenderPdf 函数是一个由 HTTP 触发的 Azure 函数,它接受 url 查询参数,使用 IronPDF 的基于 Chromium 的引擎渲染目标页面,并将生成的 PDF 作为带有 Content-Disposition: attachment 标头的二进制响应返回。 此头告知浏览器(或HTTP客户端)下载PDF而不是内联显示。

完整的函数代码在上面的快速启动中展示。 将其放置在 src/main/java/com/example/Function.java 中,替换或扩展由 Maven 原型生成的占位符。

//:path=/static-assets/pdf/content-code-examples/tutorials/azure/RenderPdf-annotated.java
import com.microsoft.azure.functions.*;
import com.ironsoftware.ironpdf.PdfDocument;
import java.util.Optional;

public class Function {

    @FunctionName("RenderPdf")
    public HttpResponseMessage renderPdf(
            @HttpTrigger(
                    name = "req",
                    methods = {HttpMethod.GET, HttpMethod.POST},
                    authLevel = AuthorizationLevel.ANONYMOUS)
            HttpRequestMessage<Optional<String>> request,
            final ExecutionContext context) {

        // Log each invocation for Azure Monitor / Application Insights
        context.getLogger().info("RenderPdf triggered.");

        final String url = request.getQueryParameters().get("url");

        // Return 400 if no URL was supplied
        if (url == null) {
            return request.createResponseBuilder(HttpStatus.BAD_REQUEST)
                    .body("Provide a 'url' query parameter.")
                    .build();
        }

        try {
            // renderUrlAsPdf launches Chromium, loads the page, and captures it as PDF
            PdfDocument pdf = PdfDocument.renderUrlAsPdf(url);

            // getBinaryData returns the raw PDF bytes ready for transmission
            byte[] pdfBytes = pdf.getBinaryData();

            return request.createResponseBuilder(HttpStatus.OK)
                    .body(pdfBytes)
                    .header("Content-Disposition", "attachment; filename=output.pdf")
                    .header("Content-Type", "application/pdf")
                    .build();

        } catch (Exception ex) {
            context.getLogger().severe("Rendering error: " + ex.getMessage());
            return request.createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR)
                    .body("PDF rendering failed.")
                    .build();
        }
    }
}
//:path=/static-assets/pdf/content-code-examples/tutorials/azure/RenderPdf-annotated.java
import com.microsoft.azure.functions.*;
import com.ironsoftware.ironpdf.PdfDocument;
import java.util.Optional;

public class Function {

    @FunctionName("RenderPdf")
    public HttpResponseMessage renderPdf(
            @HttpTrigger(
                    name = "req",
                    methods = {HttpMethod.GET, HttpMethod.POST},
                    authLevel = AuthorizationLevel.ANONYMOUS)
            HttpRequestMessage<Optional<String>> request,
            final ExecutionContext context) {

        // Log each invocation for Azure Monitor / Application Insights
        context.getLogger().info("RenderPdf triggered.");

        final String url = request.getQueryParameters().get("url");

        // Return 400 if no URL was supplied
        if (url == null) {
            return request.createResponseBuilder(HttpStatus.BAD_REQUEST)
                    .body("Provide a 'url' query parameter.")
                    .build();
        }

        try {
            // renderUrlAsPdf launches Chromium, loads the page, and captures it as PDF
            PdfDocument pdf = PdfDocument.renderUrlAsPdf(url);

            // getBinaryData returns the raw PDF bytes ready for transmission
            byte[] pdfBytes = pdf.getBinaryData();

            return request.createResponseBuilder(HttpStatus.OK)
                    .body(pdfBytes)
                    .header("Content-Disposition", "attachment; filename=output.pdf")
                    .header("Content-Type", "application/pdf")
                    .build();

        } catch (Exception ex) {
            context.getLogger().severe("Rendering error: " + ex.getMessage());
            return request.createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR)
                    .body("PDF rendering failed.")
                    .build();
        }
    }
}
JAVA

PdfDocument.renderUrlAsPdf(url) 在容器内启动一个无头 Chromium 实例,完全加载目标 URL(包括 JavaScript),并将渲染后的输出保存为 PDF 文件。 这会生成与用户在浏览器中看到的视觉效果相同的输出,适合捕捉现代网络应用程序、仪表板和报告页面。

重要函数触发器中的 authLevel = AuthorizationLevel.ANONYMOUS 设置会使该端点对公众开放。 对于生产环境部署,请将其更改为 FUNCTIONADMIN,并在请求头中传递该函数键。)}]

如何为IronPDF配置Dockerfile? {#configure-dockerfile}

IronPDF的Chromium引擎依赖于一组基础Azure Functions镜像中不包含的共享Linux库。 基础镜像 mcr.microsoft.com/azure-functions/java:4-java17-build 基于 Debian 11 构建,因此必须使用 apt 安装软件包。

必须将以下 RUN 命令添加到由 Azure Functions Maven 原型生成的 Dockerfile 中。 请将它们放置在 FROM 指令之后,以及添加应用程序 JAR 的 COPY 步骤之前:

//:path=/static-assets/pdf/content-code-examples/tutorials/azure/Dockerfile
FROM mcr.microsoft.com/azure-functions/java:4-java17-build AS installer-env

# Install system dependencies required by IronPDF's Chromium renderer
RUN apt-get update && apt-get install -y \
    libgdiplus \
    libxkbcommon-x11-0 \
    libc6 \
    libc6-dev \
    libgtk2.0-0 \
    libnss3 \
    libatk-bridge2.0-0 \
    libx11-xcb1 \
    libxcb-dri3-0 \
    libdrm-common \
    libgbm1 \
    libasound2 \
    libxrender1 \
    libfontconfig1 \
    libxshmfence1 \
    && apt-get install -y xvfb libva-dev libgdiplus \
    && rm -rf /var/lib/apt/lists/*

# Copy the built function JAR
COPY --from=installer-env /home/site/wwwroot /home/site/wwwroot

ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true

libgdiplus 软件包为图形渲染提供了 GDI+ 兼容性。 libnss3libatk-bridge2.0-0 是 Chromium 沙箱和辅助功能层所必需的。 xvfb 提供了一个虚拟帧缓冲区,在某些 Debian 配置中,Chromium 即使在无头模式下也需要它。 rm -rf /var/lib/apt/lists/* 块末尾的 RUN 步骤会清除包管理器缓存,从而使最终镜像大小尽可能小。

请注意如果Azure Functions基础镜像版本更改或使用不同的Linux发行版作为基础,则所需的包可能有所不同。 请查阅<IronPDF Linux安装指南以获取Debian、Ubuntu、CentOS和Alpine的完整依赖矩阵。)}]

如何构建和推送Docker镜像? {#build-push-docker}

在Maven项目构建完毕并更新Dockerfile后,可以组装容器镜像并将其上传到Docker注册表。 创建或更新Function App时,Azure Functions会拉取此镜像。

步骤1—构建并打包Maven项目

//:path=/static-assets/pdf/content-code-examples/tutorials/azure/build.sh
# Compile the Java code and package it as a JAR
mvn clean package
//:path=/static-assets/pdf/content-code-examples/tutorials/azure/build.sh
# Compile the Java code and package it as a JAR
mvn clean package
SHELL

Maven 会编译函数代码,解析所有依赖项(包括两个 IronPDF 构建产物),并在 target/ 目录中生成一个可部署的 JAR 文件。 在继续之前修复所有编译错误。

步骤2—构建Docker镜像

//:path=/static-assets/pdf/content-code-examples/tutorials/azure/docker-build.sh
# Replace <DOCKER_ID> with your Docker Hub username or ACR login server
docker build --tag <DOCKER_ID>/ironpdf-azure-functions:v1.0.0 .
//:path=/static-assets/pdf/content-code-examples/tutorials/azure/docker-build.sh
# Replace <DOCKER_ID> with your Docker Hub username or ACR login server
docker build --tag <DOCKER_ID>/ironpdf-azure-functions:v1.0.0 .
SHELL

构建安装Dockerfile中列出的Linux包,复制JAR,并将所有东西分层到最终镜像中。 首次构建可能需要几分钟,因为包下载和层缓存正在建立。 使用相同基础镜像的后续构建快得多。

步骤3—推送镜像到Docker Hub

//:path=/static-assets/pdf/content-code-examples/tutorials/azure/docker-push.sh
# Authenticate if not already logged in
docker login

# Push the image to the registry
docker push <DOCKER_ID>/ironpdf-azure-functions:v1.0.0
//:path=/static-assets/pdf/content-code-examples/tutorials/azure/docker-push.sh
# Authenticate if not already logged in
docker login

# Push the image to the registry
docker push <DOCKER_ID>/ironpdf-azure-functions:v1.0.0
SHELL

提示Azure容器注册表(ACR)是Docker Hub的私有替代方案。 ACR直接与Azure Active Directory集成,是希望镜像隐私的生产工作负荷的推荐选择。

如何将功能部署到Azure? {#deploy-to-azure}

在注册表中有了镜像后,Azure Function App可以被创建(或更新)以参考它。 az functionapp create 命令可在单一步骤中完成 Function App 的配置、将其链接到存储帐户,并设置容器镜像。

步骤1—创建或更新Function App

//:path=/static-assets/pdf/content-code-examples/tutorials/azure/az-deploy.sh
az functionapp create \
  --name <APP_NAME> \
  --storage-account <STORAGE_NAME> \
  --resource-group AzureFunctionsContainers-rg \
  --plan myPremiumPlan \
  --deployment-container-image-name <DOCKER_ID>/ironpdf-azure-functions:v1.0.0
//:path=/static-assets/pdf/content-code-examples/tutorials/azure/az-deploy.sh
az functionapp create \
  --name <APP_NAME> \
  --storage-account <STORAGE_NAME> \
  --resource-group AzureFunctionsContainers-rg \
  --plan myPremiumPlan \
  --deployment-container-image-name <DOCKER_ID>/ironpdf-azure-functions:v1.0.0
SHELL

请将 <APP_NAME> 替换为 Function App 的全局唯一名称,将 <STORAGE_NAME> 替换为现有的 Azure 存储帐户名称,并将 <DOCKER_ID> 替换为上一步中使用的 Docker Hub 用户名或 ACR 登录服务器。

--plan myPremiumPlan 标记用于选择高级托管方案。 IronPDF的Chromium引擎在渲染过程中消耗大量内存; 消耗计划的1.5 GB内存上限通常是不够的。 高级计划提供至少3.5 GB并支持预热实例,从而消除冷启动延迟。

步骤2 — 验证部署:

//:path=/static-assets/pdf/content-code-examples/tutorials/azure/az-verify.sh
# Check that the function app is running and the container has been pulled
az functionapp show \
  --name <APP_NAME> \
  --resource-group AzureFunctionsContainers-rg \
  --query "state"
//:path=/static-assets/pdf/content-code-examples/tutorials/azure/az-verify.sh
# Check that the function app is running and the container has been pulled
az functionapp show \
  --name <APP_NAME> \
  --resource-group AzureFunctionsContainers-rg \
  --query "state"
SHELL

当容器成功启动时,该命令将返回 "Running"。 如果返回 "Starting" 或出现错误,请检查 Azure 门户中函数应用下的日志流,查看是否存在容器拉取或启动错误。

警告不建议在Azure Functions上使用IronPDF的消耗(无服务器)计划。 使用Chromium进行PDF渲染所需的内存超过了消耗计划分配的内存。 使用高级或专用(App Service)计划以避免内存不足错误。

如何触发和测试功能? {#trigger-and-test}

一旦 Function App 报告 Running 状态,RenderPdf 端点即可开始接受请求。 端点 URL 遵循基于 Function App 名称以及 @FunctionName 注释中定义的函数名称的可预测模式。

使用浏览器或curl进行测试:

//:path=/static-assets/pdf/content-code-examples/tutorials/azure/test-request.sh
# Replace <APP_NAME> with the Function App name
curl -o output.pdf \
  "https://<APP_NAME>.azurewebsites.net/api/RenderPdf?url=https://www.example.com"
//:path=/static-assets/pdf/content-code-examples/tutorials/azure/test-request.sh
# Replace <APP_NAME> with the Function App name
curl -o output.pdf \
  "https://<APP_NAME>.azurewebsites.net/api/RenderPdf?url=https://www.example.com"
SHELL

成功的响应会将一个名为 output.pdf 的 PDF 文件保存到当前目录。 curl 中的 -o 标志会将二进制响应正文写入文件,而非将其输出到终端。

在浏览器中测试时,请导航到:

https://<APP_NAME>.azurewebsites.net/api/RenderPdf?url=https://www.example.com

浏览器会提示下载一个PDF。 打开它以验证页面是否正确渲染。

重要冷启动后的第一个请求可能需要20-60秒,因为Azure要拉取容器镜像及IronPDF初始化Chromium。 在同一容器生命周期内的后续请求会快得多。 高级计划的预热实例功能通过保持至少一个实例持续运行来消除冷启动。

检查错误日志:导航到Azure门户,打开功能应用,在监控下选择日志流。 context.getLogger() 调用的日志条目会近乎实时地显示在此处,这使得诊断渲染故障变得十分简单。

下一步是什么? {#next-steps}

本指南演示了如何在Azure Functions Docker容器内部署IronPDF for Java,编写一个HTTP触发的功能将URL渲染为PDF,配置Dockerfile以满足Linux依赖项,并测试活动端点。 相同的模式仅需少量更改即可扩展到更高级的使用案例。

扩展功能:

  • 使用 PdfDocument.renderHtmlAsPdf(htmlString) 直接渲染 HTML 字符串,而非 URL
  • 使用IronPDF的完整Java PDF API应用水印、合并多个PDF或添加数字签名
  • 读取请求头或POST主体以传递自定义HTML内容或渲染选项

改进生产准备度:

探索更多IronPDF for Java指南:

开始免费IronPDF试用,在评估期间无需水印即可访问所有渲染和操作功能。 准备好部署到生产环境时,查看IronPDF许可选项以找到适合项目规模的计划。

常见问题解答

为什么Azure Functions需要Docker部署IronPDF?

IronPDF附带一个本地的Chromium渲染引擎,它必须在运行时执行二进制文件。Azure Functions的Zip部署不能运行本地二进制文件,因此Docker容器镜像是唯一支持的部署路径。

运行IronPDF在Docker容器中需要哪些Maven工件?

pom.xml中需要两个工件:com.ironsoftware:ironpdf用于Java API,com.ironsoftware:ironpdf-engine-linux-x64用于本地Chromium引擎。两者必须共享相同的版本号。

Dockerfile需要为IronPDF安装哪些Linux包?

Dockerfile必须安装libgdipluslibxkbcommon-x11-0libc6libc6-devlibgtk2.0-0libnss3libatk-bridge2.0-0libx11-xcb1libxcb-dri3-0libdrm-commonlibgbm1libasound2libxrender1libfontconfig1libxshmfence1xvfblibva-dev

RenderPdf函数的作用是什么?

RenderPdf函数是一个HTTP触发的Azure函数,它读取url查询参数,将其传递给PdfDocument.renderUrlAsPdf,并使用Content-Disposition: attachment头返回生成的PDF字节,使调用者收到一个可下载的PDF文件。

使用IronPDF的Azure Functions托管计划应该选择哪个?

推荐选择Premium计划。IronPDF的Chromium引擎需要大量内存——通常超过消费计划的1.5 GB上限。Premium计划至少提供3.5 GB的内存,并支持预热实例以消除冷启动延迟。

为什么对新部署函数的首次请求很慢?

因为需要拉取容器镜像并初始化IronPDF的Chromium引擎,冷启动后的首次请求可能需要20-60秒。相同容器生命周期内的后续请求响应速度快得多。Premium计划的预热实例功能可以消除这种延迟。

如何更新现有的Azure Function App以使用新的Docker镜像?

重新构建并推送标记更新后的新镜像,然后再次运行az functionapp create,并使用新的--deployment-container-image-name值,或在Azure门户中的Deployment Center下更新容器设置。

IronPDF能否在Azure Function中渲染HTML字符串,而不仅仅是URL?

可以。替换PdfDocument.renderUrlAsPdf(url)PdfDocument.renderHtmlAsPdf(htmlString)以直接渲染HTML字符串。函数结构和响应处理保持不变。

如果请求中缺少url查询参数,会发生什么?

函数会检查url参数是否为null,并在尝试任何PDF渲染之前,返回带有描述性消息的HTTP 400错误请求响应。

Curtis Chau
技术作家

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。

准备开始了吗?
版本: 2026.5 just released
Still Scrolling Icon

还在滚动吗?

想快速获得证据?
运行示例看着你的HTML代码变成PDF文件。