From a087baa089dff361446a7f83951b8bd72b9d5d7e Mon Sep 17 00:00:00 2001 From: OlgunR Date: Fri, 29 May 2026 11:26:25 +0200 Subject: [PATCH] Add stamp to first page of PDF documents MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce functionality to add a stamp to the top-right corner of the first page of a PDF. The stamp includes a white background, a green border, and two lines of text: "✔ VERARBEITET" in bold green font and the current date/time in gray font. The stamp is drawn using `DevExpress.Pdf.PdfDocumentProcessor` and saved to the document's foreground. --- .../Services/PdfResultPackageService.cs | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/DXApp.TemplateKitProject/Services/PdfResultPackageService.cs b/DXApp.TemplateKitProject/Services/PdfResultPackageService.cs index 411621b..f2b8581 100644 --- a/DXApp.TemplateKitProject/Services/PdfResultPackageService.cs +++ b/DXApp.TemplateKitProject/Services/PdfResultPackageService.cs @@ -70,6 +70,54 @@ public class PdfResultPackageService( Data = File.ReadAllBytes(reportPath) }); + // Schritt 4: Stempel auf Seite 1 zeichnen + var firstPage = processor.Document.Pages[0]; + using (var graphics = processor.CreateGraphicsWorldSystem()) + { + // Stempel-Position: oben rechts + // Welt-Koordinaten: Ursprung oben links, X nach rechts, Y nach unten + var stampX = (float)firstPage.CropBox.Width - 200; + var stampY = 20f; + var stampWidth = 175f; + var stampHeight = 50f; + + // Hintergrund weiß + using var whiteBrush = new DevExpress.Drawing.DXSolidBrush( + System.Drawing.Color.White); + graphics.FillRectangle(whiteBrush, + new System.Drawing.RectangleF(stampX, stampY, stampWidth, stampHeight)); + + // Rahmen grün + using var greenPen = new DevExpress.Drawing.DXPen( + System.Drawing.Color.Green, 1.5f); + graphics.DrawRectangle(greenPen, + new System.Drawing.RectangleF(stampX, stampY, stampWidth, stampHeight)); + + // Text Zeile 1: VERARBEITET + using var greenBrush = new DevExpress.Drawing.DXSolidBrush( + System.Drawing.Color.Green); + var fontBold = new DevExpress.Drawing.DXFont( + "Arial", 11, DevExpress.Drawing.DXFontStyle.Bold); + graphics.DrawString( + "✔ VERARBEITET", + fontBold, + greenBrush, + new System.Drawing.PointF(stampX + 8, stampY + 6)); + + // Text Zeile 2: Datum/Uhrzeit + using var grayBrush = new DevExpress.Drawing.DXSolidBrush( + System.Drawing.Color.DimGray); + var fontNormal = new DevExpress.Drawing.DXFont("Arial", 9); + graphics.DrawString( + DateTime.Now.ToString("dd.MM.yyyy HH:mm"), + fontNormal, + grayBrush, + new System.Drawing.PointF(stampX + 8, stampY + 28)); + + graphics.AddToPageForeground( + processor.Document.Pages[0], 96, 96); + } + // Schritt 4: Speichern try {