Some document formats also support content encryption. To load these type of documents you will have to provide the password. GroupDocs.Watermark API allows you to load content of these documents to manage watermark.
Load password-protected document of any supported format
The following example demonstrates how to load an encrypted document of any supported format using the password. If the password is incorrect, InvalidPasswordExceptionis thrown.
LoadOptionsloadOptions=newLoadOptions();loadOptions.Password="P@$$w0rd";// Specify an absolute or relative path to your document. Ex: @"C:\Docs\protected-document.docx"stringfilePath="protected-document.docx";using(Watermarkerwatermarker=newWatermarker(filePath,loadOptions)){// use watermarker methods to manage watermarks in the documentTextWatermarkwatermark=newTextWatermark("Test watermark",newFont("Arial",12));watermarker.Add(watermark);watermarker.Save("protected-document.docx");}
Load password-protected word processing document
The following example demontrates how to load an encrypted word processing document (DOC, DOCX etc) using the password.
WordProcessingLoadOptionsloadOptions=newWordProcessingLoadOptions();loadOptions.Password="P@$$w0rd";// Specify an absolute or relative path to your document. Ex: @"C:\Docs\protected-document.docx"stringfilePath="protected-document.docx";using(Watermarkerwatermarker=newWatermarker(filePath,loadOptions)){// use watermarker methods to manage watermarks in the WordProcessing documentTextWatermarkwatermark=newTextWatermark("Test watermark",newFont("Arial",12));watermarker.Add(watermark);watermarker.Save("protected-document.docx");}