I have migrated to PdfSharp-1.50b3, but my watermark is not work on this version...
Code:
XFont fontKM = new XFont("Times New Roman", 48, XFontStyle.Bold);
XFont fontStamp = new XFont("Times New Roman", 24, XFontStyle.Regular);
XPen penPart1 = new XPen(XColor.FromArgb(80, 103, 8, 123), 1);
XBrush brushPart1 = new XSolidBrush(XColor.FromArgb(70, 103, 8, 123));
XPen penPart2 = new XPen(XColor.FromArgb(80, 154, 207, 22), 1);
XBrush brushPart2 = new XSolidBrush(XColor.FromArgb(70, 154, 207, 22));
XPen penStamp = new XPen(XColor.FromArgb(80, 0, 0, 0), 1);
XBrush brushStamp = new XSolidBrush(XColor.FromArgb(75, 0, 0, 0));
String strStamp = String.Format(wmarkStamp, DateTime.Now.ToString(DateTimeFormat));
using (PdfDocument resDoc = new PdfDocument())
{
foreach (VWcsDocsRecord item in ccDocuments)
{
using (MemoryStream ms = new MemoryStream(item.FILES))
{
try
{
using (PdfDocument cDoc = PdfReader.Open(ms, PdfDocumentOpenMode.Import))
{
foreach (PdfPage page in cDoc.Pages)
{
PdfPage newPage = resDoc.AddPage(page);
using (XGraphics cnv = XGraphics.FromPdfPage(newPage, XGraphicsPdfPageOptions.Append))
{
// Get the size (in point) of the text
XSize sizePart1 = cnv.MeasureString(wmarkKMPart1, fontKM);
XSize sizePart2 = cnv.MeasureString(wmarkKMPart2, fontKM);
XSize sizeStamp = cnv.MeasureString(strStamp, fontStamp);
// Create a graphical path
XGraphicsPath pathPart1 = new XGraphicsPath();
XGraphicsPath pathPart2 = new XGraphicsPath();
XGraphicsPath pathStamp = new XGraphicsPath();
// Add the text to the path
pathPart1.AddString(wmarkKMPart1, fontKM.FontFamily, fontKM.Style, fontKM.Size,
new XPoint((page.Width - sizePart1.Width - sizePart2.Width) / 2, (page.Height - sizePart1.Height) / 2), XStringFormats.Default);
pathPart2.AddString(wmarkKMPart2, fontKM.FontFamily, fontKM.Style, fontKM.Size,
new XPoint(((page.Width - sizePart1.Width - sizePart2.Width) / 2) + sizePart1.Width, (page.Height - sizePart1.Height) / 2), XStringFormats.Default);
pathStamp.AddString(strStamp, fontStamp.FontFamily, fontStamp.Style, fontStamp.Size,
new XPoint(page.Width / 2, ((page.Height - sizePart1.Height) / 2) + sizePart1.Height * 1.3), XStringFormats.TopCenter);
// Stroke the outline of the path
cnv.DrawPath(penPart1, brushPart1, pathPart1);
cnv.DrawPath(penPart2, brushPart2, pathPart2);
cnv.DrawPath(penStamp, brushStamp, pathStamp);
}
}
realCount++;
}
}
catch (Exception exc)
{
}
}
}
}
The result pdf-file has only original pages without my watermark on library 1.50b3...
Maybe I am doing something wrong...