How can i set an image to a pdf field in existing pdf file?

前端 未结 3 1747
既然无缘
既然无缘 2021-01-18 15:19

\"enter

How can i set an image to a pdf field in existing pdf file?

I\'m usin

3条回答
  •  庸人自扰
    2021-01-18 16:04

    This is the answer that works for placing an image in a specific location. `

        using (PdfStamper stamper = new PdfStamper(new PdfReader(fromFilePath), File.Create("toFilePath")))
                {
                    AcroFields.FieldPosition fieldPosition = stamper.AcroFields.GetFieldPositions("btn1")[0];
    
                    PushbuttonField imageField = new PushbuttonField(stamper.Writer, fieldPosition.position, "btn1Replaced");
                    imageField.Layout = PushbuttonField.LAYOUT_ICON_ONLY;
                    imageField.Image = iTextSharp.text.Image.GetInstance(ImageLocationPath);
                    imageField.ScaleIcon = PushbuttonField.SCALE_ICON_ALWAYS;
                    imageField.ProportionalIcon = false;
                    imageField.Options = BaseField.READ_ONLY;
    
                    stamper.AcroFields.RemoveField("btn1");
                    stamper.AddAnnotation(imageField.Field, fieldPosition.page);
    
                    stamper.Close();
                }
    

提交回复
热议问题