欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C#教程

當(dāng)前位置:主頁 > 軟件編程 > C#教程 >

C#利用iTextSharp添加PDF水印

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C#教程|點擊: 次

本文實例為大家分享了使用的是iTextSharp添加PDF水印的具體代碼,供大家參考,具體內(nèi)容如下

需要iTextSharp.dll, 下載地址http://sourceforge.net/projects/itextsharp/

public void Test()
    {
      Watermark(@"E:\日常工作\12084347 config.pdf", @"E:\日常工作\12084347 config wm.pdf", @"E:\日常工作\wm.png");
}    
 public bool AddWatermark(string inputPath, string outputPath, string watermarkPath, ref string error)
    {
      try
      {
        PdfReader pdfReader = new PdfReader(inputPath);
        int numberOfPages = pdfReader.NumberOfPages;
        FileStream outputStream = new FileStream(outputPath, FileMode.Create);
        PdfStamper pdfStamper = new PdfStamper(pdfReader, outputStream);
        PdfContentByte waterMarkContent;

        iTextSharp.text.Image image = null;
        if (string.IsNullOrEmpty(watermarkPath))
        {
          Stream s = GetType().Assembly.GetManifestResourceStream("WatermarkTool.wm.png");
          image = iTextSharp.text.Image.GetInstance(s);
        }
        else
        {
          image = iTextSharp.text.Image.GetInstance(watermarkPath);
        }        
        image.SetAbsolutePosition(100, 100);
        for (int i = 1; i <= numberOfPages; i++)
        {
          waterMarkContent = pdfStamper.GetUnderContent(i);
          waterMarkContent.AddImage(image);
        }
        pdfStamper.Close();
        pdfReader.Close();
        outputStream.Close();
        return true;
      }
      catch (Exception ex)
      {
        error = ex.StackTrace;
        return false;
      }
    }

 //選擇文件夾
    private void textBox2_DoubleClick(object sender, EventArgs e)
    {
      FolderBrowserDialog dialog = new FolderBrowserDialog();
      dialog.Description = label2.Text;
      if (dialog.ShowDialog() == DialogResult.OK)
      {
        textBox2.Text = dialog.SelectedPath;
      }
    }

    //選擇文件
    private void textBox3_DoubleClick(object sender, EventArgs e)
    {
      OpenFileDialog fileDialog = new OpenFileDialog();
      fileDialog.Multiselect = true;
      fileDialog.Title = label3.Text;
      fileDialog.Filter = "*.jpg|*.jpg|*.jpeg|*.jpeg|*.bmp|*.bmp|*.gif|*.gif|*.png|*.png|*.Tiff|*.Tiff|*.Wmf|*.Wmf";
      if (fileDialog.ShowDialog() == DialogResult.OK)
      {
        textBox3.Text = fileDialog.FileName;
      }
    }

 //啟動線程
    private void button1_Click(object sender, EventArgs e)
    {
      if (Directory.Exists(textBox1.Text) == false )
      {
        MessageBox.Show(label1.Text, "Require input", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        textBox1.Focus();
        return;
      }
      if (Directory.Exists(textBox2.Text) == false)
      {
        MessageBox.Show(label2.Text, "Require input", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        textBox2.Focus();
        return;
      }
      if ( textBox3.Enabled && File.Exists(textBox3.Text) == false)
      {
        MessageBox.Show(label3.Text, "Require input", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        textBox3.Focus();
        return;
      }

      richTextBox1.Clear();
      button1.Enabled = false;
      Thread thread = new Thread(new ThreadStart(this.BatchDo));

      thread.IsBackground = true;
      thread.Start(); 
    }

 public delegate void SetControlValue(string message);
    //在線程中修改控件屬性
    public void AppendRTBText(string text)
    {
      if (richTextBox1.InvokeRequired)
      {
        SetControlValue cal = delegate(string s) { richTextBox1.AppendText(s); };
        this.Invoke(cal, text);
      }
      else
      {
        richTextBox1.AppendText(text);
      }
    }

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。

上一篇:FtpHelper實現(xiàn)ftp服務(wù)器文件讀寫操作(C#)

欄    目:C#教程

下一篇:C# 讀寫XML(代碼分享)

本文標(biāo)題:C#利用iTextSharp添加PDF水印

本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/5817.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有