c# - How to bottom align text in a textbox control in pdf file using itextsharp -
i need bottom align text i'm getting textbox in pdf file.
i'm using below code text textbox in pdf.
(int = 1; <= reader.numberofpages; i++) { itextsharp.text.pdf.pdfarray array = reader.getpagen(i).getasarray(itextsharp.text.pdf.pdfname.annots); if (array == null) continue; (int j = 0; j < array.size; j++) { itextsharp.text.pdf.pdfdictionary annot = array.getasdict(j); itextsharp.text.pdf.pdfstring text = annot.getasstring(itextsharp.text.pdf.pdfname.contents); } }
i'm using itextsharp library. error screenshot
pdfreader reader = new pdfreader(source); pdfstamper stamper = new pdfstamper(reader, target); textfield tf = new textfield(stamper.getwriter(), new rectangle(300, 400, 500, 420), text); stamper.addannotation(tf.gettextfield(), 1); pdfcontentbyte overcontent = stamper.getovercontent(1); basefont basefont = basefont.createfont(); overcontent.setfontandsize(basefont, 12); overcontent.begintext(); overcontent.showtextaligned(pdfcontentbyte.align_bottom, text, 300, 405, 0); overcontent.endtext(); stamper.close ();
or try also
using (pdfstamper stamper = new pdfstamper(new pdfreader(inputfile), file.create(outputfile))) { textfield tf = new textfield(stamper.writer, new itextsharp.text.rectangle(0, 0, 100, 300), "vertical"); stamper.addannotation(tf.gettextfield(), 1); stamper.close(); }
Comments
Post a Comment