Java에서 PowerPoint 슬라이드에 오디오 및 비디오 파일을 추가하는 방법

광고 캠페인이나 제품 시연을 위해 슬라이드를 사용할 때 사람들은 일반적으로 프레젠테이션을 보다 생생하고 역동적으로 만들기 위해 미디어 파일(예: 오디오 및 비디오)을 추가합니다. 이 기사에서는 Free Spire.Presentation for Java를 사용하여 오디오 및 비디오 파일을 PowerPoint 프레젠테이션에 삽입하는 방법을 보여 드리겠습니다.

Spire.Presentation.jar을 종속성으로 추가



방법 1: Free Spire.Presentation for Java 팩을 다운로드하고 압축을 풀면 "lib"폴더에서 Spire.Presentation.jar 파일을 얻을 수 있습니다. 프로젝트의 jar 파일을 종속성으로 가져옵니다.

방법 2: Maven 프로젝트를 생성하는 경우 다음 구성을 pom.xml에 추가하여 jar 종속성을 쉽게 추가할 수 있습니다.

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId> e-iceblue </groupId>
        <artifactId>spire.presentation.free</artifactId>
        <version>2.6.1</version>
    </dependency>
</dependencies>


예 1. 슬라이드에 오디오 추가




import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;

import java.awt.*;
import java.awt.geom.Rectangle2D;

public class InsertAudio {

    public static void main(String[] args) throws Exception {

        //Create a Presentation object
        Presentation presentation = new Presentation();


        //Load a sample PowerPoint document
        presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\example.pptx");

        //Add a shape to the first slide
        Rectangle2D.Double labelRect= new Rectangle2D.Double(50, 120, 120, 30);
        IAutoShape labelShape = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE, labelRect);
        labelShape.getLine().setFillType(FillFormatType.NONE);
        labelShape.getFill().setFillType(FillFormatType.NONE);
        labelShape.getTextFrame().setText("Double Click to Play Audio:");
        labelShape.getTextFrame().getTextRange().setFontHeight(20);
        labelShape.getTextFrame().getTextRange().setLatinFont(new TextFont("Times New Roman"));
        labelShape.getTextFrame().getTextRange().getFill().setFillType(FillFormatType.SOLID);
        labelShape.getTextFrame().getTextRange().getFill().getSolidColor().setColor(Color.BLACK);

        //Add an audio file to the slide
        Rectangle2D.Double audioRect = new Rectangle2D.Double(175, 120, 30, 30);
        IAudio audio = presentation.getSlides().get(0).getShapes().appendAudioMedia((new java.io.File("C:\\Users\\Administrator\\Desktop\\music.wav")).getAbsolutePath(), audioRect);
        audio.setPlayMode(AudioPlayMode.ON_CLICK);

        //Save to file
        presentation.saveToFile("AddAudio.pptx", FileFormat.PPTX_2013);
        presentation.dispose();
    }
}


산출


예 2. 슬라이드에 비디오 추가




import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;

public class InsertVideo {

    public static void main(String[] args) throws Exception {

        //Create a Presentation object
        Presentation presentation = new Presentation();

        //Load a sample PowerPoint file
        presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\example.pptx");

        //Add a shape to the first slide
        Rectangle2D.Double labelRect = new Rectangle2D.Double(50, 120, 120, 50);
        IAutoShape labelShape = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE, labelRect);
        labelShape.getLine().setFillType(FillFormatType.NONE);
        labelShape.getFill().setFillType(FillFormatType.NONE);
        labelShape.getTextFrame().setText("Play Video:");
        labelShape.getTextFrame().getTextRange().setFontHeight(20);
        labelShape.getTextFrame().getTextRange().setLatinFont(new TextFont("Times New Roman"));
        labelShape.getTextFrame().getTextRange().getFill().setFillType(FillFormatType.SOLID);
        labelShape.getTextFrame().getTextRange().getFill().getSolidColor().setColor(Color.BLACK);

        //Append a video file to the slide and set the cover image
        Rectangle2D.Double videoRect = new Rectangle2D.Double(175, 120, 400, 225);
        IVideo video = presentation.getSlides().get(0).getShapes().appendVideoMedia((new java.io.File("C:\\Users\\Administrator\\Desktop\\video.mp4")).getAbsolutePath(), videoRect);
        BufferedImage coverImage = ImageIO.read( new File("C:\\Users\\Administrator\\Desktop\\coverImage.jpg"));
        video.getPictureFill().getPicture().setEmbedImage(presentation.getImages().append(coverImage));

        //Save to file
        presentation.saveToFile("AddVideo.pptx", FileFormat.PPTX_2010);
        presentation.dispose();
    }
}


산출

좋은 웹페이지 즐겨찾기