PDF添加图片印章是实现文档权威属性的重要手段之一,本文将介绍一种通过Office免费组件Spire.PDF for .NET 来实现PDF添加印章的方法。本文转载自http://www.cnblogs.com/Yesi/p/6141635.html
下面是实现印章添加的全部代码,具体详细步骤可查看原文档,这里不作赘述。
class="c#" name="code"> using System; using System.Drawing; using System.Windows.Forms; using Spire.Pdf; using Spire.Pdf.Annotations; using Spire.Pdf.Annotations.Appearance; using Spire.Pdf.Graphics; namespace addanimagestamptoaPDF_file { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { PdfDocument doc = new PdfDocument(); doc.LoadFromFile(@"E:\Visual Studio\Sample\template7\sample.pdf"); PdfPageBase page = doc.Pages[0]; PdfRubberStampAnnotation loStamp = new PdfRubberStampAnnotation(new RectangleF(new PointF(-5, -5), new SizeF(60, 60))); PdfAppearance loApprearance = new PdfAppearance(loStamp); PdfImage image = PdfImage.FromFile(@"C:\Users\Administrator\Pictures\sample.jpg"); PdfTemplate template = new PdfTemplate(160, 160); template.Graphics.DrawImage(image, 0,0); loApprearance.Normal = template; loStamp.Appearance = loApprearance; page.AnnotationsWidget.Add(loStamp); string output = "ImageStamp.pdf"; doc.SaveToFile(output); } } }
?调试运行该项目程序生成文档。印章添加前/后对比效果如下图所示:
添加前:
?
添加后:
?
当然,你也可以根据需要添加其他类型的印章,这里提供的方法供参考。