Change Background Image in Itext to watermark or alter opacity c# ASP.net -


i want make background image in itext transparent

here code image:

    string root = server.mappath("~");     string parent = path.getdirectoryname(root);     string grandparent = path.getdirectoryname(parent);     string imagefilepath = parent + "/images/logo.png";     itextsharp.text.image jpg = itextsharp.text.image.getinstance(imagefilepath);     jpg.scaletofit(1700, 800);     jpg.alignment = itextsharp.text.image.underlying;     jpg.setabsoluteposition(100, 250);     jpg.scaleabsoluteheight(500);     jpg.scaleabsolutewidth(500); 

any idea?

please take @ backgroundtransparant example. variation on backgroundimage example.

in code, you're adding image document instance. that's ok, if want make such image transparent, need introduce soft mask. that's not difficult, there's easier way make background transparent: add image direct content, , introduce pdfgstate defining opacity:

pdfcontentbyte canvas = writer.getdirectcontentunder(); image image = image.getinstance(image); image.setabsoluteposition(0, 0); canvas.savestate(); pdfgstate state = new pdfgstate(); state.setfillopacity(0.6f); canvas.setgstate(state); canvas.addimage(image); canvas.restorestate(); 

compare background_image.pdf background_transparent.pdf see difference.

my example written in java, it's easy port c#:

pdfcontentbyte canvas = writer.directcontentunder; image image = image.getinstance(image); image.setabsoluteposition(0, 0); canvas.savestate(); pdfgstate state = new pdfgstate(); state.fillopacity = 0.6f; canvas.setgstate(state); canvas.addimage(image); canvas.restorestate(); 

Comments

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -