Free Support Forum -

Adding password to a PDF document programmatically in .NET

I am using following code to add password to office document and pdf files

using (FileStream fs = new FileStream(FilePath, FileMode.Open))

                AddPasswordOptions options = new AddPasswordOptions(getFileFormat(FilePath), Password);
                GroupDocs.Merger.Domain.Result.DocumentResult result = new DocumentHandler().AddPassword(fs, options);

                Stream documentStream = result.Stream;
                var filestream = File.Create(OutputPath);



My password it 255 charactors long for example like this


after adding password pdf file cannot open manually by entering above password.
but word files works correctly

do yo have any idea of this

1 Like


This issue is reproduced at our end. Hence, we’ve logged it in our internal issue tracking system with ID MERGERNET-942. We’ll now further investigate it and let you know as there’s any update.

1 Like


We have an update on MERGERNET-942, there are some limits for the PDF formats related to it’s format specification. Usually, the PDF password could be from 4 to 32 symbols. GroupDocs.Merger API uses AES-256 encryption algorithm. Please read about password string length limit here.