Hi!
I tried the following code successfully:
Code:
string file = @"D:\PDFsharp\Prepend404\Doc2 whith Append.pdf";
string copy2 = @"D:\PDFsharp\Prepend404\doc2$$$$$$.pdf";
const string text = "My text 2014";
PdfDocument document = PdfReader.Open(file, PdfDocumentOpenMode.Modify);
foreach (PdfPage page_ in document_.Pages)
{
XFont font = new XFont("Times New Roman", 10, XFontStyle.Bold);
XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Append);
XTextFormatter tf = new XTextFormatter(gfx);
XRect rect = new XRect(250, 1, 70, 20);
gfx.DrawRectangle(XBrushes.Blue, rect);
tf.Alignment = XParagraphAlignment.Right;
gfx.DrawString(text, font, XBrushes.Black, rect, XStringFormats.TopLeft);
}
document_.Save(copy2);
I only had your modified Doc2.pdf and the other file to try it with.
As a hack: run your code twice and the watermark should show.
Or give me the unmodified source of Doc2.pdf and I'll have a look after Easter.
BTW: you probably meant to use tf.DrawString(). I didn't try it, but it should make no difference.