多线程生成
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.11刚刚发布