PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Transparent text watermark
https://forum.pdfsharp.net/viewtopic.php?f=2&t=804
Page 1 of 1

Author:  pessi [ Sat Jul 25, 2009 9:13 am ]
Post subject:  Transparent text watermark

Dear All,

I am trying to watermark a pdf with transparency. I used the example code provided.
with a "Alpha" value for Xcolor. The watermark is working nicely but not the transparency.

I checked document.version and it is 14.
I am using the latest version of pdfsharp.

Thank you all in advance,
Prasad.

Author:  Thomas Hoevel [ Mon Jul 27, 2009 9:13 am ]
Post subject:  Re: Transparent text watermark

You need Adobe Acrobat Reader 5.0 or higher to see the transparency.

Do you see transparency if you run the Watermark sample?
If not: wrong Reader version.
If yes: you missed something important while copying from the sample source code.

Author:  pessi [ Thu Jul 30, 2009 10:25 am ]
Post subject:  Re: Transparent text watermark

Thank you for your answer however it still, Doesnt work.

1. I have acrobat reader 8
2. I ran the watermark sample but with a font defined properly (font was not defined the sample example).

PdfDocument source = PdfReader.Open(@"C:\Documents and Settings\prasad\Desktop\sample.pdf");
foreach (PdfPage page in source.Pages)
{
// Variation 1: Draw watermark as text string
// Get an XGraphics object for drawing beneath the existing content
XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend);

// Get the size (in point) of the text
XFont font = new XFont("Georgia", 80, XFontStyle.Regular);
XSize size = gfx.MeasureString("watermark",font);
// Define a rotation transformation at the center of the page
gfx.TranslateTransform(page.Width / 2, page.Height / 2);
gfx.RotateTransform(-Math.Atan(page.Height / page.Width) * 180 / Math.PI);
gfx.TranslateTransform(-page.Width / 2, -page.Height / 2);

// Create a string format
XStringFormat format = new XStringFormat();
format.Alignment = XStringAlignment.Near;
format.LineAlignment = XLineAlignment.Near;

// Create a dimmed red brush
XBrush brush = new XSolidBrush(XColor.FromArgb(128, 255, 0, 0));

// Draw the string
gfx.DrawString("watermark", font, brush,
new XPoint((page.Width - size.Width) / 2, (page.Height - size.Height) / 2),
format);
}
source.Save(@"C:\Documents and Settings\prasad\Desktop\sample1.pdf");
MessageBox.Show("Done.");


3. When I change the alpha value from 128 to "10" or "200" makes no difference.

Can you please help me dig furthur?

Prasad.

Author:  Thomas Hoevel [ Thu Jul 30, 2009 11:38 am ]
Post subject:  Re: Transparent text watermark

pessi wrote:
2. I ran the watermark sample but with a font defined properly (font was not defined the sample example).

Font was defined as "Times New Roman" in the sample (but not in the snippet on the web site).

Have you tried variation 3? See page 3 of the sample output file (this is the only variation where transparency matters because the watermark is drawn on top of the text).

Another snippet from the sample:
Code:
// Set version to PDF 1.4 (Acrobat 5) because we use transparency.
if (document.Version < 14)
  document.Version = 14;

Author:  pessi [ Thu Jul 30, 2009 12:34 pm ]
Post subject:  Re: Transparent text watermark

wow! Thomas, I owe you a beer.

//This did the trick
if (document.Version < 14)
document.Version = 14;

I actually saw this in some other post, but damn, I didnt try it.

Thanks a lot.

Prasad.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/