c# - Adding borders and background color with iTextSharp to PdfFormField -
i want add borders , background color pdfformfield. background color activated after write text field before white. , can't borders show up.
this code:
public void addfield(pdfwriter writer, string name, int x, int y, int w, int h, pdfcontentbyte cb, int maxsize, string text, basefont font, int border) { rectangle rec = new rectangle(x, y-h, x+w, y); // change font widths //basefont font = basefont.createfont("c:\\windows\\fonts\\calibri.ttf", basefont.cp1252, basefont.not_embedded); float fontsize = 12; //int[] widths = font.widths; //for (int k = 0; k < widths.length; k++) //{ //if (widths[k] != 0) //widths[k] = width; //} font.forcewidthsoutput = true; string = "0123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz-*/+.,\"'():;,?./!$+=_{[]}&éèàêîâ"; //color textcolor = basecolor.red; // create acroform textfield pdfformfield field = pdfformfield.createtextfield(writer, pdfformfield.singleline, pdfformfield.plaintext, maxsize); field.fieldname = name; field.defaultvalueasstring = text; //ield.gettextfield(); field.mkbackgroundcolor = basecolor.red; //field.backgroundcolor = new graycolor(0.75f); //field.bordercolor = graycolor.grayblack; //field.borderwidth = 1; //field.borderstyle = pdfborderdictionary.style_beveled; field.setfieldflags(pdfannotation.flags_print); field.setpage(); writer.addannotation(field); // position field on page field.setwidget(rec, pdfannotation.highlight_invert); // create apperance field size , font match want pdfappearance tp = cb.createappearance(rec.right-rec.left, rec.top-rec.bottom); pdfappearance da = (pdfappearance)tp.duplicate; da.setfontandsize(font, fontsize); da.setcolorfill(basecolor.red); field.defaultappearancestring = da; // fill default value of field tp.beginvariabletext(); tp.savestate(); tp.rectangle(rec); tp.clip(); tp.newpath(); tp.begintext(); tp.setfontandsize(font, fontsize); tp.setcolorfill(basecolor.black); tp.settextmatrix(100,100); tp.showtext(all); tp.settextmatrix(2,(rec.top-rec.bottom)/2-(fontsize*0.3f)); tp.showtext(text); tp.endtext(); tp.restorestate(); tp.endvariabletext(); field.setappearance(pdfannotation.appearance_normal, tp); }
Comments
Post a Comment