Aspose.Slides for Java

Aspose.Slides for Java

Aspose.Slides for Java 是一個類別庫,可在 Java 應用程式中建立、讀取、編輯和轉換 PowerPoint 與 OpenDocument 簡報,無需 Microsoft PowerPoint。

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



您的第一個簡報

Aspose.Slides for Java 發佈於 Aspose 自己的 Maven 儲存庫,而非 Maven Central。為 Maven 專案建立一個資料夾,並將此 pom.xml 儲存於其中。它宣告儲存庫、加入函式庫,並指定要執行的類別:

<project xmlns="http://maven.apache.org/POM/4.0.0">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>hello-slides</artifactId>
    <version>1.0</version>

    <properties>
        <maven.compiler.release>11</maven.compiler.release>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <exec.mainClass>HelloSlides</exec.mainClass>
    </properties>

    <repositories>
        <repository>
            <id>AsposeJavaAPI</id>
            <name>Aspose Java API</name>
            <url>https://releases.aspose.com/java/repo/</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>com.aspose</groupId>
            <artifactId>aspose-slides</artifactId>
            <version>26.9</version>
            <classifier>jdk16</classifier>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.15.0</version>
            </plugin>
        </plugins>
    </build>
</project>

將此程式碼儲存為 src/main/java/HelloSlides.java:

import com.aspose.slides.*;

public class HelloSlides {
    public static void main(String[] args) {
        // 建立一個簡報。它已包含一張空白投影片。
        Presentation presentation = new Presentation();
        try {
            // 取得第一張投影片。
            ISlide slide = presentation.getSlides().get_Item(0);

            // 新增雲形狀並在其中放入文字。
            IAutoShape autoShape = slide.getShapes().addAutoShape(ShapeType.Cloud, 20, 20, 200, 80);
            autoShape.getTextFrame().setText("Hello, Aspose!");

            // 將簡報儲存為 PPTX 檔案。
            presentation.save("new_presentation.pptx", SaveFormat.Pptx);
        } finally {
            presentation.dispose();
        }
    }
}

接著,在安裝了 JDK 11 或更新版本以及 Apache Maven 後,於專案資料夾中執行以下指令:

mvn compile exec:java

程式會將 new_presentation.pptx 儲存於專案資料夾,內含一張帶有雲形狀與文字的投影片。於 Linux 必須安裝 fontconfig 並至少一種字型;請參閱Installation。未取得授權時,儲存的檔案會帶有評估水印 — 請參閱Licensing。欲了解更多建立與填充簡報的方法,請參閱Create Presentations.