好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

浅谈Java设置PPT幻灯片背景——纯色、渐变、图片背景

ppt幻灯片生成时,系统默认是无色背景填充,幻灯片设计需要手动设置背景效果,可设置颜色填充或者图片背景填充。本文将对此介绍具体实现方法。

jar文件导入方法(参考):

步骤1:在java程序中可新建一个文件夹命名为lib,并将下载包中的jar文件复制到新建的文件夹下。

步骤2:复制文件后,添加到引用类库:选中这个jar文件,点击鼠标右键,选择[build path] – [add to build path]。完成引用。

java示例1:设置背景颜色

1.纯色背景

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

import com.spire.presentation.*; import com.spire.presentation.drawing.*; public class backgroundcolor { public static void main(string[] args) throws exception {

 

  string inputfile = "sample.pptx" ;

  string outputfile = "output/setbackgroundcolor.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.pink);

 

  ppt.savetofile(outputfile, fileformat.pptx_2010);

  ppt.dispose();

  }

}

纯色背景效果:

2.渐变背景

?

1

2

3

4

5

6

7

8

9

10

11

12

13

import java.awt.color; import com.spire.presentation.*; import com.spire.presentation.drawing.*; public class backgroundcolor { public static void main(string[] args) throws exception {

  string inputfile = "test.pptx" ;

  string outputfile = "output/setbackgroundcolor2.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.green); 

  ppt.savetofile(outputfile, fileformat.pptx_2010);

  ppt.dispose();

  }

}

渐变色背景效果:

java示例2:图片背景

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

import com.spire.presentation.*; import com.spire.presentation.drawing.*; public class imagebackground { public static void main(string[] args) throws exception {

  string inputfile = "input.pptx" ;

  string imagefile = "1.png" ;

  string outputfile = "output/imgbackgroundcolor.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();

  }

}

图片背景效果:

 

 

 

以上所述是小编给大家介绍的java设置ppt幻灯片背景——纯色、渐变、图片背景详解整合,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!

原文链接:https://HdhCmsTestimooc测试数据/article/282027

查看更多关于浅谈Java设置PPT幻灯片背景——纯色、渐变、图片背景的详细内容...

  阅读:21次