Java のロウコード プレゼンテーション操作
概要
The com.aspose.slides package provides static helper classes for common presentation operations. These helpers wrap frequently used object-model workflows in focused methods, so you can convert or merge files, process presentation elements, collect shapes, and remove unused content with less code.
Low-code helpers are most useful when the operation applies to an entire file or presentation and the default workflow matches your requirements. Use the full Aspose.Slides オブジェクトモデル when you need fine-grained control over individual slides, masters, layouts, shapes, export settings, or relationships between presentation elements.
The following table summarizes the available helpers:
| ヘルパー | 使用目的 |
|---|---|
| Convert | 直接のファイル間呼び出しでプレゼンテーションを別の形式に変換します。 |
| Merger | 同じ形式の完全なプレゼンテーションファイルを結合します。 |
| ForEach | 各スライド、シェイプ、段落、またはテキスト部分に対してアクションを実行します。 |
| Collect | 繰り返しの処理や分析のために、プレゼンテーション全体からシェイプを取得します。 |
| Compress | 未使用のマスターとレイアウトを削除し、埋め込みフォントデータを削減します。 |
プレゼンテーションの変換
Use Convert.autoByExtension when the output file extension is sufficient to select the export format. The method opens the source presentation, determines the required format from the output path, and writes the result.
import com.aspose.slides.Convert;
Convert.autoByExtension("input.pptx", "output.pdf");
The Convert class also provides dedicated methods for PDF, SVG, JPEG, PNG, and TIFF output. Use the full object model when you need to inspect or modify the presentation before export or configure an export option that is not exposed by the selected helper. See プレゼンテーションの変換 for format-specific workflows and options.
プレゼンテーションの結合
Use Merger.process to combine complete presentation files with one call. The input presentations must have the same file format.
import com.aspose.slides.Merger;
String[] inputFiles = { "part-1.pptx", "part-2.pptx" };
Merger.process(inputFiles, "merged.pptx");
The helper is appropriate when all slides should be appended to one result without selecting or remapping them individually. Use the full object model when you need to merge selected slides, apply a destination master or layout, preserve sections explicitly, or reconcile different slide sizes. See プレゼンテーションの結合 for those scenarios.
プレゼンテーション要素の反復処理
The ForEach class invokes a callback for each requested type of presentation element. It avoids nested collection loops and is convenient for presentation-wide inspection or formatting changes.
The following example uses ForEach.slide, ForEach.shape, ForEach.paragraph, and ForEach.portion to inspect the corresponding elements:
import com.aspose.slides.*;
Presentation presentation = new Presentation("input.pptx");
try {
ForEach.slide(presentation, (slide, index) -> {
System.out.println(String.format("Slide %d: %d shapes", index, slide.getShapes().size()));
});
ForEach.shape(presentation, (shape, slide, index) -> {
System.out.println(String.format("Shape %d on %s: %s", index, slide.getClass().getSimpleName(), shape.getName()));
});
ForEach.paragraph(presentation, (paragraph, slide, index) -> {
System.out.println(String.format("Paragraph %d on %s: %s", index, slide.getClass().getSimpleName(), paragraph.getText()));
});
ForEach.portion(presentation, (portion, paragraph, slide, index) -> {
System.out.println(String.format("Portion %d on %s: %s", index, slide.getClass().getSimpleName(), portion.getText()));
});
} finally {
presentation.dispose();
}
By default, presentation-wide shape and text traversal includes normal, master, and layout slides. Overloads with an includeNotes parameter can also process notes slides. Use direct collection loops when traversal order, early exit, filtering before callback invocation, or detailed parent-child control is important.
シェイプの収集
Use Collect.shapes when you need a collection of all shapes in a presentation rather than a callback for each shape. This is useful when the same set will be filtered, counted, or processed more than once.
import com.aspose.slides.*;
Presentation presentation = new Presentation("input.pptx");
try {
Iterable<Shape> shapes = Collect.shapes(presentation);
for (Shape shape : shapes) {
System.out.println(String.format("%s: %s", shape.getName(), shape.getClass().getSimpleName()));
}
} finally {
presentation.dispose();
}
Use ForEach.shape instead when each shape can be handled immediately and you do not need to retain the collected result.
プレゼンテーション コンテンツの圧縮
The Compress class can remove unused structural elements and reduce embedded font data:
- Compress.removeUnusedLayoutSlides removes layout slides that no normal slide references.
- Compress.removeUnusedMasterSlides removes master slides that are no longer used.
- Compress.compressEmbeddedFonts removes unused characters from embedded fonts.
import com.aspose.slides.*;
Presentation presentation = new Presentation("input.pptx");
try {
Compress.removeUnusedLayoutSlides(presentation);
Compress.removeUnusedMasterSlides(presentation);
Compress.compressEmbeddedFonts(presentation);
presentation.save("compressed.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
Remove unused layouts before unused masters so a master that becomes unreferenced after layout cleanup can also be removed. Save the optimized presentation to a new file if you may need the original masters, layouts, or complete embedded font data later. For more detail, see スライドマスター and 埋め込みフォント.
よくある質問
低コード API をフル オブジェクトモデルの代わりに使用すべきはいつですか?
標準的な操作がファイル全体またはプレゼンテーション全体に適用され、個々の要素に対する詳細な制御が不要な場合はロウコードヘルパーを使用してください。特定のスライドを選択したり、マスターやレイアウトの関係を制御したり、途中状態を検査したり、ヘルパーが提供しない動作を設定する必要がある場合は、フルオブジェクトモデルを使用してください。
Merger は異なるファイル形式のプレゼンテーションを結合できますか?
いいえ。Merger.process は同じ形式の入力プレゼンテーションが必要です。まず、たとえば Convert.autoByExtension を使用して入力ファイルを共通の形式に変換し、変換したファイルを結合してください。
ForEach はマスター、レイアウト、およびノートスライドを処理しますか?
ForEach.slide は通常のプレゼンテーションスライドを走査します。プレゼンテーション全体の ForEach.shape、ForEach.paragraph、および ForEach.portion 操作はデフォルトで通常、マスター、レイアウトスライドを含みます。includeNotes を true に設定したオーバーロードを使用すると、ノートスライドも含めることができます。
ForEach.shape と Collect.shapes の違いは何ですか?
ForEach.shape はコールバックで各シェイプを即座に処理します。Collect.shapes はイテラブルな結果を取得し、保持、フィルタリング、カウント、または複数回走査できる場合に使用します。
Compress は常にプレゼンテーションファイルを小さくしますか?
必ずしもそうではありません。結果は、プレゼンテーションに未使用のレイアウト、未使用のマスター、または未使用文字を含む埋め込みフォントがあるかどうかに依存します。これらが存在しない場合、対応する Compress 操作はファイルサイズを削減しないことがあります。
ForEach や Compress によって行われた変更は自動的に保存されますか?
いいえ。これらのヘルパーはメモリ内の Presentation オブジェクトに対して操作します。[ForEach] コールバックや [Compress] を実行した後は、Presentation.save を呼び出して結果を書き出してください。