如何在演示文稿幻灯片中添加图像和文本水印

“水印”的含义有不同的概念,但是通常我们需要在文档中添加水印是为了防止他人进行未经授权的复制,或者是在文档中添加背景以显示公司徽标。 本节将向您展示如何在Java应用程序的PowerPoint文档中添加文本水印和图像水印。

添加图像水印
图像watermakr用于使演示幻灯片更具吸引力,并显示演示幻灯片的版权信息。 演示幻灯片上的图像水印实际上是使其看起来像水印的图像背景。

import com.spire.presentation.* ;
import com.spire.presentation.drawing.FillFormatType ;
import com.spire.presentation.SlideBackground ;
import com.spire.presentation.drawing.* ;
import javax.imageio.ImageIO ;
import java.awt.image.BufferedImage ;
import java.io.FileInputStream ;


public class ImageWatermark {
    public static void main ( String [] args ) throws Exception {

        //Create a PPT document and load file
        Presentation presentation = new Presentation ();
        presentation . loadFromFile ( "Sample.pptx" );

        //presentation.getSlides().get(0).getSlideBackground().getType()= presentation.;
        BufferedImage bufferedImage = ImageIO . read ( new FileInputStream ( "ima.png" ));
        IImageData imageData = presentation . getImages (). append ( bufferedImage );

        //apply the image to the specific slide as background
        SlideBackground background = presentation . getSlides (). get ( 1 ). getSlideBackground ();
        background . setType ( BackgroundType . CUSTOM );
        background . getFill (). setFillType ( FillFormatType . PICTURE );
        background . getFill (). getPictureFill (). setFillType ( PictureFillType . STRETCH );
        background . getFill (). getPictureFill (). getPicture (). setEmbedImage ( imageData );

        //save the file
        presentation . saveToFile ( "output/ImageWatermark.pptx" , FileFormat . PPTX_2013 );
        presentation . dispose ();
    }
}

演示幻灯片上图像水印的输出:

图像水印

添加文字水印

文本水印基于形状,并且使用形状的锁定属性来保护形状不被编辑或复制。

import com.spire.presentation.* ;
import com.spire.presentation.drawing.FillFormatType ;
import java.awt.* ;
import java.awt.geom.Rectangle2D ;

public class TextWatermark {
    public static void main ( String [] args ) throws Exception {

        //Create a PPT document and load file
        Presentation presentation = new Presentation ();
        presentation . loadFromFile ( "Sample.pptx" );

        //Set the width and height of watermark string
        int width = 400 ;
        int height = 300 ;
        //Define a rectangle range
        Rectangle2D . Double rect = new Rectangle2D . Double (( presentation . getSlideSize (). getSize (). getWidth () - width ) / 2 ,
                ( presentation . getSlideSize (). getSize (). getHeight () - height ) / 2 , width , height );

        //Add a rectangle shape with a defined range
        IAutoShape shape = presentation . getSlides (). get ( 0 ). getShapes (). appendShape ( ShapeType . RECTANGLE , rect );

        //Set the style of shape
        shape . getFill (). setFillType ( FillFormatType . NONE );
        shape . getShapeStyle (). getLineColor (). setColor ( Color . white );
        shape . setRotation (- 45 );
        shape . getLocking (). setSelectionProtection ( true );
        shape . getLine (). setFillType ( FillFormatType . NONE );

        //Add text to shape
        shape . getTextFrame (). setText ( "E-iceblue" );
        PortionEx textRange = shape . getTextFrame (). getTextRange ();

        //Set the style of the text range
        textRange . getFill (). setFillType ( FillFormatType . SOLID );
        textRange . getFill (). getSolidColor (). setColor ( Color . pink );
        textRange . setFontHeight ( 50 );

        //Save the document
        presentation . saveToFile ( "output/TextWatermark.pptx" , FileFormat . PPTX_2010 );
    }
}

演示幻灯片上的文本水印输出:
文字水印

From: https://dev.to/eiceblue/how-to-add-image-and-text-watermark-to-presentation-slides-bib

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值