日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

给pdf文件加水印(aspose)

發布時間:2023/12/13 综合教程 25 生活家
生活随笔 收集整理的這篇文章主要介紹了 给pdf文件加水印(aspose) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

//要jar 加群找群主要。

package com.tythin.tyboot.core.util;

import com.aspose.pdf.Color;
import com.aspose.pdf.Document;
import com.aspose.pdf.FontRepository;
import com.aspose.pdf.FontStyles;
import com.aspose.pdf.PageCollection;
import com.aspose.pdf.Rotation;
import com.aspose.pdf.TextStamp;

import java.io.InputStream;

/**
 * @author kuangQingLin
 * @version 1.0
 * @date 2019/10/21/02115:39
 **/
public class WatermarkPdfUtil {
    public static void main(String[] args) {

        Document pdfDocument = new Document("C:\Users\Administrator\Desktop\采購合同.pdf");

        TextStamp textStamp = new TextStamp("合同水印");
        textStamp.setBackground(true);
        textStamp.setXIndent(200);
        textStamp.setYIndent(100);
        textStamp.setRotate(Rotation.None);
        textStamp.getTextState().setFont( FontRepository.findFont("Arial"));
        textStamp.getTextState().setFontSize(34.0F);
        textStamp.getTextState().setFontStyle(FontStyles.Bold);
        textStamp.getTextState().setFontStyle(FontStyles.Italic);
        textStamp.getTextState().setForegroundColor(Color.getPink());

        TextStamp textStamp1 = new TextStamp("合同水印");
        textStamp1.setBackground(true);
        textStamp1.setXIndent(200);
        textStamp1.setYIndent(400);
        textStamp1.setRotate(Rotation.None);
        textStamp1.getTextState().setFont( FontRepository.findFont("Arial"));
        textStamp1.getTextState().setFontSize(34.0F);
        textStamp1.getTextState().setFontStyle(FontStyles.Bold);
        textStamp1.getTextState().setFontStyle(FontStyles.Italic);
        textStamp1.getTextState().setForegroundColor(Color.getPink());




        TextStamp textStamp2 = new TextStamp("合同水印");
        textStamp2.setBackground(true);
        textStamp2.setXIndent(200);
        textStamp2.setYIndent(700);
        textStamp2.setRotate(Rotation.None);
        textStamp2.getTextState().setFont( FontRepository.findFont("Arial"));
        textStamp2.getTextState().setFontSize(34.0F);
        textStamp2.getTextState().setFontStyle(FontStyles.Bold);
        textStamp2.getTextState().setFontStyle(FontStyles.Italic);
        textStamp2.getTextState().setForegroundColor(Color.getPink());


        PageCollection pages = pdfDocument.getPages();
        int size = pages.size();
        for (int i = 0; i < size; i++) {
            pages.get_Item(i + 1).addStamp(textStamp);
            pages.get_Item(i + 1).addStamp(textStamp1);
            pages.get_Item(i + 1).addStamp(textStamp2);
        }

        pdfDocument.save("C:\Users\Administrator\Desktop\采購合同11.pdf");

    }


    /**
     * 給pdf文件加水印
     * 水印字體不支持宋體,不要亂改字體 !!!
     * @param inputStream 輸入流
     * @param path 輸出路徑
     */
    public static void addWater(InputStream inputStream, String path) {
        Document pdfDocument = new Document(inputStream);

        TextStamp textStamp = new TextStamp("合同水印");
        textStamp.setBackground(true);
        textStamp.setXIndent(200);
        textStamp.setYIndent(100);
        textStamp.setRotate(Rotation.None);
        textStamp.getTextState().setFont( FontRepository.findFont("Arial"));
        textStamp.getTextState().setFontSize(34.0F);
        textStamp.getTextState().setFontStyle(FontStyles.Bold);
        textStamp.getTextState().setFontStyle(FontStyles.Italic);
        textStamp.getTextState().setForegroundColor(Color.getPink());

        TextStamp textStamp1 = new TextStamp("合同水印");
        textStamp1.setBackground(true);
        textStamp1.setXIndent(200);
        textStamp1.setYIndent(400);
        textStamp1.setRotate(Rotation.None);
        textStamp1.getTextState().setFont( FontRepository.findFont("Arial"));
        textStamp1.getTextState().setFontSize(34.0F);
        textStamp1.getTextState().setFontStyle(FontStyles.Bold);
        textStamp1.getTextState().setFontStyle(FontStyles.Italic);
        textStamp1.getTextState().setForegroundColor(Color.getPink());




        TextStamp textStamp2 = new TextStamp("合同水印");
        textStamp2.setBackground(true);
        textStamp2.setXIndent(200);
        textStamp2.setYIndent(700);
        textStamp2.setRotate(Rotation.None);
        textStamp2.getTextState().setFont( FontRepository.findFont("Arial"));
        textStamp2.getTextState().setFontSize(34.0F);
        textStamp2.getTextState().setFontStyle(FontStyles.Bold);
        textStamp2.getTextState().setFontStyle(FontStyles.Italic);
        textStamp2.getTextState().setForegroundColor(Color.getPink());
        PageCollection pages = pdfDocument.getPages();
        int size = pages.size();
        //這里下標從1 開始,切記
        for (int i = 0; i < size; i++) {
            pages.get_Item(i + 1).addStamp(textStamp);
            pages.get_Item(i + 1).addStamp(textStamp1);
            pages.get_Item(i + 1).addStamp(textStamp2);
        }
        pdfDocument.save(path);
    }

}

有疑問:加Q

總結

以上是生活随笔為你收集整理的给pdf文件加水印(aspose)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。