Adding a Watermark

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF Converter for .NET (v1)  /  Adding a Watermark

DynamicPDF Converter for .NET (v1) Forum

 May 10 2013 2:32 PM
So... I'm looking for a way to add a watermark (classification, company name, etc...) to a doc after (or during) conversion to PDF. I was hoping to open the converted documents with Generator, add a background image, then save back to PDF. But I'm not seeing a way to do that?

What would be the easiest way to do that (multiple source document types)?

Thanks
 May 10 2013 4:33 PM
Posted by a ceTe Software moderator
Hello,

The Converter does the have the watermarking feature. Once the PDF is generated by the Converter you can add the watermark using Merger. Generator can only generate PDFs programmatically where as Merger can open existing PDFs and add content and save it. Here is the sample code for Merger that can be used to add the watermark.

//Open an existing document to add watermark.
MergeDocument document = new MergeDocument("Input.pdf");

//use TransparencyGroup to add lable and text to create a watermark
TransparencyGroup group = new TransparencyGroup(0.5f); // adjust the transparency.

//cerate a label for watermark.
Label lbl = new Label(""Text Watermark"", 250, 250, 300, 300, Font.Courier, 35);
lbl.Angle = 45;
//create a image for watermark
Image image = new Image(""DPDFLogo.png"", 250, 250);

//add label and image to transparencygroup
group.Add(lbl);
group.Add(image);

//create template and add the watermark to the template.
Template pageTemplate = new Template();
pageTemplate.Elements.Add(group);

//apply the template to the document so watermark shows up on all pages.
//use StampTemplate to apply the watermark on top of existing content.
document.StampTemplate = pageTemplate;

//use Template to apply the watermark under the exisiting content.
//document.Template = pageTemplate;

document.Draw("output.pdf");

Thanks,
ceTe Software Support Team.
 Nov 17 2017 7:18 AM
I'm using your code in order tu set a watermark on PDF, but doesn't Work because cannot set the object in PageElement.

TransparencyGroup group = new TransparencyGroup(0.5f); // adjust the transparency.Add(image);

the error is:
Argument 1: cannot convert from 'System.Drawing.Image' to 'ceTe.DynamicPDF.PageElement'

How can solve it?


 Nov 17 2017 11:02 AM
Posted by a ceTe Software moderator
Hello,

You are getting error most likely because of directly adding System.Drawing.Image object to the TransparencyGroup page element of DynamicPDF API. Please note that adding System.Drawing.Image object to TransparencyGroup page element is not supported.

You will need to create a ceTe.DynamicPDF.PageElements.Image class object by specifying the image data. Then add this object to TransparencyGroup. Below is the code sample.

           //Create DynamicPDF Image object.
            ceTe.DynamicPDF.PageElements.Image imageObj = new ceTe.DynamicPDF.PageElements.Image(@"Image file path", 0, 0);
            //Create TransparencyGroup object.
            TransparencyGroup groupObj = new TransparencyGroup(0.5f);
            //Add the image object to the TransparencyGroup.
            groupObj.Add(imageObj);

Thanks,
ceTe Software Support Team.

All times are US Eastern Standard time. The time now is 12:25 PM.