Hi,
I am trying to add watermarks to an existing PDF file (some text as a background, some text-based headers and footers, and also an image-based background watermark).
I managed to add stamp "on top" of the exisiting Pdf, with code like this one :
Code: C#
var firstPage = document.Pages[0];
//Create a new text layer
EO.Pdf.Contents.PdfTextLayer textLayer = new EO.Pdf.Contents.PdfTextLayer();
//Use a big font, light text color and also
//rotate the text 45 degrees
textLayer.Font = new EO.Pdf.Drawing.PdfFont("Arial", 50);
textLayer.NonStrokingColor = Color.LightGray;
textLayer.GfxMatrix.Rotate(45);
//Create the text object
EO.Pdf.Contents.PdfTextContent textContent = new EO.Pdf.Contents.PdfTextContent("CONFIDENTIAL");
textContent.PositionMode = EO.Pdf.Contents.PdfTextPositionMode.Offset;
textContent.Offset = new EO.Pdf.Drawing.PdfPoint(350, 150);
//Add the text object into the text layer object
textLayer.Contents.Add(textContent);
//Add the text layer into the page
firstPage.Contents.Add(textLayer);
using (var targetStream = new MemoryStream())
{
document.Save(targetStream);
var data = targetStream.ToArray();
//throw new NotImplementedException();
Logger.Instance.LogDebug("< EssentialObjectsPdfEngine.AddOverlay(...)");
return new OverlayedPdfResult { Data = data };
}
but could not put that same text "behind" the existing content.
I understand that I can use an AcmRenderer and handle the BeforeRenderPage event, but all the samples I have found did it at the initial generation of the Pdf from an Html source.
Is there a way to apply a background watermark to an already generated Pdf ?
Thanks in advance !