In this article I'll show how the PDF Metamorphosis .Net works with watermarks. "The PDF Metamorphosis .Net" is the name of the our library, the general function of which is converting HTML, RTF to PDF.
Sometime ago a one customer asked us to add a new feature 'Watermark' in the PDF Metamorphosis .Net. He said: There is one feature that I cannot make work with your solution – the idea of background images to show our invoices on our letterhead.
I’ve seen many people trying to make ‘background’ images work in RTF but there is no good solution in the RTF specification (and PdfMetamorphosis seems to ignore the \absh\phpg\posx<N> absolute position features of RTF).
So I have a suggestion that would make me 🙂 and everyone in the web forums happy – because what most of us are trying to do is incorporate letterhead, 2nd pages, and/or watermarks into the final PDF file.
His suggestion seemed interesting to all of us and we decided to make new property the 'Watermark'. We like a new ideas from people who uses our products! 🙂
Now the PDF Metamorphosis .Net can do these operations with watermarks:
- Create a watermark from image file and add place it to PDF document
- Place one or several watermarks on any pages (all, even, odd or custom)
- Set individual size and position for each watermark
- Set a transparency for each watermark
But, I want to make accent that watermarks can be inserted only during converting from RTF and HTML PDF. The component can't insert watermark into existing PDF document.
And at the end of article let's make a sample in C# to create PDF with watermark:
1. Convert RTF file to PDF file and add a watermark at center on every page with 30% of transparency:
SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis(); p.PageStyle.PageSize.Letter(); //Create a new watermark object SautinSoft.PdfMetamorphosis.WaterMark wm1 = new SautinSoft.PdfMetamorphosis.WaterMark(); //Load watermark from image file wm1.Img = System.Drawing.Image.FromFile(@"d:WaterMark.png"); //Set w&h by 2 inch for watermark and place it at the center of Letter page (8.5 x 11 inches) wm1.PositionInch(3.25f, 4.5f, 2f, 2f); //Specify that watermark will appear at all pages wm1.PageNumAll(); //set 30% transparency wm1.Transparency(30); //add watermark to watermarks ArrayList p.PageStyle.WaterMarks.Add(wm1); //Convert RTF file to PDF file p.RtfToPdfConvertFile(@"d:test.rtf", @"d:test.pdf");
I would be glad to get your comments and suggestions...