IRONSOFTWAREHOME
多线程生成
import {PdfDocument} from "@ironsoftware/ironpdf";

(async () => {
    const htmlStrings = ["<h1>Html#1</h1>", "<h1>Html#2</h1>", "<h1>Html#3</h1>"];

    // Use Promise.all to render HTML strings asynchronously
    const renderPromises = htmlStrings.map(async (html) => {
        const pdf = await PdfDocument.fromHtml(html);
        // Perform more action to the returned PDF
        return pdf;
    });

    // Wait for all rendering Promises to complete
    const pdfDocuments = await Promise.all(renderPromises);
    
    // Do something with the pdfDocuments
})();
npm i @ironsoftware/ironpdf
多线程生成

多线程生成

JavaScript和Node.js都支持异步处理。 IronPDF也是如此,IronPDF,一个.NET PDF库,以其高效的PDF生成和操作功能而闻名。

大多数IronPDF的方法返回承诺。 借助此功能,我们可以渲染多个HTML内容,然后使用Promise.all方法等待所有承诺完成。

请注意,Promise.all方法不保证所有承诺的成功; 它仅确保Promise已完成。

.map函数中用于等待返回的PDF文档并进一步编辑文档。 如果您的目标仅是渲染PDF而不进行其他处理,使用await可能没有必要。

探索异步 PDF 生成代码示例
在 GitHub 上查看

准备开始了吗?

版本:2026.6刚刚发布

Key in blue circle

立即获取免费的 30 天试用版密钥

Your trial license will be sent to your email address

无任何限制。100% 解锁。无需信用卡。

bullet_checked无需信用卡或创建账户无任何限制。100% 解锁。无需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
预约您的免费现场演示
Booking Badge

深受全球数百万工程师信赖

Iron Software 的客户徽标
获取您的无义务咨询
填写下面的表格或通过sales@ironsoftware.com
您的资料将始终保密。
深受全球数百万工程师信赖
Iron Software 的客户徽标
立即获取您的免费30 天试用密钥
无需信用卡或创建账户