Rank: Administration
Groups: Administrators
Joined: 1/5/2016(UTC) Posts: 1,138
Thanks: 10 times Was thanked: 133 time(s) in 130 post(s)
|
Question:How can I add a watermark when printing a document? The watermark content should by dynamic (usually it's the UserName). Answer:You should create a derived class from PdfPrintDocument and override the OnPrintPage() method. Inside that method you can get access to Graphics to draw your watermark. There is you have two options. Please look at code below Code:
public class PdfPrintDocumentEx : PdfPrintDocument
{
public PdfPrintDocumentEx(PdfDocument Document, int mode = 0) : base(Document, mode)
{
}
//Draw watermark in the background (under page content)
protected override void OnPrintPage(PrintPageEventArgs e)
{
//Draw watermark
e.Graphics.FillRectangle(Brushes.Red, 0, 0, 500, 500);
//Draw page content
base.OnPrintPage(e);
}
//Draw watermark above page content (with transparency)
protected override void OnPrintPage(PrintPageEventArgs e)
{
//Draw page content
base.OnPrintPage(e);
//Draw watermark
e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(50, 255, 0, 0)), 0, 0, 500, 500);
}
}
and printing... Code:
var doc = PdfDocument.Load(@"D:/sample.pdf");
var pd = new PdfPrintDocumentEx(doc);
pd.Print();
Please note, when you drawing watermark in the background it may becomes invisible due to page content is not transparency (scanned pages for example) Edited by user Sunday, May 21, 2017 4:51:31 PM(UTC)
| Reason: Not specified
|
|
|
|
|
|
Rank: Newbie
Groups: Registered
Joined: 5/22/2017(UTC) Posts: 3
Thanks: 1 times
|
Hi, Thanks for the quick reply. Where can I find more information on the dealing with graphics ?
Thanks
|
|
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 1/5/2016(UTC) Posts: 1,138
Thanks: 10 times Was thanked: 133 time(s) in 130 post(s)
|
|
|
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
Important Information:
The Patagames Software Support Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close