可用于审核后的pdf文件签字盖章

具体实现代码如下:

     /// <summary>/// 第一页盖章/// </summary>/// <param name="pdfPath">源pdf地址</param>/// <param name="outPdfPath">盖章后生成pdf地址</param>/// <param name="imagePath">盖章图片地址</param>public static void SignFirstPage(string pdfPath, string outPdfPath, string imagePath){//创建盖章后生成pdfSystem.IO.Stream outputPdfStream = new System.IO.FileStream(outPdfPath, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None);//读取原有pdfiTextSharp.text.pdf.PdfReader pdfReader = new iTextSharp.text.pdf.PdfReader(pdfPath);iTextSharp.text.pdf.PdfStamper pdfStamper = new iTextSharp.text.pdf.PdfStamper(pdfReader, outputPdfStream);//获取内容//GetUnderContent 加在内容下层//GetOverContent 加在内容上层//盖章在第一页iTextSharp.text.pdf.PdfContentByte pdfContentByte = pdfStamper.GetUnderContent(1);//获取图片iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(imagePath);//设置图片比例image.ScalePercent(40);//读取pdf文件第一页尺寸iTextSharp.text.Rectangle psize = pdfReader.GetPageSize(1);//设置图片的绝对位置,位置偏移方向为:左到右,下到上image.SetAbsolutePosition(psize.Width / 10 * 7, psize.Height / 10);//图片添加到文档pdfContentByte.AddImage(image);pdfStamper.Close();pdfReader.Close();//直接打开盖章后文件System.Diagnostics.Process.Start(outPdfPath);}
     /// <summary>/// 最后一页盖章/// </summary>/// <param name="pdfPath">源pdf地址</param>/// <param name="outPdfPath">盖章后生成pdf地址</param>/// <param name="imagePath">盖章图片地址</param>public static void SignLastPage(string pdfPath, string outPdfPath, string imagePath){//创建盖章后生成pdfSystem.IO.Stream outputPdfStream = new System.IO.FileStream(outPdfPath, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None);//读取原有pdfiTextSharp.text.pdf.PdfReader pdfReader = new iTextSharp.text.pdf.PdfReader(pdfPath);iTextSharp.text.pdf.PdfStamper pdfStamper = new iTextSharp.text.pdf.PdfStamper(pdfReader, outputPdfStream);//读取页数int pdfPageSize = pdfReader.NumberOfPages;//获取内容//GetUnderContent 加在内容下层//GetOverContent 加在内容上层//盖章在最后一页iTextSharp.text.pdf.PdfContentByte pdfContentByte = pdfStamper.GetUnderContent(pdfPageSize);//获取图片iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(imagePath);//设置图片比例image.ScalePercent(40);//读取pdf文件第一页尺寸iTextSharp.text.Rectangle psize = pdfReader.GetPageSize(1);//设置图片的绝对位置,位置偏移方向为:左到右,下到上image.SetAbsolutePosition(psize.Width / 10 * 7, psize.Height / 10);//图片添加到文档pdfContentByte.AddImage(image);pdfStamper.Close();pdfReader.Close();//直接打开盖章后文件System.Diagnostics.Process.Start(outPdfPath);}
         /// <summary>/// PDF盖章,循环到每页/// </summary>/// <param name="pdfPath">源pdf地址</param>/// <param name="outPdfPath">盖章后生成pdf地址</param>/// <param name="imagePath">盖章图片地址</param>public static void SignEachPage(string pdfPath, string outPdfPath, string imagePath){//读取pdfiTextSharp.text.pdf.PdfReader pdfReader = new iTextSharp.text.pdf.PdfReader(pdfPath);//读取页数int pdfPageSize = pdfReader.NumberOfPages;//创建新pdfSystem.IO.FileStream outputStream = new System.IO.FileStream(outPdfPath, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None);iTextSharp.text.pdf.PdfStamper pdfStamper = new iTextSharp.text.pdf.PdfStamper(pdfReader, outputStream);//文件内容iTextSharp.text.pdf.PdfContentByte waterMarkContent;//读取第一页尺寸iTextSharp.text.Rectangle psize = pdfReader.GetPageSize(1);//读取盖章图片iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(imagePath);//图片缩放到一定百分比image.ScalePercent(40);//设置图片位置,位置偏移方向为:左到右,下到上image.SetAbsolutePosition(psize.Width / 10 * 7, psize.Height / 10);//循环给每页盖章for (int i = 1; i <= pdfPageSize; i++){//GetUnderContent 加在内容下层//GetOverContent 加在内容上层waterMarkContent = pdfStamper.GetUnderContent(i);//添加waterMarkContent.AddImage(image);}pdfStamper.Close();pdfReader.Close();//直接打开盖章后文件System.Diagnostics.Process.Start(outPdfPath);}

最后效果如下图所示


个人记录,不喜勿喷,谢谢

