c# - iTextSharp - Position text on top of existing contents -


i have been able absolute position new text x,y co-ordinates new text hides behind existing image. played around stamper, overcontent no success.

here's code using:

pdfreader reader = new pdfreader(new randomaccessfileorarray(filenameexisting), null); rectangle size = reader.getpagesizewithrotation(1);  using (var outstream = new filestream(filenamenew, filemode.create)) {     document document = new document(size);     pdfwriter writer = pdfwriter.getinstance(document, outstream);      document.open();     try     {         pdfcontentbyte cb = writer.directcontent;          cb.begintext();         try         {             cb.setfontandsize(basefont.createfont(), 12);             cb.settextmatrix(10, 100);             cb.showtext("my new text");         }                 {             cb.endtext();         }          pdfimportedpage page = writer.getimportedpage(reader, 1);         cb.addtemplate(page, 0, 0);      }         {         document.close();         writer.close();         reader.close();     } } 

just realised mistake in code. getimportedpage should have been called before setting text. here's updated code:

          try           {             pdfimportedpage page = writer.getimportedpage(reader, 1);             cb.addtemplate(page, 0, 0);             cb.setfontandsize(basefont.createfont(), 12);             cb.settextmatrix(10, 100);             cb.showtext("rando text");            } 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -