In this blog post, we'll develop a document conversion application. And the scope is not just limited to converting a Word to PDF. We will see how we could add a (non-removeable) patent or watermark in the resultant PDF.
Watermark Options
It's not just like adding a simple background watermark. You can control or set the following options/properties while adding a watermark:
- Background - Stamp watermark as background, if we set it to true, watermark will be laid at bottom otherwise on top
- Color - Set watermark color
- Font - e.g Comis Sans, Times New Roman
- Height/Width
- Rotation angle
- Transparency
Setting Image Watermark
API also allows you to set image watermark. It has a property Image, you have to set it to image byte array.
Implementation
Let's convert a Word file to PDF and add some watermar with the options/properties specified earlier.
- using (var converter = new Converter(@"D:/sample.docx"))
- {
- PdfConvertOptions convert = new PdfConvertOptions();
- WatermarkOptions options = new WatermarkOptions();
- options.Text = "Sample Watermark";
- options.Color = Color.Red;
- options.Transparency = 0.8;
- options.Top = 190;
- options.Left = 50;
- options.Background = true;
- options.RotationAngle = 90;
- convert.Watermark = options;
- converter.Convert(@"D:/output.pdf", convert);
- }
Have a look at the Word source file (image below),
And the following PDF output:
You can see how we controlled watermark positioning, color, rotation etc. Eventually, you have a PDF with a non-removable patent. All you have to do is to add this
DLL reference in your .NET project. You don't have to install or refer to any third party tool or software. For further details or in case of any issue, you can post
here.