製做一個精美的PPT文檔,不只要求內容充實、排版得當;同時對於背景顏色的搭配,尤爲是背景圖片的設置也尤其重要。恰當的背景顏色或圖片可以使PPT更加美觀,引人注目。本文就將經過使用Java程序來演示如何給PPT幻燈片添加背景顏色和背景圖片。背景顏色主要分爲純色背景顏色和漸變色背景顏色。html
方法1:經過官方網站下載獲取jar包。解壓後將lib文件夾下的Spire.Presentation.jar文件導入Java程序。(以下圖)
java
方法2:經過maven倉庫安裝導入。具體安裝教程詳見此網頁。app
import com.spire.presentation.*; import com.spire.presentation.drawing.*; public class BackgroundImage { public static void main(String[] args) throws Exception { String inputFile = "C:\\Users\\Test1\\Desktop\\Sample.pptx"; String imageFile = "C:\\Users\\Test1\\Desktop\\Image.jpg"; String outputFile = "output/setBackgroundImage.pptx"; Presentation ppt = new Presentation(); ppt.loadFromFile(inputFile); ppt.getSlides().get(0).getSlideBackground().setType(BackgroundType.CUSTOM); //設置文檔的背景填充模式爲圖片填充 ppt.getSlides().get(0).getSlideBackground().getFill().setFillType(FillFormatType.PICTURE); ppt.getSlides().get(0).getSlideBackground().getFill().getPictureFill().setAlignment(RectangleAlignment.NONE); ppt.getSlides().get(0).getSlideBackground().getFill().getPictureFill().setFillType(PictureFillType.STRETCH); ppt.getSlides().get(0).getSlideBackground().getFill().getPictureFill().getPicture().setUrl((new java.io.File(imageFile)).getAbsolutePath()); ppt.saveToFile(outputFile, FileFormat.PPTX\_2010); ppt.dispose(); } }
背景圖片添加效果:maven
Part 1:添加純色背景顏色ide
import com.spire.presentation.*; import com.spire.presentation.drawing.*; public class PureBackgroundColor { public static void main(String[] args) throws Exception { String inputFile = "C:\\Users\\Test1\\Desktop\\Sample.pptx"; String outputFile = "output/PureBackgroundColor.pptx"; Presentation ppt = new Presentation(); ppt.loadFromFile(inputFile); ppt.getSlides().get(0).getSlideBackground().setType(BackgroundType.CUSTOM); //設置文檔的背景填充模式爲純色填充,設置顏色 ppt.getSlides().get(0).getSlideBackground().getFill().setFillType(FillFormatType.SOLID); ppt.getSlides().get(0).getSlideBackground().getFill().getSolidColor().setColor(java.awt.Color.LIGHT\_GRAY); ppt.saveToFile(outputFile, FileFormat.PPTX\_2010); ppt.dispose(); } }
純色背景顏色添加效果:工具
Part 2: 添加漸變色背景顏色網站
import com.spire.presentation.*; import com.spire.presentation.drawing.*; import java.awt.*; public class GradientColor { public static void main(String[] args) throws Exception { String inputFile = "C:\\Users\\Test1\\Desktop\\Sample.pptx"; String outputFile = "output/setGradientColor.pptx"; Presentation ppt = new Presentation(); ppt.loadFromFile(inputFile); ppt.getSlides().get(0).getSlideBackground().setType(BackgroundType.CUSTOM); //設置文檔的背景填充模式爲漸變色填充,設置顏色 ppt.getSlides().get(0).getSlideBackground().getFill().setFillType(FillFormatType.GRADIENT); ppt.getSlides().get(0).getSlideBackground().getFill().getGradient().getGradientStops().append(0, Color.white); ppt.getSlides().get(0).getSlideBackground().getFill().getGradient().getGradientStops().append(1,Color.darkGray); ppt.saveToFile(outputFile, FileFormat.PPTX\_2010); ppt.dispose(); } }
漸變色背景顏色添加效果:spa
(本文完)code