zoukankan      html  css  js  c++  java
  • 给已经存在的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)

  • 相关阅读:
    没有上司的舞会
    邮票面值设计
    小木棍
    简单的试炼
    区间质数
    加工生产调度
    泥泞的道路
    总数统计
    中庸之道

  • 原文地址:https://www.cnblogs.com/wonder223/p/3559347.html
Copyright © 2011-2022 走看看