Download and add watermark programmatically using C# .NET

Hi,When i’m downloading i need to add watermark to all file types(.pdf,.docx,.pptx,.xlsx)…Actually i’m getting document data in memory stream from blob…how to pass this to watermark().

watermark issue.png (31.7 KB)
watermark1.jpg (126.2 KB)

1 Like

@bharathiGK,

Please have a look at this documentation article. You can see that a document could be loaded from multiple sources and then watermark could be added. Loading a document from stream will help you out.

Okay.That Code i already checked.that not suits for me and i found another way to convert stream…Thank you

image.png (315.8 KB)

Hi.i have applied watermark on document,but i need to apply foreground watermark.

my watermark text should be visible above the image and i wish to divide watermark text,if length exceeds means,how it is possible in this.
image.jpg (168.9 KB)
like this screenshot i wish to apply.

i gone through the text watermark article and applied different scenario but fails.

1 Like

@bharathiGK,

We are investigating this scenario. Your investigation ticket ID is WATERMARKNET-1265. As there’s any update, you’ll be notified.

Do you mean split watermark text into multiple lines (add a line break)?

Yes correct.split string into multilines(it means line breaks)
“Confidential”
“UserName”
“TimeStamp”

like this i need to show watermark

1 Like

@bharathiGK,

Have a look at the code below, hopefully it’ll help you out.

string text= "Confidential" + System.Environment.NewLine + "UserName";
TextWatermark watermark= new TextWatermark(text, font);

Yeah…Thanks…I have applied same thing and i got correct output for .pdf files.
image.png (519.3 KB)

i’m dynamically getting .docx,.pdf,.pptx,.xlsx files…in that case its not coming properly.

string[] watermarkText = new string[] { “CONFIDENTIAL”, User.Identity.Name, $"{TimeZoneInfo.ConvertTimeToUtc(DateTime.Now, TimeZoneInfo.Local).ToString()} UTC" };
string VmText = Utilities.Text.AlignCenter(watermarkText);

        using (Watermarker watermarker = new Watermarker(stream))
        {
            Font font = new Font("Courier New", 20, FontStyle.Bold);
            TextWatermark watermark = new TextWatermark(VmText, font);
            watermark.ForegroundColor = Color.FromArgb(100, Color.LightGreen);
            watermark.Opacity = 0.5;
            watermark.TextAlignment = TextAlignment.Right;
            watermark.HorizontalAlignment = HorizontalAlignment.Center;
            watermark.VerticalAlignment = VerticalAlignment.Center;
            //watermark.ScaleFactor = 0.5;
            watermark.RotateAngle = -45;
            watermark.Height = 350;
            //watermark.Width = 200;

            watermarker.Add(watermark);
            watermarker.Save(filePathout);
        }

for word document i’m getting like below image.
image.png (237.4 KB)

@bharathiGK,

Can you please try to increase font size for the Word document? Watermark text is not readable.

I tried to increase the font size also.i’m getting like this if i increase font size…kindly help to do set up for word document.

image.png (270.5 KB)

like below pdf i need to get.same content i using for watermark.
image.png (519.3 KB)

if i give single word,its making correct.
image.png (288.3 KB)

@bharathiGK,

Thanks for the details. We are investigating this issue. Your investigation ticket ID is WATERMARKNET-1266. As there’s any update, you’ll be notified.

HI…I would like to get update soon.so can you make it possible…i’m the one of the user under frontedge consulting company…we already purchased license from you…
So what i want to do for getting update soonOrderid.jpg (7.7 KB)

1 Like

@bharathiGK,

Your issues are still under investigation. Please note that all issues are served on first come first served basis. We’ll surely let you know as there is any update.

However, in order to expedite resolution of these tickets, you may purchase the priority support.

Okay.Thank you for your information. Looking for the Investigation resuls.

1 Like

@bharathiGK,

We’ll surely notify you as there’s any update.

Hi how to apply redact by area selection and highlight on original document…
In viewer I’m showing original documents as a .png images and applying… coordinate s saving in document metadata storage…how to apply that on original document…
Because when i download a document i need to have redacted and highlight

1 Like

@bharathiGK,

You can use GroupDocs.Annotation API for text redaction. Please have a look at this article. Moreover, we’d recommend you to always create a new post for a new scenario/issue.

@bharathiGK

We have following updates:
WATERMARKNET-1265 - You can place the watermark to the headers and footers of the page. Please consider the following code:

string headerText = "CONFIDENTIAL";
string footerText = "superuser@something.com 28-04-2020 10:01:47 UTC";
using (Watermarker watermarker = new Watermarker(input, new WordProcessingLoadOptions()))
{
    Font headerFont = new Font("Courier New", 20, FontStyle.Bold);
    TextWatermark headerWatermark = new TextWatermark(headerText, headerFont);
    headerWatermark.ForegroundColor = Color.LightGreen;
    headerWatermark.HorizontalAlignment = HorizontalAlignment.Center; // centers the text
    headerWatermark.VerticalAlignment = VerticalAlignment.Top; // moves the watermark to the top of the page

    WordProcessingWatermarkHeaderFooterOptions headerOptions = new WordProcessingWatermarkHeaderFooterOptions();
    headerOptions.HeaderFooterType = OfficeHeaderFooterType.HeaderPrimary; // anchors the watermark to the header
    watermarker.Add(headerWatermark, headerOptions);

    Font footerFont = new Font("Courier New", 16, FontStyle.Bold);
    TextWatermark footerWatermark = new TextWatermark(footerText, footerFont);
    footerWatermark.ForegroundColor = Color.LightBlue;
    footerWatermark.HorizontalAlignment = HorizontalAlignment.Center; // centers the text
    footerWatermark.VerticalAlignment = VerticalAlignment.Bottom; // moves the watermark to the bottom of the page

    WordProcessingWatermarkHeaderFooterOptions footerOptions = new WordProcessingWatermarkHeaderFooterOptions();
    footerOptions.HeaderFooterType = OfficeHeaderFooterType.FooterPrimary; // anchors the watermark to the footer
    watermarker.Add(footerWatermark, footerOptions);

    watermarker.Save(output);
}

WATERMARKNET-1266 - Unfortunately, this is a LibreOffice Writer issue. Microsoft Word renders this watermark correctly, like in PDF. You can check at your end as well.

Okay.Thank you.i will check

1 Like

@bharathiGK

You are welcome.