Aspose.Slides for Node.js via .NET

Aspose.Slides for Node.js via .NET

Aspose.Slides for Node.js via .NET 是一個用於在 Node.js 應用程式中建立、讀取、編輯與轉換 PowerPoint 與 OpenDocument 簡報的函式庫,無需 Microsoft PowerPoint 或 Office Automation。它透過 edge-js 橋接執行 Aspose.Slides for .NET,因此其 JavaScript API 與 .NET API 相同,使用 camelCase 成員名稱。

它可載入與儲存 PPT、PPTX、PPS、POT 與 ODP,包含支援巨集與範本的變體,並可匯出為 PDF、XPS、HTML、TIFF、Markdown 與圖片。



您的第一個簡報

您需要 Node.js 22 或 24 以及 .NET SDK 8 或更新版本;Linux 亦需安裝幾個系統套件。安裝 列出了它們以及已測試的平台。建立專案,新增一個覆寫以告訴 npm 要安裝哪個 edge-js 版本,然後安裝套件:

mkdir hello-slides
cd hello-slides
npm init -y
npm pkg set overrides.edge-js=26.1.0
npm install aspose.slides.via.net

每台機器執行一次,還原此函式庫所依賴的 .NET 套件。將 deps.csproj 檔案從還原 .NET 依賴項 保存至專案資料夾內的 deps 資料夾,然後執行:

dotnet restore deps/deps.csproj

將此程式碼儲存為 hello.js 於專案資料夾中:

const asposeSlides = require("aspose.slides.via.net");
const { Presentation, ShapeType, SaveFormat } = asposeSlides;

// 新的簡報包含一張空白投影片。
const presentation = new Presentation();
try {
    const slide = presentation.slides.get(0);

    // 位置與尺寸以點 (1/72 英吋) 為單位:x、y、寬度、高度。
    const rectangle = slide.shapes.addAutoShape(ShapeType.Rectangle, 50, 50, 400, 100);
    rectangle.addTextFrame("Hello, World!");

    presentation.save("hello.pptx", SaveFormat.Pptx);
    console.log("Saved hello.pptx");
} finally {
    // 釋放支援簡報的 .NET 物件。
    presentation.dispose();
}

在專案資料夾中執行它:

node hello.js

腳本會顯示 Saved hello.pptx,並將 hello.pptx 儲存為包含一張帶有文字矩形的投影片。如果未授權,儲存的檔案會有評估水印 ─ 請參見授權。如需更多建立與填充簡報的方式,請參閱建立簡報。