国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

Java 創(chuàng)建并應(yīng)用PPT幻燈片母版的方法示例

瀏覽:121日期:2022-05-29 13:21:54

前言

在PowerPoint文檔中,幻燈片母版可供用戶設(shè)置幻燈片的樣式,比如標(biāo)題文字、背景、屬性等。預(yù)先設(shè)定好的幻燈片母版可用于所有幻燈片,此外,也可創(chuàng)建多個(gè)幻燈片母版分別應(yīng)用到幻燈片中。本文將介紹如何創(chuàng)建并應(yīng)用單個(gè)或多個(gè)幻燈片母版。

環(huán)境構(gòu)建

文中演示代碼用到的工具是Free Spire.Presentation for Java,可通過(guò)官網(wǎng)下載獲取。解壓后將位于lib文件夾下的Spire.Presentation.jar導(dǎo)入Java程序。此外,還可通過(guò)maven倉(cāng)庫(kù)安裝導(dǎo)入。

Java代碼示例

示例1 創(chuàng)建唯一母版,并應(yīng)用于所有幻燈片

import com.spire.presentation.*;import com.spire.presentation.drawing.BackgroundType;import com.spire.presentation.drawing.FillFormatType;import com.spire.presentation.drawing.IImageData;import com.spire.presentation.drawing.PictureFillType;import javax.imageio.ImageIO;import java.awt.*;import java.awt.geom.Rectangle2D;import java.awt.image.BufferedImage;import java.io.FileInputStream;public class UniqueSlideMaster { public static void main(String[] args) throws Exception { //創(chuàng)建PPT文檔,指定幻燈片大小 Presentation presentation = new Presentation(); presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9); //獲取第一張母版 IMasterSlide masterSlide = presentation.getMasters().get(0); //獲取圖片地址 String backgroundPic = 'C:UsersTest1DesktopBackground.jpg'; String logo = 'C:UsersTest1Desktoplogo2.png'; //設(shè)置母版背景 BufferedImage image = ImageIO.read(new FileInputStream(backgroundPic)); IImageData imageData = presentation.getImages().append(image); masterSlide.getSlideBackground().setType(BackgroundType.CUSTOM); masterSlide.getSlideBackground().getFill().setFillType(FillFormatType.PICTURE); masterSlide.getSlideBackground().getFill().getPictureFill().setFillType(PictureFillType.STRETCH); masterSlide.getSlideBackground().getFill().getPictureFill().getPicture().setEmbedImage(imageData); //添加圖片(公司Logo)到母版 image = ImageIO.read(new FileInputStream(logo)); imageData = presentation.getImages().append(image); IEmbedImage imageShape = masterSlide.getShapes().appendEmbedImage(ShapeType.RECTANGLE,imageData,new Rectangle2D.Float(40,40,200,100)); imageShape.getLine().setFillType(FillFormatType.NONE); //添加文字(公司名稱)到母版 IAutoShape textShape = masterSlide.getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle2D.Float((float) presentation.getSlideSize().getSize().getWidth()-200,(float) presentation.getSlideSize().getSize().getHeight()-60,200,30));//Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(ppt.SlideSize.Size.Width-200, ppt.SlideSize.Size.Height-60, 200, 30)); textShape.getTextFrame().setText('鷹翔傳媒有限公司'); textShape.getTextFrame().getTextRange().setFontHeight(15f); textShape.getTextFrame().getTextRange().getFill().setFillType(FillFormatType.SOLID); textShape.getTextFrame().getTextRange().getFill().getSolidColor().setColor(Color.blue); textShape.getTextFrame().getTextRange().getParagraph().setAlignment(TextAlignmentType.CENTER); textShape.getFill().setFillType(FillFormatType.NONE); textShape.getLine().setFillType(FillFormatType.NONE); //添加一張幻燈片 presentation.getSlides().append(); //保存文檔 presentation.saveToFile('output/SlideMaster.pptx', FileFormat.PPTX_2013); presentation.dispose(); }}

創(chuàng)建效果:

Java 創(chuàng)建并應(yīng)用PPT幻燈片母版的方法示例

示例2 創(chuàng)建多個(gè)母版并分別應(yīng)用到幻燈片

import com.spire.presentation.*;import com.spire.presentation.drawing.BackgroundType;import com.spire.presentation.drawing.FillFormatType;import com.spire.presentation.drawing.IImageData;import com.spire.presentation.drawing.PictureFillType;import javax.imageio.ImageIO;import java.awt.image.BufferedImage;import java.io.FileInputStream;public class MultiSlideMasters { public static void main(String[] args)throws Exception { //新建PPT文檔 Presentation presentation = new Presentation(); presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9); //插入4頁(yè)幻燈片(連同默認(rèn)的幻燈片,文檔中共5頁(yè)) for (int i = 0; i < 4; i++) { presentation.getSlides().append(); } //獲取默認(rèn)的母版 IMasterSlide first_master = presentation.getMasters().get(0); //創(chuàng)建并獲取第二個(gè)母板 presentation.getMasters().appendSlide(first_master); IMasterSlide second_master = presentation.getMasters().get(1); //為兩個(gè)母版分別設(shè)置不同的背景圖片 String pic1 = 'C:UsersTest1DesktopImage1.jpg'; String pic2 = 'C:UsersTest1DesktopImage2.jpg'; BufferedImage image = ImageIO.read(new FileInputStream(pic1)); IImageData imageData = presentation.getImages().append(image); first_master.getSlideBackground().setType(BackgroundType.CUSTOM); first_master.getSlideBackground().getFill().setFillType(FillFormatType.PICTURE); first_master.getSlideBackground().getFill().getPictureFill().setFillType(PictureFillType.STRETCH); first_master.getSlideBackground().getFill().getPictureFill().getPicture().setEmbedImage(imageData); image = ImageIO.read(new FileInputStream(pic2)); imageData = presentation.getImages().append(image); second_master.getSlideBackground().setType(BackgroundType.CUSTOM); second_master.getSlideBackground().getFill().setFillType(FillFormatType.PICTURE); second_master.getSlideBackground().getFill().getPictureFill().setFillType(PictureFillType.STRETCH); second_master.getSlideBackground().getFill().getPictureFill().getPicture().setEmbedImage(imageData); //在第一頁(yè)應(yīng)用第一個(gè)母版及版式(板式6為空板式) presentation.getSlides().get(0).setLayout(first_master.getLayouts().get(6)); //在剩下的幻燈片應(yīng)用第二個(gè)母版及版式 for (int i = 1; i < presentation.getSlides().getCount(); i++) { presentation.getSlides().get(i).setLayout(second_master.getLayouts().get(6)); } //保存文檔 presentation.saveToFile('output/MultiSlideMaters.pptx', FileFormat.PPTX_2013); presentation.dispose(); }}

創(chuàng)建效果:

Java 創(chuàng)建并應(yīng)用PPT幻燈片母版的方法示例

到此這篇關(guān)于Java 創(chuàng)建并應(yīng)用PPT幻燈片母版的方法示例的文章就介紹到這了,更多相關(guān)Java 創(chuàng)建PPT幻燈片母版內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: ppt
相關(guān)文章:
主站蜘蛛池模板: 宜兰县| 元氏县| 永城市| 尉氏县| 双牌县| 孟连| 淮北市| 泸西县| 青海省| 新丰县| 那曲县| 乌拉特后旗| 方正县| 临漳县| 万宁市| 古蔺县| 高淳县| 进贤县| 马鞍山市| 盐亭县| 微山县| 贡嘎县| 惠安县| 金乡县| 南江县| 凤冈县| 舞阳县| 阿荣旗| 沭阳县| 北宁市| 西乌珠穆沁旗| 舞钢市| 德兴市| 西畴县| 峨山| 遂川县| 马边| 青海省| 黎城县| 浙江省| 崇信县|