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

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -