首页 > 编程语言 >C# Spire.PDF 实现pdf文件盖章

C# Spire.PDF 实现pdf文件盖章

时间:2023-05-05 15:01:43浏览次数:50  
标签:盖章 C# Pdf Spire new PDF pdf

1、添加引用

通过Spire.PDF实现合同盖章,社区版dll(免费,但是只支持10页以内的pdf文档),也可以直接通过VS管理NuGet包添加dll引用,
收费版直接搜索Spire.PDF安装,免费社区版搜索FreeSpire.PDF安装

2、参数定义与调用

string pdfPath = "C:\\Users\\Administrator\\Desktop\\2月份工作报告.pdf";
string imagePath = "C:\\Users\\Administrator\\Desktop\\图片\\20230314161221.jpg";
string outputPath = "C:\\Users\\Administrator\\Desktop\\测试签名文件.pdf";
CreateSign(pdfPath, imagePath, outputPath, 400, 650);

3、具体盖章实现

        /// <summary>
        ///  pdf盖章
        ///  Spire.PDF——收费商用版
        ///  FreeSpire.PDF——免费社区版,但只支持10页以内的pdf文件
        /// </summary>
        /// <param name="pdfPath">源Pdf文件地址</param>
        /// <param name="imagePath">盖章图片地址</param>heng'xiang
        /// <param name="outputPath">盖章后重新生成的pdf地址</param>
        /// <param name="driftX">盖章图片横向偏移</param>
        /// <param name="driftY">盖章图片竖向偏移</param>
        /// <returns></returns>
        public static void CreateSign(string pdfPath, string imagePath, string outputPath, float driftX, float driftY)
        {
            //创建一个PdfDocument类对象,并加载PDF文档
            Spire.Pdf.PdfDocument doc = new Spire.Pdf.PdfDocument();
            doc.LoadFromFile(pdfPath);
            //文档最后一页
            Spire.Pdf.PdfPageBase page = doc.Pages[doc.Pages.Count - 1];
            //新建一个PdfRubberStampAnnotation对象,指定其注释的位置和大小
            Spire.Pdf.Annotations.PdfRubberStampAnnotation loStamp =
            new Spire.Pdf.Annotations.PdfRubberStampAnnotation(
                new System.Drawing.RectangleF(
                    //盖章偏移
                    new System.Drawing.PointF(driftX, driftY),
                    //盖章图片大小
                    new System.Drawing.SizeF(80, 80))
                );
            //实例化一个PdfAppearance对象,并加载作为印章的图片
            Spire.Pdf.Annotations.Appearance.PdfAppearance loApprearance = new Spire.Pdf.Annotations.Appearance.PdfAppearance(loStamp);
            Spire.Pdf.Graphics.PdfImage image = Spire.Pdf.Graphics.PdfImage.FromFile(imagePath);
            //新建一个PDF模板,并在模板里绘制图片
            Spire.Pdf.Graphics.PdfTemplate template = new Spire.Pdf.Graphics.PdfTemplate(150, 150);
            template.Graphics.DrawImage(image, 0, 0);
            loApprearance.Normal = template;
            loStamp.Appearance = loApprearance;
            //添加印章到PDF文档
            page.AnnotationsWidget.Add(loStamp);
            //保存文档
            doc.SaveToFile(outputPath);
            //直接打开文档
            System.Diagnostics.Process.Start(outputPath);
        }
View Code

4、最终效果

 

标签:盖章,C#,Pdf,Spire,new,PDF,pdf
From: https://www.cnblogs.com/lwk9527/p/17374138.html

相关文章

  • 《CTFshow-Web入门》08. Web 71~80
    目录web71知识点题解web72知识点题解web73题解web74题解web75知识点题解web76题解web77知识点题解web78知识点题解web79题解web80知识点题解ctf-web入门web71知识点ob_get_contents():得到输出缓冲区的内容。ob_end_clean():清除缓冲区的内容,并将缓冲区关闭,但不会输出内......
  • C# 通过iTextSharp实现pdf文件盖章(通过在内容中插入盖章图片的形式)
    具体盖章方法实现///<summary>///第一页盖章///</summary>///<paramname="pdfPath">源pdf地址</param>///<paramname="outPdfPath">盖章后生成pdf地址</param>///<paramna......
  • C# 生成印章
    1、界面实现及按钮事件 ///点击按钮事件privatevoidbutton2_Click(objectsender,EventArgse){try{stringimageUrl="C:\\Users\\Administrator\\Desktop\\新建文件夹(2)";stringimageForm......
  • bootstrap-select组件
    bootstrap-select组件mmkkuoi于2021-10-1312:08:55发布10178收藏19分类专栏:js文章标签:bootstrapselect版权华为云开发者联盟该内容已被华为云开发者联盟社区收录加入社区js专栏收录该内容2篇文章0订阅订阅专栏阅读目录一、组件开源地址以及API说......
  • ArcGIS Pro创建、发布、调用GP服务全过程示例(等高线分析)
    在之前的文章介绍过使用ArcMap发布GP分析服务,由于ArcGIS后续不在更新ArcMap,改用ArcGISPro,本文对ArcGISPro发布GP分析服务进行说明。本文以等高线分析为例,使用ArcGISPro软件,从GP分析服务的创建、发布、调用全过程进行演示。使用ArcMap发布GP服务请跳转:本文示例使用(因为本人po......
  • CT感应取电无线测温解决高压柜内测温难题
    安科瑞虞佳豪随着社会经济的不断发展,电力系统向着高电压、高容量的方向前进着,电力系统全新的技术与设备层出不穷,电力的输送能力不断提升。然而,高压电气设备承载的高压电力负荷也让其自身的温升问题成为了威胁电网稳定的元凶,设备温度已经成为了当下电网输电设备稳定运行的重要参数......
  • STM32单片机引脚要职能配置为输入或者输出模式,并不能像51一样准双向,那么如何进行但总
    如题随便找个端口举例对应的程序为 难道需要写之后立即初始化为输入?然后赶紧读?然后再赶紧初始化为输出?再往外写?是的,还真他妈就是这么傻逼的操作 ......
  • ssh远程连接报错ssh_exchange_identification: Connection closed by remote host
    被远程主机拒绝此类报错为原因1:ssh连接数量过多导致如果问题是偶尔能登录一次,大多不能登录,建议往第一点方向排查[root@localhost~]#cat/etc/ssh/sshd_config|grepMaxSessions#MaxSessions10[root@localhost~]#cat/etc/ssh/sshd_config|grepMaxStart#MaxStartups10......
  • CosineSimilarity
    余弦相似度implementation'org.apache.commons:commons-text:1.10.0'MeasurestheCosinesimilarityoftwovectorsofaninnerproductspaceandcomparestheanglebetweenthem.ForfurtherexplanationabouttheCosineSimilarity,refertohttp://en.......
  • el-select数据太多造成页面卡顿?el-select实现触底加载
    当我们使用el-select下拉框的时候,会遇到后端放回的数据太过庞大(成千上万条),导致页面渲染的时候造成卡顿现象。这时候我们可以利用触底加载方法减少资源的消耗,避免页面卡顿。思路:这时候我们可以利用vue的自定义指令,监听到他的下拉滚动事件,当滚动到最后时,(下拉宽高度+可滑动高度距离......