java - Watermark in itextsharp is not displaying properly -


i'm using itextsharp populate data pdf templates, created in openoffice. populating fine, i'm getting proper pdf, watermark not displaying properly.

below code:

public void addwatermark(pdfstamper stamper, int pagenumber, watermark watermark)     {         list<watermarkfield> watermarkfields = watermark.getwatermarkfieldasreference();         (watermarkfield watermarkfield : watermarkfields) {             // setting font , font size watermark text             font font = new font(fontfamily.helvetica, watermarkfield.getfontsize(), font.bold, new graycolor(0.75f));             // setting alignment watermark             columntext.showtextaligned(stamper.getundercontent(pagenumber), element.align_center, new phrase(watermarkfield.gettext(), font), watermarkfield.getxdirection(), watermarkfield.getydirection(), watermarkfield.getrotation());         }      }  

when putting in background text-boxes hiding watermark.
when putting in foreground watermark hiding text.
both screen shorts attaching below.

enter image description here

enter image description here

please suggest me solution. thanks.

in this answer there ideas on how add watermarks (in under content, in on content, both in under content , in on content before bitmaps.,,,).

the missing use case, transparent mark in on content, can generated this:

void addsimpletransparentpatterntoovercontent(file source, file target) throws ioexception, documentexception {     pdfreader reader = new pdfreader(source.getpath());     outputstream os = new fileoutputstream(target);     pdfstamper stamper = new pdfstamper(reader, os);      pdfpatternpainter painter = stamper.getovercontent(1).createpattern(200, 150);     painter.setcolorfill(basecolor.green);     painter.begintext();     painter.settextmatrix(affinetransform.gettranslateinstance(0, 50));     painter.setfontandsize(basefont.createfont(), 100);     painter.showtext("test");     painter.endtext();      pdfgstate state = new pdfgstate();     state.setfillopacity(0.5f);      (int = reader.getnumberofpages(); > 0; i--)     {         pdfcontentbyte overcontent = stamper.getovercontent(i);          overcontent.setgstate(state);         overcontent.setcolorfill(new patterncolor(painter));         overcontent.rectangle(200, 300, 200, 150);         overcontent.fill();     }      stamper.close();     os.close(); } 

in spirit of other answer mark generated using pattern prevent watermark appearing in copy&paste outputs.

you can change transparency / opacity selecting different value in state.setfillopacity(0.5f).


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -