java - Is there a way to set the font using pdfcanvas in iText when adding a header? -
i"m using page event add header , footer in pdf using itext. header needs different color, i'm not sure how change color of text. there doesn't seem function calls change text color, how paragraphs have.
@override public void handleevent(event event) { pdfdocumentevent docevent = (pdfdocumentevent) event; if (docevent.getdocument().getpagenumber(docevent.getpage()) != 1) { try { pdfcanvas canvas = new pdfcanvas(docevent.getpage()); canvas.begintext(); canvas.setfontandsize(pdffontfactory.createfont(fontconstants.helvetica_oblique), 24); canvas.movetext(50, pagesize.a4.getheight() - 50) .showtext("header") .endtext() .release(); } catch (ioexception e) { e.printstacktrace(); } catch (java.io.ioexception ex) { logger.getlogger(pdfheaderpagenumberevt.class.getname()).log(level.severe, null, ex); } } }
the pdfcanvas
object has setfillcolorrgb()
method.
canvas.movetext(50, pagesize.a4.getheight() - 50) .setfillcolorrgb(255,0,0) // red .showtext("header") .endtext() .release();
will produce header in red.
Comments
Post a Comment