Java'da Düşük Kodlu Sunum İşlemleri
Genel Bakış
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 object model 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:
| Helper | Use it for |
|---|---|
| Convert | Sunumu başka bir biçime dosya‑dosya doğrudan çağrı ile dönüştürmek. |
| Merger | Aynı biçimdeki tam sunum dosyalarını birleştirmek. |
| ForEach | Her slayt, şekil, paragraf veya metin parçası için bir işlem çalıştırmak. |
| Collect | Tekrar tekrar işleme veya analiz için tüm sunumdaki şekilleri toplamak. |
| Compress | Kullanılmayan master ve layoutları kaldırmak ve gömülü font verisini azaltmak. |
Bir Sunumu Dönüştürme
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 Convert Presentation for format-specific workflows and options.
Sunumları Birleştirme
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 Merge Presentations for those scenarios.
Sunum Öğeleri Üzerinde Dolaşma
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.
Şekilleri Toplama
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.
Sunum İçeriğini Sıkıştırma
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 Slide Master and Embedded Font.
SSS
When should I use the low-code API instead of the full object model?
Low-code yardımcıları, standart bir işlem tüm dosya veya sunuma uygulanıyor ve bireysel öğeler üzerinde ayrıntılı kontrol gerektirmiyorsa kullanın. Bireysel slaytları seçmeniz, master‑layout ilişkilerini yönetmeniz, ara durumu incelemeniz veya yardımcı tarafından sunulmayan davranışları yapılandırmanız gerektiğinde tam nesne modelini kullanın.
Can Merger combine presentations in different file formats?
Hayır. Merger.process aynı biçimdeki giriş sunumlarını gerektirir. Önce giriş dosyalarını ortak bir biçime dönüştürün, örneğin Convert.autoByExtension ile, ardından dönüştürülmüş dosyaları birleştirin.
Does ForEach process master, layout, and notes slides?
ForEach.slide normal sunum slaytlarını iterasyona alır. Sunum‑geneli ForEach.shape, ForEach.paragraph, ve ForEach.portion işlemleri varsayılan olarak normal, master ve layout slaytlarını içerir. Not slaytlarını da dahil etmek için includeNotes parametresi true olarak ayarlanmış aşırı yüklemelerini kullanın.
What is the difference between ForEach.shape and Collect.shapes?
ForEach.shape her şekli anında bir geri çağrı ile işlemek içindir. Collect.shapes ise şekilleri bir koleksiyon olarak elde edip daha sonra filtreleme, sayma veya birden çok kez dolaşma ihtiyacınız olduğunda kullanılır.
Does Compress always make the presentation file smaller?
Her zaman değildir. Sonuç, sunumda kullanılmayan layoutlar, kullanılmayan masterlar veya kullanılmayan karakterlere sahip gömülü fontlar olup olmamasına bağlıdır. Bu öğeler yoksa ilgili Compress işlemleri dosya boyutunu azaltmayabilir.
Are changes made by ForEach or Compress saved automatically?
Hayır. Bu yardımcılar, bellekte yüklü olan Presentation nesnesi üzerinde çalışır. Bir ForEach geri çağrısında veya bir Compress çalıştırdıktan sonra sonucu yazmak için Presentation.save metodunu çağırın.