คุณลักษณะและความสามารถ

คุณลักษณะและความสามารถ

คุณลักษณะและความสามารถ

Aspose.Slides FOSS for Java provides a broad set of capabilities for working with PowerPoint .pptx ไฟล์โดยโปรแกรมมิ่ง หน้านี้แสดงรายการพื้นที่ฟีเจอร์ที่รองรับทั้งหมดพร้อมตัวอย่างโค้ดที่เป็นตัวแทน.


การอ่าน/เขียนงานนำเสนอ

เปิดไฟล์ที่มีอยู่แล้ว .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, ตาราง, และตัวเชื่อมต่อไปยังสไลด์.

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 Formatting

ใช้ 3D bevel, กล้อง, ระบบแสง, วัสดุ, และความลึกการดันออกผ่าน 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 และไม่พร้อมใช้งานในฉบับนี้:

พื้นที่สถานะ
แผนภูมิยังไม่ได้ดำเนินการ
SmartArtยังไม่ได้ดำเนินการ
การเคลื่อนไหวและการเปลี่ยนฉากยังไม่ได้ดำเนินการ
การส่งออก PDF / HTML / SVG / รูปภาพยังไม่ได้ดำเนินการ (เฉพาะ PPTX)
มาโคร VBAยังไม่ได้ดำเนินการ
ลายเซ็นดิจิทัลยังไม่ได้ดำเนินการ
ไฮเปอร์ลิงก์และการตั้งค่าการกระทำยังไม่ได้ดำเนินการ
อ็อบเจ็กต์ OLEยังไม่ได้ดำเนินการ
ข้อความคณิตศาสตร์ยังไม่ได้ดำเนินการ

ดูเพิ่มเติม

 ภาษาไทย