tab 1
此演示向您展示如何将文本水印和图像水印添加到 powerpoint 文档。
set text watermark
text: | |
font: | |
font size: | |
color: | |
rotate: |
e-iceblue
|
downloads
|
set image watermark
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.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.file;
public class watermarkdemo {
public void watermark(string filepath, string watermarktype, string text, string imagefile, string resultfilepath) throws exception {
presentation presentation = new presentation();
presentation.loadfromfile(filepath);
switch (watermarktype){
case "text":
addtextwatermark(presentation,text);
break;
case "image":
file file = new file(imagefile);
bufferedimage bufferedimage = imageio.read(file);
addimagewatermark(presentation,bufferedimage);
break;
}
presentation.savetofile(resultfilepath,fileformat.pptx_2013);
}
private void addtextwatermark(presentation presentation, string text) throws exception {
int width= 400;
int height= 300;
rectangle2d.double rect = new rectangle2d.double((presentation.getslidesize().getsize().getwidth() - width) / 2,
(presentation.getslidesize().getsize().getheight() - height) / 2, width, height);
for (int i = 0; i< presentation.getslides().getcount();i ){
iautoshape shape = presentation.getslides().get(i).getshapes().appendshape(shapetype.rectangle,rect);
shape.getfill().setfilltype(fillformattype.none);
shape.getshapestyle().getlinecolor().setcolor(color.white);
shape.setrotation(-45);
shape.getlocking().setselectionprotection(true);
shape.getline().setfilltype(fillformattype.none);
shape.gettextframe().settext(text);
portionex textrange = shape.gettextframe().gettextrange();
textfont font = new textfont("arial rounded mt bold");
textrange.setlatinfont(font);
textrange.getfill().setfilltype(fillformattype.solid);
textrange.getfill().getsolidcolor().setcolor(color.red);
textrange.setfontheight(22);
}
}
private void addimagewatermark(presentation presentation, bufferedimage bufferedimage) throws documenteditexception {
iimagedata image = presentation.getimages().append(bufferedimage);
for (int i = 0; i< presentation.getslides().getcount();i ) {
islide slide = presentation.getslides().get(i);
slide.getslidebackground().settype(backgroundtype.custom);
slide.getslidebackground().getfill().setfilltype(fillformattype.picture);
slide.getslidebackground().getfill().getpicturefill().setfilltype(picturefilltype.stretch);
slide.getslidebackground().getfill().getpicturefill().getpicture().setembedimage(image);
}
}
}
tab 3
using spire.presentation;
using spire.presentation.drawing;
using system.drawing;
using system.windows.forms;
namespace demoonlinecode
{
class addwatermark
{
public void addtextorimagewatermarkdemo(string filepath,string format,string text, string imagepath, string resultfilename)
{
presentation presentation = new presentation();
presentation.loadfromfile(filepath);
switch (format)
{
case "text":
addtextwatermark(presentation,text,resultfilename);
break;
case "image":
addimagewatermark(presentation,imagepath,resultfilename);
break;
}
}
private static void addtextwatermark(presentation presentation, string text, string resultfilename)
{
form frm = new form();
graphics gc = frm.creategraphics();
sizef size = gc.measurestring(text, new font("lucida sans unicode", 50));
//define a rectangle range
rectanglef rect = new rectanglef((presentation.slidesize.size.width - size.width) / 2, (presentation.slidesize.size.height - size.height) / 2, size.width, size.height);
foreach (islide slide in presentation.slides)
{
iautoshape shape =slide.shapes.appendshape(shapetype.rectangle, rect);
//set the style of the shape
shape.fill.filltype = fillformattype.none;
shape.shapestyle.linecolor.color = color.white;
shape.rotation = -45;
shape.locking.selectionprotection = true;
shape.line.filltype = fillformattype.none;
//add text to the shape
shape.textframe.text = text;
textrange textrange = shape.textframe.textrange;
//set the style of the text range
textrange.fill.filltype = fillformattype.solid;
textrange.fill.solidcolor.color = color.fromargb(120, color.hotpink);
textrange.fontheight = 50;
}
presentation.savetofile(resultfilename ".pptx", fileformat.pptx2013);
}
private static void addimagewatermark(presentation presentation, string imagefile, string resultfilename)
{
iimagedata image = presentation.images.append(image.fromfile(imagefile));
foreach (islide slide in presentation.slides)
{
slide.slidebackground.type = backgroundtype.custom;
slide.slidebackground.fill.filltype = fillformattype.picture;
slide.slidebackground.fill.picturefill.filltype = picturefilltype.stretch;
slide.slidebackground.fill.picturefill.picture.embedimage = image;
}
presentation.savetofile(resultfilename ".pptx", fileformat.pptx2013);
}
}
}