System.NullReferenceException is thrown while adding watermark to PDF

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");
            }
        }
    }
}
1 Like

@tahir.manzoor

We could not reproduce this issue using latest API version and .NET/.NET Core. Could you please share more details about your development environment or a sample console application using that issue could be reproduced?

@atir.tahir

Could you please share the output file that you have generated?

Exception using net6.0
net6.0.png (106.0 KB)

Exception using .NET framework 4.8
.netframework.png (75.7 KB)

OS : Windows 11

@tahir.manzoor

Please take a look at this screenshot.jpg (187.3 KB) and this output.pdf (109.7 KB).

GroupDocsWatermarkIssue.zip (212.1 KB)

issue detail.jpg (215.6 KB)

I have created new separate application for this case and still facing issue. Please check the attached project and screenshot for this issue.

@tahir.manzoor

We still cannot reproduce this issue using your project. Take a look at this screenshot - image.png (71.9 KB).