คุณลักษณะและความสามารถ
คุณลักษณะและความสามารถ
Aspose.Slides FOSS for Java มีชุดความสามารถที่กว้างขวางสำหรับการทำงานกับไฟล์ PowerPoint .pptx อย่างโปรแกรมมิ่ง หน้านี้แสดงรายการพื้นที่คุณลักษณะที่รองรับทั้งหมดพร้อมตัวอย่างโค้ดที่เป็นตัวแทน.
การนำเสนอ I/O
เปิดไฟล์ .pptx ที่มีอยู่แล้วหรือสร้างไฟล์ใหม่, แล้วบันทึกกลับเป็นรูปแบบ PPTX.
import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.export.SaveFormat;
// Open an existing presentation
try (Presentation prs = new Presentation("input.pptx")) {
System.out.println("Slide count: " + prs.getSlides().size());
prs.save("output.pptx", SaveFormat.PPTX);
}
// Create a new presentation (starts with one blank slide)
try (Presentation prs = new Presentation()) {
prs.save("new.pptx", SaveFormat.PPTX);
}หมายเหตุ: PPTX เป็นรูปแบบการบันทึกที่รองรับเพียงอย่างเดียว การส่งออกเป็น PDF, HTML, SVG หรือรูปภาพไม่สามารถทำได้
ส่วน XML ที่ไม่รู้จักในไฟล์ต้นฉบับจะถูกเก็บไว้ตามต้นฉบับเมื่อบันทึก ดังนั้นการเปิดและบันทึกใหม่ของ .pptx จะไม่มีการลบเนื้อหาที่ไลบรารียังไม่เข้าใจ.
การจัดการสไลด์
เพิ่ม, ลบ, คัดลอก, และจัดเรียงสไลด์ใหม่.
import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.export.SaveFormat;
try (Presentation prs = new Presentation()) {
// Access the first slide
var slide = prs.getSlides().get(0);
// Add an additional blank slide at the end
prs.getSlides().addEmptySlide(prs.getLayoutSlides().get(0));
System.out.println("Total slides: " + prs.getSlides().size());
prs.save("multi-slide.pptx", SaveFormat.PPTX);
}รูปร่าง
เพิ่ม AutoShapes, PictureFrames, Tables และ Connectors ลงในสไลด์.
AutoShapes
import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ShapeType;
import org.aspose.slides.foss.export.SaveFormat;
try (Presentation prs = new Presentation()) {
var slide = prs.getSlides().get(0);
// Add a rectangle at (x=50, y=50) with width=300, height=100
var shape = slide.getShapes().addAutoShape(ShapeType.RECTANGLE, 50, 50, 300, 100);
shape.addTextFrame("Aspose.Slides FOSS");
prs.save("shapes.pptx", SaveFormat.PPTX);
}ตาราง
import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.export.SaveFormat;
try (Presentation prs = new Presentation()) {
var slide = prs.getSlides().get(0);
// Column widths and row heights in points
double[] colWidths = {120.0, 120.0, 120.0};
double[] rowHeights = {40.0, 40.0, 40.0};
var table = slide.getShapes().addTable(50, 50, colWidths, rowHeights);
table.getRows().get(0).get(0).getTextFrame().setText("Product");
table.getRows().get(0).get(1).getTextFrame().setText("Quantity");
table.getRows().get(0).get(2).getTextFrame().setText("Price");
prs.save("table.pptx", SaveFormat.PPTX);
}คอนเนคเตอร์
import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ShapeType;
import org.aspose.slides.foss.export.SaveFormat;
try (Presentation prs = new Presentation()) {
var slide = prs.getSlides().get(0);
var box1 = slide.getShapes().addAutoShape(ShapeType.RECTANGLE, 50, 100, 150, 60);
var box2 = slide.getShapes().addAutoShape(ShapeType.RECTANGLE, 350, 100, 150, 60);
var conn = slide.getShapes().addConnector(ShapeType.BENT_CONNECTOR3, 0, 0, 10, 10);
conn.setStartShapeConnectedTo(box1);
conn.setStartShapeConnectionSiteIndex(3); // right side
conn.setEndShapeConnectedTo(box2);
conn.setEndShapeConnectionSiteIndex(1); // left side
prs.save("connector.pptx", SaveFormat.PPTX);
}การจัดรูปแบบข้อความ
จัดรูปแบบข้อความในระดับย่อหน้าและอักขระโดยใช้ PortionFormat.
import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ShapeType;
import org.aspose.slides.foss.NullableBool;
import org.aspose.slides.foss.FillType;
import org.aspose.slides.foss.drawing.Color;
import org.aspose.slides.foss.export.SaveFormat;
try (Presentation prs = new Presentation()) {
var slide = prs.getSlides().get(0);
var shape = slide.getShapes().addAutoShape(ShapeType.RECTANGLE, 50, 50, 500, 150);
var tf = shape.addTextFrame("Bold blue heading");
var fmt = tf.getParagraphs().get(0).getPortions().get(0).getPortionFormat();
fmt.setFontHeight(28);
fmt.setFontBold(NullableBool.TRUE);
fmt.getFillFormat().setFillType(FillType.SOLID);
fmt.getFillFormat().getSolidFillColor().setColor(Color.fromArgb(255, 0, 70, 127));
prs.save("text.pptx", SaveFormat.PPTX);
}NullableBool.TRUE ตั้งค่าคุณสมบัติโดยตรง; NullableBool.NOT_DEFINED สืบทอดจากสไลด์มาสเตอร์.
ประเภทการเติม
เติมสีแบบทึบ, ไล่ระดับสี, ลวดลาย หรือรูปภาพให้กับรูปร่าง
import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ShapeType;
import org.aspose.slides.foss.FillType;
import org.aspose.slides.foss.drawing.Color;
import org.aspose.slides.foss.export.SaveFormat;
try (Presentation prs = new Presentation()) {
var slide = prs.getSlides().get(0);
var shape = slide.getShapes().addAutoShape(ShapeType.RECTANGLE, 50, 50, 300, 150);
// Solid fill
shape.getFillFormat().setFillType(FillType.SOLID);
shape.getFillFormat().getSolidFillColor().setColor(Color.fromArgb(255, 30, 120, 200));
prs.save("fill.pptx", SaveFormat.PPTX);
}เอฟเฟกต์ภาพ
ใช้เงานอก, แสงเรืองแสง, ขอบนุ่ม, เบลอ, การสะท้อน, และเงาภายในกับรูปทรง.
คุณสมบัติของเอฟเฟกต์สามารถเข้าถึงได้ผ่าน shape.getEffectFormat(). เรียกใช้ enableOuterShadowEffect(), enableGlowEffect(), enableSoftEdgeEffect(), setBlurEffect(radius, grow), enableReflectionEffect() หรือ enableInnerShadowEffect() เพื่อกำหนดค่าแต่ละอย่างแยกกัน.
การจัดรูปแบบ 3D
ใช้ 3D bevel, camera, light rig, material, และ extrusion depth ผ่าน shape.getThreeDFormat(). สิ่งนี้ควบคุมความลึกเชิงภาพและโมเดลการส่องแสงสำหรับการเรนเดอร์รูปทรงในโปรแกรมดู PPTX ที่รองรับเอฟเฟกต์ 3D.
บันทึกผู้พูด
แนบบันทึกย่อไปยังสไลด์ใดก็ได้โดยใช้ getNotesSlideManager().
import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.export.SaveFormat;
try (Presentation prs = new Presentation()) {
var notes = prs.getSlides().get(0).getNotesSlideManager().addNotesSlide();
notes.getNotesTextFrame().setText("Key talking point: emphasize the ROI benefit.");
prs.save("notes.pptx", SaveFormat.PPTX);
}ความคิดเห็น
เพิ่มความคิดเห็นแบบเธรดพร้อมข้อมูลผู้เขียนและตำแหน่งสไลด์
import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.drawing.PointF;
import org.aspose.slides.foss.export.SaveFormat;
import java.time.LocalDateTime;
try (Presentation prs = new Presentation()) {
var author = prs.getCommentAuthors().addAuthor("Jane Smith", "JS");
var slide = prs.getSlides().get(0);
author.getComments().addComment(
"Please verify this data before the presentation.",
slide,
new PointF(2.0f, 2.0f),
LocalDateTime.now()
);
prs.save("comments.pptx", SaveFormat.PPTX);
}ภาพฝัง
ฝังรูปภาพจากไฟล์ลงในงานนำเสนอและเพิ่มลงสไลด์เป็น PictureFrame.
import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ShapeType;
import org.aspose.slides.foss.export.SaveFormat;
import java.nio.file.Files;
import java.nio.file.Path;
try (Presentation prs = new Presentation()) {
byte[] imageData = Files.readAllBytes(Path.of("logo.png"));
var image = prs.getImages().addImage(imageData);
var slide = prs.getSlides().get(0);
slide.getShapes().addPictureFrame(ShapeType.RECTANGLE, 50, 50, 200, 150, image);
prs.save("with-image.pptx", SaveFormat.PPTX);
}คุณสมบัติของเอกสาร
อ่านและเขียนคุณสมบัติของเอกสารหลัก, แอป และกำหนดเอง
import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.export.SaveFormat;
try (Presentation prs = new Presentation()) {
var props = prs.getDocumentProperties();
// Core properties
props.setTitle("Q1 Results");
props.setAuthor("Finance Team");
props.setSubject("Quarterly Review");
props.setKeywords("Q1, finance, results");
// Custom property
props.setCustomPropertyValue("ReviewedBy", "Legal Team");
prs.save("deck.pptx", SaveFormat.PPTX);
}ข้อจำกัดที่ทราบ
พื้นที่ต่อไปนี้ทำให้เกิด UnsupportedOperationException และไม่พร้อมใช้งานในฉบับนี้:
| ส่วน | สถานะ |
|---|---|
| Charts | ยังไม่ได้ดำเนินการ |
| SmartArt | ยังไม่ได้ดำเนินการ |
| Animations and transitions | ยังไม่ได้ดำเนินการ |
| PDF / HTML / SVG / image export | ยังไม่ได้ดำเนินการ (PPTX only) |
| VBA macros | ยังไม่ได้ดำเนินการ |
| Digital signatures | ยังไม่ได้ดำเนินการ |
| Hyperlinks and action settings | ยังไม่ได้ดำเนินการ |
| OLE objects | ยังไม่ได้ดำเนินการ |
| Mathematical text | ยังไม่ได้ดำเนินการ |
ดูเพิ่มเติม
- เริ่มต้น: การติดตั้งและโปรแกรมแรก
- เอกสารอ้างอิง API: การอ้างอิงคลาสและเมธอด
- คู่มือวิธีทำ: บทความเชิงงาน