多執行緒生成
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,一個.NET PDF程式庫,以其高效的PDF生成和操作能力著稱。

大多數IronPDF的方法返回promise。 利用這一點,我們可以渲染多個HTML內容,然後使用Promise.all方法來等待所有promise完成。

請注意,Promise.all方法並不保證所有promise成功; 它只確保promise已經完成。

在await用來等待返回的PDF文件並對文件進行進一步編輯。 如果您的目標僅僅是渲染PDF而不進行額外處理,則可能不需要使用await。

探索非同步PDF生成程式碼範例
在 GitHub 上查看

準備好開始了嗎?

版本:2026.11剛剛發布