自学内容网 自学内容网

企业级-PDF图片水印

作者:fyupeng
技术专栏:☞ https://github.com/fyupeng
项目地址:☞ https://github.com/fyupeng/distributed-blog-system-api


留给读者

遇到签名,往往很无奈签名的位置、大小。

一、介绍

直接提供PDF路径和图片路径,以及输出路径,就可以完成需要的需求,关键字也可以作为参数传入,根据自行需求修改。

二、代码

public class PdfBuilderUtil {
   
    public static void imageWatermark(String inputPath, String outputPath,String imagePath) throws IOException, com.itextpdf.text.DocumentException {
   
        PdfReader reader = new PdfReader(inputPath);
        PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(outputPath));
        PdfGState gs1 = new PdfGState();
        gs1.setFillOpacity(0.1f);

        InputStream imageIS = new FileInputStream(imagePath);
        Image image = Image.getInstance(IOUtils.toByteArray(imageIS));
        int n = reader.getNumberOfPages();

        InputStream inputStream = new FileInputStream(inputPath);
        PDDocument document = PDDocument.load(inputStream);
        for(int

原文地址:https://blog.csdn.net/F15217283411/article/details/140519315

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!