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

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using iTextSharp.text.html.simpleparser;
using iTextSharp.text.pdf;
using iTextSharp.text;
using System.IO;

namespace pdf_test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

private void button1_Click(object sender, EventArgs e)
        {
            string source = @"D:\Sample\18.pdf"; //模板路径
            string output = @"D:\Sample\Chap1018.pdf"; //导出水印背景后的PDF
            string watermark = @"D:\Sample\03.gif";   // 水印图片

bool isSurrcess = PDFWatermark(source, output, watermark, 10, 10);

}

public bool PDFWatermark(string inputfilepath, string outputfilepath, string ModelPicName, float top, float left)
        {
            //throw new NotImplementedException();
            PdfReader pdfReader = null;
            PdfStamper pdfStamper = null;
            try
            {
                pdfReader = new PdfReader(inputfilepath);

int numberOfPages = pdfReader.NumberOfPages;

iTextSharp.text.Rectangle psize = pdfReader.GetPageSize(1);

float width = psize.Width;

float height = psize.Height;

pdfStamper = new PdfStamper(pdfReader, new FileStream(outputfilepath, FileMode.Create));

PdfContentByte waterMarkContent;

iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(ModelPicName);

image.GrayFill = 20;//透明度,灰色填充
                //image.Rotation//旋转
                //image.RotationDegrees//旋转角度
                //水印的位置
                if (left < 0)
                {
                    // left = width - image.Width + left;   //h////////////
                }

//image.SetAbsolutePosition(left, (height - image.Height) - top);     //h////////////
                image.SetAbsolutePosition(136, 36);

//每一页加水印,也可以设置某一页加水印
                for (int i = 1; i <= numberOfPages; i++)
                {
                    waterMarkContent = pdfStamper.GetUnderContent(i);

waterMarkContent.AddImage(image);
                }
                //strMsg = "success";
                return true;
            }
            catch (Exception ex)
            {
                ex.Message.Trim();
                return false;
            }
            finally
            {

if (pdfStamper != null)
                    pdfStamper.Close();

if (pdfReader != null)
                    pdfReader.Close();
            }
        }

//
    }
}

C# PDF添加水印的更多相关文章

  1. 如何在PDF中添加水印,PDF添加水印技巧

    PDF文件现在的使用很是普遍,不管是工作中还是学习中都会使用到PDF文件,制作一个PDF文件就很辛苦的,我们要是想把PDF文件中添加水印防止抄袭的时候应该要怎么做呢,其实吧PDF文件添加水印还挺简单的 ...

  2. PDF如何添加水印,PDF添加水印工具的使用方法

    PDF文件在编辑修改的时候是需要借助工具才可以编辑,PDF文件不像普通的文件可以直接打开编辑,PDF编辑工具是PDF文件进行编辑的重要工具,就以添加水印为例,能够在PDF中添加水印的工具有哪些呢?要怎 ...

  3. PHP使用FPDF pdf添加水印中文乱码问题 pdf合并版本问题

    ---恢复内容开始--- require_once('../fpdf/fpdf.php');require_once('../fpdi/fpdi.php'); 使用此插件 pdf 合并 并添加水印 期 ...

  4. C#使用iTextSharp给PDF添加水印

    代码: /// <summary> /// 添加普通偏转角度文字水印 /// </summary> public static void SetWatermark(string ...

  5. iTextSharp简单生成pdf和操作pdf添加水印

    遇到需要导出页面到pdf,并添加pdf水印的业务.稍微研究了下,借阅网友的前车之鉴,经过使用可行之后的代码贴出来,做个记录,也供需要的网友借阅. public class PDFSetWaterMar ...

  6. java 为pdf添加水印图片

    首先需要引入两个Jar包分别是:iTextAsian.jar .itext-2.1.7.jar  可以去  http://download.csdn.net/detail/work201003/922 ...

  7. C#向pdf 添加水印

    调用直接这样用: //PDFHelper.AddImageWatermarkPDF(path, "D://my.pdf", Server.MapPath("/HtmlTo ...

  8. php pdf添加水印(中文水印,图片水印)

    1.下载软件包 链接:https://pan.baidu.com/s/1cah-mf-SCtfMhVyst_sG8w&shfl=sharepset 提取码:ld8z 2.下载pdf_water ...

  9. PDF上添加水印

    1.整合jar: itext-asian-5.2.0.jar,itextpdf-5.5.10.jar,iTextAsianCmaps.jar 下载:itext的整合jar包 2.使用方法: publi ...

随机推荐

  1. C++ note

    主要是为了学习c++的类和对象   内容摘自 c++概述 http://see.xidian.edu.cn/cpp/biancheng/cpp/rumen_1/   1,变量  ,C++中,我们可以在 ...

  2. Java基础之读文件——使用输入流读取二进制文件(StreamInputFromFile)

    控制台程序,读取Java基础之读文件部分(StreamOutputToFile)写入的50个fibonacci数字. import java.nio.file.*; import java.nio.* ...

  3. Silverlight Popup Bubble

    控件下载地址: http://www.pudn.com/downloads217/sourcecode/others/detail1023372.html silverlight工程引入Liquid. ...

  4. tinyxml安装和使用

    下载: 官方文档:http://www.grinninglizard.com/tinyxmldocs/index.html 中文翻译:http://www.cnblogs.com/kex1n/arch ...

  5. hdu 2528 Area

    2014-07-30 http://acm.hdu.edu.cn/showproblem.php?pid=2528解题思路: 求多边形被一条直线分成两部分的面积分别是多少.因为题目给的直线一定能把多边 ...

  6. CentOS 7 自动更新时间日期

    # ntpdate time.nist.gov 或 # rdate -s time.nist.gov 下列服务器可用 time-nw.nist.gov

  7. ligerui+json_001_实现表格(grid)的后台数据显示、分页

    代码下载地址: http://download.csdn.net/detail/poiuy1991719/8556841 效果: 需要导入的包: 01:编写界面:index.jsp <%@ pa ...

  8. 关于Linux系统basename函数缺陷的思考

    某模块作为前台进程独立运行时,运行命令携带命令行参数:作为某平台下守护进程子进程运行时,需要将命令行参数固化在代码里.类似如下写法: char *argv[] = {"./DslDriver ...

  9. qsort函数用法(转)

    qsort函数用法   qsort 功 能: 使用快速排序例程进行排序  用 法: void qsort(void *base, int nelem, int width, int (*fcmp)(c ...

  10. 手机端js事件支持(event)

    http://blog.163.com/rex_blog/blog/static/1944801012013102743014369/ 所有被测试的浏览器都支持touchstart.touchend和 ...