c# - Not able to write multiple annotation images in itextsharp -


here trying add images overlay on text.so used pushbutton , annotations. can write 1 image.not able write second image onwards.please me

pdfreader reader1 = new pdfreader(path); filestream fs = new filestream(outlocation, filemode.create,    fileaccess.write,fileshare.none); pdfstamper stamper = new pdfstamper(reader1, fs); pushbuttonfield fld = new pushbuttonfield(stamper.writer,     new itextsharp.text.rectangle(315, 400, 210, 250), "test "); fld.layout = pushbuttonfield.layout_icon_only; string img = path + "redslash.png"; itextsharp.text.image jpeg = itextsharp.text.image.getinstance(img); jpeg.scaletofit(100, 200); fld.image = jpeg; stamper.addannotation(fld.field, 1); fld1 = new pushbuttonfield(stamper.writer,     new  itextsharp.text.rectangle(500, 500, 210, 250), "test "); fld1.layout = pushbuttonfield.layout_icon_only;         itextsharp.text.image jpeg1 = itextsharp.text.image.getinstance(img); jpeg1.scaletofit(100, 200); fld1.image = jpeg1; stamper.addannotation(fld1.field, 1); 

answer 1 question was: make sure different fields have different names. fixed based on comment , worked.

answer 2 question is: don't use form fields add images, add images "the normal way". asked me code sample, i'm giving chapter of book: working existing pdfs. in chapter, you'll find some examples involving pdfstamper class. can find c# version of these examples here.

some code:

using (pdfstamper stamper = new pdfstamper(reader, ms)) {     image img = image.getinstance(imagepath);     img.setabsoluteposition(0, 0);     int n = reader.numberofpages;     pdfcontentbyte foreground;     (int = 1; <= n; i++) {         foreground = stamper.getovercontent(i);         foreground.addimage(img);     } } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -