hi guys.
i have a question to be solved. i am using an image to watermark existing
pdf document.
and this is ok with using GetUnderContent() method. but if there is an
picture attached into the pdf, watermark is not visible on it.
if i use GetOverContent water mark is visible on attached picture but there
is an opacity. i need full transparent dokument.
any i can help me pls?
stamp1 is using GetUnderContent
and stamp2 is using GetOverContent
*public void stamp1(string inputPath, string outputFile, string stamp)
> {
> PdfReader pdfReader = new PdfReader(inputPath);
> iTextSharp.text.Image image =
> iTextSharp.text.Image.GetInstance(stamp);
> //image.Transparency = (new int[] { 1, 1 });
> float h = image.ScaledHeight;
> float w = image.ScaledWidth;
> using (Stream output = new FileStream(outputFile,
> FileMode.Create, FileAccess.Write, FileShare.None))
> {
> using (PdfStamper pdfStamper = new PdfStamper(pdfReader,
> output))
> {
> for (int pageIndex = 1; pageIndex <=
> pdfReader.NumberOfPages; pageIndex++)
> {
> pdfStamper.FormFlattening = false;
> pdfStamper.RotateContents = false;
> iTextSharp.text.Rectangle pageRectangle =
> pdfReader.GetPageSizeWithRotation(pageIndex);
> PdfContentByte pdfData =
> pdfStamper.GetUnderContent(pageIndex);
>
> float width = pageRectangle.Width;
> float height = pageRectangle.Height;
> if (height > width)
> {
> image.Rotation = 0;
> image.ScaleToFit(width - 10, height - 20);
> }
> else
> {
> image.RotationDegrees = (float)Math.PI / 4;
> image.ScaleToFit(height - 10, width - 10);
> }
> image.SetAbsolutePosition(10, 10);
> pdfData.AddImage(image);
> //pdfData.EndText();
> }
> pdfStamper.Close();
> }
> output.Close();
> output.Dispose();
> }
> }*
> *public void stamp2(string inputPath, string outputFile, string
> stamp)
> {
> iTextSharp.text.Image image =
> iTextSharp.text.Image.GetInstance(stamp);
> PdfReader pdfReader = new PdfReader(inputPath);
> using (Stream output = new FileStream(outputFile,
> FileMode.Create, FileAccess.Write, FileShare.None))
> {
> using (PdfStamper pdfStamper = new PdfStamper(pdfReader,
> output))
> {
> for (int pageIndex = 1; pageIndex <=
> pdfReader.NumberOfPages; pageIndex++)
> {
> pdfStamper.FormFlattening = false;
> iTextSharp.text.Rectangle pageRectangle =
> pdfReader.GetPageSizeWithRotation(pageIndex);
> PdfContentByte pdfData =
> pdfStamper.GetOverContent(pageIndex);
>
> pdfData.SetFontAndSize(BaseFont.CreateFont(BaseFont.HELVETICA_BOLD,
> BaseFont.CP1252, BaseFont.NOT_EMBEDDED), 10);
> PdfGState graphicsState = new PdfGState();
> graphicsState.FillOpacity = 0.25F;
> graphicsState.StrokeOpacity = 0.25F;
>
> //graphicsState.BlendMode = PdfGState.BM_NORMAL;
> //pdfData.SetColorFill(BaseColor.YELLOW);
> pdfData.SaveState();
> pdfData.SetGState(graphicsState);
> pdfData.BeginText();
>
> float width = pageRectangle.Width;
> float height = pageRectangle.Height;
>
> if (height > width)
> {
> image.Rotation = 0;
> image.ScaleToFit(width - 10, height - 20);
> }
> else
> {
> image.Rotation = (float)Math.PI / 4;
> image.ScaleToFit(height - 10, width - 10);
> }
> image.SetAbsolutePosition(10, 10);
> //jpeg.Rotation = 45;
> pdfData.AddImage(image);
> pdfData.EndText();
> pdfData.RestoreState();
> }
> pdfStamper.Close();
> }
> output.Close();
> output.Dispose();
> }
> }*
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134791&iu=/4140/ostg.clktrk
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
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