• 给已经存在的PDF文件加水印


     1   static public bool WatermarkPDF(string SourcePdfPath, string OutputPdfPath, string WatermarkPath, int positionX, int positionY, int WatermarkHeight, int WatermarkWidth, out string msg)
     2         {
     3             try
     4             {
     5                 PdfReader reader = new PdfReader(SourcePdfPath);
     6                 PdfStamper stamp = new PdfStamper(reader, new FileStream(OutputPdfPath, FileMode.Create));
     7                 int n = reader.NumberOfPages;
     8                 int i = 0;
     9                 PdfContentByte under;
    10                 iTextSharp.text.Image im = iTextSharp.text.Image.GetInstance(WatermarkPath);
    11                 im.SetAbsolutePosition(positionX, positionY);
    12                 im.ScaleAbsolute(WatermarkWidth, WatermarkHeight);
    13 
    14                 while (i < n)
    15                 {
    16                     i++;
    17                     under = stamp.GetUnderContent(i);
    18                     under.AddImage(im, true);
    19 
    20                 }
    21                 stamp.Close();
    22                 reader.Close();
    23             }
    24             catch (Exception ex)
    25             {
    26                 msg = ex.Message;
    27                 return false;
    28             }
    29             msg = "加水印成功!";
    30             return true;
    31         }
    View Code

    调用方法

    WatermarkPDF("N.pdf", "N1.pdf", "Signer.JPG", 200, 200, 100, 200, out msg)

  • 相关阅读:
    8、泛型程序设计与c++标准模板库5.函数对象
    Linux和Windows系统分区原理
    Linux命令----cd
    为什么会产生TCP/IP?
    区间 dp
    dp-划分数 (递推)
    dp-LCS(递归输出最短合串)
    dp-(LCS 基因匹配)
    位运算符
    求对数
  • 原文地址:https://www.cnblogs.com/wonder223/p/3559347.html
Copyright © 2020-2023  润新知