Welcome Guest Search | Active Topics | Sign In | Register

Adding a background watermark to an existing PDF Options
Thibaud D
Posted: Tuesday, March 5, 2013 4:43:08 AM
Rank: Newbie
Groups: Member

Joined: 3/5/2013
Posts: 1
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 !
eo_support
Posted: Tuesday, March 5, 2013 1:58:33 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

There is no reliable way to do that. If you are generating the PDF from the scratch, then it's easy (for example, you can use BeforeRenderPage). However if the PDF is from somewhere else, then it is very difficult or even technical impossible. For example, if your PDF file is from a scanner with just a single image on the page but that image is not transparent, then there is no way for you to do a watermark because whatever you put behind that image will always be obscured by the image.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.