C# PDF 中插入图片

   public static void PDFIMG() {
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile(@"D:");//pdf地址
            int count = doc.Pages.Count;
             
            PdfRubberStampAnnotation loStamp = new PdfRubberStampAnnotation(new RectangleF(new PointF(5, 5), new SizeF(180, 180)));
            PdfAppearance loApprearance = new PdfAppearance(loStamp);
            PdfImage image = PdfImage.FromFile(@"D:");//图片地址
            PdfTemplate template = new PdfTemplate(160, 160);

            template.Graphics.DrawImage(image, 0, 0);

            loApprearance.Normal = template;

            loStamp.Appearance = loApprearance;
            for (int i = 0; i < count; i++)
            {
                PdfPageBase page = doc.Pages[i];
                 page.AnnotationsWidget.Add(loStamp);
            }      
            string output = @"D:";//输出插入后的pdf
            doc.SaveToFile(output);




        }

 

posted @ 2021-11-06 15:05  .就这  阅读(728)  评论(0编辑  收藏  举报