关于 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文件中添加图章-控件新闻-慧都网

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值