参考文章:C# PdfStamper.GetOverContent方法示例

C# 通过iTextSharp实现pdf文件盖章(通过在内容中插入盖章图片的形式)相关推荐

  1. C#使用iTextSharp操作PDF文件

    概述 html文件怎么转成PDF文件?有的招聘网上的简历导成DOC文件,不能直接使用,这样造成很大的困扰,那么它还有一个格式,那就是html格式.将文件导出成html格式,然后再转成PDF文件,这样便 ...

  2. C#使用iTextSharp给PDF文件添加水印,PDF文件加密,PDF文件旋转

    //添加水印public void AddWaterMark(string filePath, string text){iTextSharp.text.pdf.PdfReader pdfReader ...

  3. itextsharp 获取文本_利用iTextSharp提取PDF文件中的文本内容

    最近测试中需要对比两个PDF文件的内容,当然只是文字没有图表的,但是没有现成的工具可用.于是我的想法是先把PDF转换为Text,然后再对比Text的内容.现在问题的关键变成了如何提取PDF中的文本,在 ...

  4. C#+ItextSharp 查看pdf文件页面尺寸

    1# Nuget下载itextSharp,下载到本地 pm>Install-Package iTextSharp -Version 5.5.10 2# 引用dll,添加命名空间 using iT ...

  5. Zotero科研文献管理 - 将PDF文件同步到Google Driver中,不同电脑无缝使用

    将Zotero中的附件文件比如PDF同步到Dropbox或者Onedrive或者Google Driver中,解决Zotero免费云空间限制,实现足够云空间附件文件存储,并实现不同电脑之间无缝迁移使用 ...

  6. html 在线打开pdf文件怎么打开,在HTML中打开pdf文件怎么打开

    回答: PDF是Portable Document Format的简称,意为"便携式文档格式",是由Adobe Systems用于与应用程序.操作系统.硬件无关的方式进行文件交换所 ...

  7. Android 将PDF文件转Bitmap,并将Bitmap以图片的方式保存到相册

    转自:https://blog.csdn.net/chaogelilun/article/details/85095821 背景: 公司项目要求用户可以在手机端查看发票并将发票已图片的形式保存到相册, ...

  8. CoreIDRAW导出PDF文件时出现部分内容不显示、空白的问题解决方法。

    遇到问题: 在使用CoreIDRAW制作归档文件时,导出PDF文件后出现了部分内容不显示.空白的问题.我的设计是两页BOM表格与一页PCB丝印图.在使用"发布至PDF"导出PDF文 ...

  9. 在html中加入pdf文件吗,如何在网页中显示PDF文件

    我们是不是对百度文库能直接在网页上显示PDF文件感到好奇,你是否也想实现这样的功能?很多朋友认为可以直接在网页中插入代码就可以实现这个功能,其实要在网页中完整地显示PDF文件,需要把PDF文件转换成S ...

最新文章

  1. 怎样的视频监控的管理与运营才算高效
  2. python【力扣LeetCode算法题库】1071. 字符串的最大公因子
  3. MAC显示隐藏文件和文件夹
  4. mysql 支持json_MySQL 5.7 对 JSON 的支持
  5. php遇到Allowed memory size of 134217728 bytes exhausted问题解决方法
  6. spring boot、mybatis集成druid数据库连接池,实现mysql cluster HA负载均衡访问
  7. 03矩阵02——初等变换与高斯消元法、行阶梯形矩阵、行简化阶梯形矩阵、行阶梯形状与方程组解的关系、相抵
  8. The Second Assignment
  9. java社区团购微信小程序源码
  10. FPGA实现AXI4总线的读写
  11. 这是一篇系统的追热点方法论
  12. PPP、PPPOE、PPTP、L2TP应用场合
  13. 学Python用什么系统?
  14. trex刷固件_西數硬盘维修软件TREX指令使用教程.doc
  15. Teager能量算子(TEO)_Python实现
  16. Ubuntu_DNS配置过程记录
  17. 隔夜茶到底能不能喝?
  18. 2018西工大计算机学院学生会,风雨同舟,砥砺前行:计算机学院学生会全体会议暨主席团换届竞选答辩举行...
  19. 用鼠标点击画一个五边形
  20. AjaxPro的应用

热门文章

  1. 计算机基础操作模拟题,自学考试《计算机应用基础》操作模拟练习题(2006下
  2. php设置账号封号,关于封号设置_传奇封号的问题_一些解决方法!
  3. 新手怎么学习网站制作?
  4. 评论:软件创业再度面临生死劫 (转)
  5. linux下qt判断网线是否插入
  6. W5500的最新驱动库
  7. Java基础-Integer的==和equals方法
  8. 【Mybatis+spring整合源码探秘】--- mybatis整合spring事务原理
  9. Allegro PCB覆铜的14个注意事项
  10. 互联网职场真的就像一场《鱿鱼游戏》