java - Rotating PDFContentByte Overlay Content -
i have created watermark text vertically centered.
this line used
pdfpatternpainter.showtextalignedkerned(element.align_middle, string, x, y, -90);
what want make watermark diagonal. changing angle value make diagonal, x,y position not centered anymore.
this current method
public static void createwatermarkpdf(arraylist<string> watermark, pdfreader reader, pdfstamper stamper) throws exception { rectangle pagesize = reader.getpagesize(1); final float watermark_page_angle = 270; basefont font = basefont.createfont(basefont.helvetica, basefont.winansi, basefont.not_embedded); pdfpatternpainter painter = stamper.getovercontent(1).createpattern(pagesize.getwidth(), pagesize.getheight()); painter.setcolorstroke(new basecolor(192, 192, 192)); int font_size = 80; painter.begintext(); painter.settextrenderingmode(pdfpatternpainter.text_render_mode_fill); painter.setfontandsize(font, font_size); (int i=0; i<watermark.size(); i++) { string string = watermark.get(i); // values opposite since doing vertical alignment angle float width = font.getascentpoint(string, font_size) + font.getdescentpoint(string, font_size); float height = painter.geteffectivestringwidth(string, true); float x = (pagesize.getwidth() - width) / 2; if (i == 0) x += (width * 3); else if (i == 2) x -= (width * 3); painter.showtextalignedkerned(element.align_middle, string, x, util.transformy(pagesize, (pagesize.getheight() - height) / 2), watermark_page_angle); } painter.endtext(); // transparency of watermark pdfgstate state = new pdfgstate(); state.setfillopacity(0.1f); (int i=reader.getnumberofpages(); i>0; i--) { rectangle thispagesize = reader.getpagesize(i); pdfcontentbyte overcontent = stamper.getovercontent(i); overcontent.setcolorfill(new patterncolor(painter)); overcontent.setgstate(state); overcontent.rectangle(thispagesize.getleft(), thispagesize.getbottom(), thispagesize.getwidth(), thispagesize.getheight()); overcontent.fill(); } }
it draws vertical lines , centered. watermark arraylist. can add 3 strings.
if change angle , 300 (or -60) make diagonal, positioning whacked. need use affinetransform here? although tried, didnt work me unless lacked here?
Comments
Post a Comment