失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 关于 Aspose.Pdf添加水印

关于 Aspose.Pdf添加水印

时间:2020-05-22 17:47:55

相关推荐

关于 Aspose.Pdf添加水印

1.使用Aspose.Pdf.BackgroundArtifact 插入底层水印

Aspose.Pdf.Document document = new Aspose.Pdf.Document(pdfPath);for (int i = 1; i <= document.Pages.Count; i++){Aspose.Pdf.BackgroundArtifact artifact = new Aspose.Pdf.BackgroundArtifact();if (document.Pages[i].PageInfo.IsLandscape)//是否横版{artifact.BackgroundImage = File.OpenRead(watermarkLandscapeImgage);}else{artifact.BackgroundImage = File.OpenRead(watermarkImgage);}artifact.Opacity = opacity;artifact.Rotation = rotation;artifact.ArtifactHorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;artifact.ArtifactVerticalAlignment = Aspose.Pdf.VerticalAlignment.Center;document.Pages[i].Artifacts.Add(artifact);}document.Save(pdfPath);document.Dispose();

2.使用Aspose.Pdf.WatermarkArtifact 添加水印

Aspose.Pdf.Document document = new Aspose.Pdf.Document(pdfPath); for (int i = 1; i <= document.Pages.Count; i++){Aspose.Pdf.WatermarkArtifact artifact = new Aspose.Pdf.WatermarkArtifact();artifact.Rotation = rotation;artifact.Opacity = opacity;artifact.ArtifactHorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;artifact.ArtifactVerticalAlignment = Aspose.Pdf.VerticalAlignment.Center;artifact.Type = Aspose.Pdf.Artifact.ArtifactType.Undefined;//artifact.Subtype = Aspose.Pdf.Artifact.ArtifactSubtype.Background; if (document.Pages[i].PageInfo.IsLandscape)//是否横版{artifact.SetImage(File.OpenRead(watermarkLandscapeImgage));}else{Image imgPhoto = Image.FromFile(watermarkImgage); artifact.SetImage(File.OpenRead(watermarkImgage)); }document.Pages[i].Artifacts.Add(artifact);}document.Save(pdfPath);document.Dispose();

3. 使用Aspose.Pdf.ImageStamp(印章)

Aspose.Pdf.Document document = new Aspose.Pdf.Document(pdfPath);for (int i = 1; i <= document.Pages.Count; i++){Image imgPhoto = Image.FromFile(watermarkImgage);var Width = (int)(document.PageInfo.Width / 4);var Height = (int)(document.PageInfo.Height / 4);Aspose.Pdf.ImageStamp imageStamp = new Aspose.Pdf.ImageStamp(watermarkImgage);imageStamp.Quality = 100;imageStamp.Background = false;imageStamp.XIndent = Width;imageStamp.YIndent = Height;imageStamp.Height = imgPhoto.Height*0.72;imageStamp.Width = imgPhoto.Width*0.72;// imageStamp.Rotate = Rotation.on270;imageStamp.Opacity = 0.7;document.Pages[i].AddStamp(imageStamp);}document.Save(pdfPath);document.Dispose();

参考文档:C# 使用Aspose.Pdf给Pdf文件添加文字水印和图片水印 - Shi_zy - 博客园

PDF管理控件Aspose.PDF for .Net使用教程(四十五):在PDF文件中添加图章-控件新闻-慧都网

如果觉得《关于 Aspose.Pdf添加水印》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。