tab 1
此演示向您展示如何将文本和图像添加到 powerpoint 文档。
add text
text: | |
font: | |
font size: | |
color: | |
downloads
|
add image
image: |
click here to browse files
|
downloads
|
如果这不是您想要的 demo,您可以通过填写表格获取免费定制 demo。
如您有与我们产品相关的其他技术问题,请联系 该email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用javascript。;销售相关的问题,请联系 该email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用javascript。。
tab 2
package ppt;
import com.spire.presentation.*;
import com.spire.presentation.drawing.fillformattype;
import java.awt.*;
import java.awt.geom.rectangle2d;
public class addtextorimagedemo {
public void addtextorimage(string filepath, string addtype, string text, string imagefile, string resultfilepath) throws exception {
presentation presentation = new presentation();
presentation.loadfromfile(filepath);
switch (addtype){
case "text":
addtext(presentation,text);
break;
case "image":
addimage(presentation,imagefile);
break;
}
presentation.savetofile(resultfilepath,fileformat.pptx_2013);
}
private void addtext(presentation presentation, string text) throws exception {
iautoshape shape = presentation.getslides().get(0).getshapes().appendshape(shapetype.rectangle, new rectangle(50, 70, 620, 150));
shape.getfill().setfilltype(fillformattype.none);
shape.getshapestyle().getlinecolor().setcolor(color.white);
shape.gettextframe().getparagraphs().get(0).setalignment(textalignmenttype.left);
shape.gettextframe().getparagraphs().get(0).setindent(50);
shape.gettextframe().getparagraphs().get(0).setlinespacing(150);
shape.gettextframe().settext(text);
shape.gettextframe().getparagraphs().get(0).gettextranges().get(0).setlatinfont(new textfont("arial rounded mt bold"));
shape.gettextframe().getparagraphs().get(0).gettextranges().get(0).setfontheight(16);
shape.gettextframe().getparagraphs().get(0).gettextranges().get(0).getfill().setfilltype(fillformattype.solid);
shape.gettextframe().getparagraphs().get(0).gettextranges().get(0).getfill().getsolidcolor().setcolor(color.red);
}
private void addimage(presentation presentation, string imagefile) throws exception {
rectangle2d.double rect1 = new rectangle2d.double(presentation.getslidesize().getsize().getwidth() / 2 - 280, 140, 120, 120);
iembedimage image = presentation.getslides().get(0).getshapes().appendembedimage(shapetype.rectangle, imagefile, rect1);
image.getline().setfilltype(fillformattype.none);
}
}
tab 3
using spire.presentation;
using spire.presentation.drawing;
using system;
using system.collections.generic;
using system.drawing;
using system.linq;
using system.text;
using system.threading.tasks;
namespace demoonlinecode
{
class addtextorimage
{
public void addtextorimagedemo(string format, string text, string imagefilepath, string resultfilename)
{
presentation presentation = new presentation();
switch (format)
{
case "text":
addtext(presentation,text,resultfilename);
break;
case "image":
addimage(presentation, imagefilepath, resultfilename);
break;
}
}
private static void addtext(presentation presentation, string text, string resultfilename)
{
iautoshape shape = presentation.slides[0].shapes.appendshape(shapetype.rectangle, new rectanglef(50, 70, 620, 150));
shape.fill.filltype = fillformattype.none;
shape.shapestyle.linecolor.color = color.white;
//set the alignment of paragraph
shape.textframe.paragraphs[0].alignment = textalignmenttype.left;
//set the indent of paragraph
shape.textframe.paragraphs[0].indent = 50;
//set the linespacing of paragraph
shape.textframe.paragraphs[0].linespacing = 150;
//set the text of paragraph
shape.textframe.text = text;
//set the font
shape.textframe.paragraphs[0].textranges[0].latinfont = new textfont("arial rounded mt bold");
shape.textframe.paragraphs[0].textranges[0].fill.filltype = fillformattype.solid;
shape.textframe.paragraphs[0].textranges[0].fill.solidcolor.color = color.black;
presentation.savetofile(resultfilename ".pptx", fileformat.pptx2013);
}
private static void addimage(presentation presentation, string imagefilepath, string resultfilename)
{
rectanglef rect1 = new rectanglef(presentation.slidesize.size.width / 2 - 280, 140, 120, 120);
iembedimage image = presentation.slides[0].shapes.appendembedimage(shapetype.rectangle, imagefilepath, rect1);
image.line.filltype = fillformattype.none;
presentation.savetofile(resultfilename ".pptx", fileformat.pptx2013);
}
}
}