System.NullReferenceException, Object reference not set to an instance of an object.
input.pdf (34.3 KB)
using GroupDocs.Watermark.Common;
using GroupDocs.Watermark.Watermarks;
using GroupDocs.Watermark;
namespace GroupDocsWatermark
{
internal class Program
{
static void Main(string[] args)
{
// Set License to avoid the limitations of Viewer library
License lic = new License();
lic.SetLicense(@"GroupDocs.Watermarker.lic");
// Specify an absolute or relative path to your document.
using (Watermarker watermarker = new Watermarker("input.pdf"))
{
// Specify the desired text and font for the watermark
TextWatermark watermark = new TextWatermark("Watermark Text", new Font("Arial", 60, FontStyle.Bold));
// Specify font color and text opacity, rotation and alignments
watermark.ForegroundColor = Color.DarkGreen;
watermark.Opacity = 0.5;
watermark.HorizontalAlignment = HorizontalAlignment.Center;
watermark.VerticalAlignment = VerticalAlignment.Center;
watermark.RotateAngle = -45;
// Apply the watermark
watermarker.Add(watermark);
// Save the resulting document
watermarker.Save("output.pdf");
}
}
}
}