Java에서 PowerPoint 슬라이드에 오디오 및 비디오 파일을 추가하는 방법
19094 단어 rideopowerpointaudiojava
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();
}
}
산출
Reference
이 문제에 관하여(Java에서 PowerPoint 슬라이드에 오디오 및 비디오 파일을 추가하는 방법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/eiceblue/how-to-add-audio-and-video-files-to-powerpoint-slides-in-java-39h1텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)