Hi all,
For the past few days, I've been dealing with a curious problem with a
project I'm working on. I am simply trying to add a dynamic watermark to an
existing PDF document by adding a PdfTemplate to a PdfContentByte instance.
It has worked fine for all of the documents I've used it with except for a
few that are scanned documents given to me by an outside source. For some
reason, when printing the watermark, a white, opaque box appears around the
text, like a bounding box for the PdfTemplate object. Here is a snippet of
what I am doing:
PdfTemplate pt = cb.CreateTemplate(pagesize.Width, pagesize.Height);
PdfGState pdfgstate = new PdfGState();
BaseFont watermarkFont = BaseFont.CreateFont(BaseFont.HELVETICA,
BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
pt.SetGState(pdfgstate);
pt.BeginText();
pdfgstate.FillOpacity = 0.25f;
pt.SetRGBColorFill(0x66, 0x66, 0x66);
pt.SetFontAndSize(watermarkFont, 64f);
pt.ShowTextAligned(PdfContentByte.ALIGN_LEFT, watermarktext, x, y,
rotation); (these variables are passed in to the method).
pt.EndText();
cb.AddTemplate(pt, 0, 0);
So far, I have found two things that help remedy this problem, but no
perfect solution. Option 1 is if I don't use the pdfgstate, which causes me
to lose the transparency (not good for watermarks), but does fix the opaque
white box issue. Option 2 is to leave the pdfgstate as it is, but to add the
line "pdfgstate.TextKnockout = false;", which removes the white box around
the entire watermark text, but leaves white opaque boxes around the
individual letters. I could not find any documentation for TextKnockout, not
even in the book. I have also experimented with different combinations of
the PdfGState's OverPrintMode, BlendMode, and OverPrintNonStroking/Stroking,
etc... properties to no avail.
It seems like the issue could be me doing something blatantly incorrect in
my code, but since it works for all other documents besides the ones scanned
from a particular source, I am inclined to believe it is some weirdness with
the PDF file I am reading in.
Thanks in advance for shedding any light on this mysterious dilemma!
- Stu
------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php