PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Apr 27, 2024 12:05 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Sat Jul 25, 2009 9:13 am 
Offline

Joined: Sat Jul 25, 2009 9:07 am
Posts: 6
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.


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 27, 2009 9:13 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 30, 2009 10:25 am 
Offline

Joined: Sat Jul 25, 2009 9:07 am
Posts: 6
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.


Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 30, 2009 11:38 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
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;

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 30, 2009 12:34 pm 
Offline

Joined: Sat Jul 25, 2009 9:07 am
Posts: 6
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.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 404 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group