I ended up with this code, it works:
Code:
public static void Buil(Sitzung sitzung)
{
Document document = BuildDocument(sitzung);
DefineStyles(document);
PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfFontEmbedding.Always)
{
Document = document
};
renderer.RenderDocument();
PdfDocument pdfDocument = renderer.PdfDocument;
PdfPage page = pdfDocument.Pages[0];
AddFooter(page, userName);
DocumentRenderer docRenderer = new DocumentRenderer(document);
docRenderer.PrepareDocument();
MemoryStream stream = new MemoryStream();
pdfDocument.Save(stream);
}
public static void AddFooter(PdfPage page, string userName)
{
XGraphics gfx = XGraphics.FromPdfPage(page);
XRect rect = new XRect(new XPoint(), gfx.PageSize);
rect.Inflate(-15, -20);
XFont font = new XFont(Frutiger, 7, XFontStyle.Italic);
XStringFormat format = new XStringFormat
{
Alignment = XStringAlignment.Near,
LineAlignment = XLineAlignment.Far
};
gfx.DrawString($"Ausdruck von {userName} um {DateTime.Now.ToString("dd.MM.yyyy HH:mm")}", font, XBrushes.Black, rect, format);
}