PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Thu Sep 18, 2025 8:17 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules

Also see our new Tailored Support & Services site.



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Thu Aug 28, 2025 6:46 pm 
Offline

Joined: Thu Aug 28, 2025 6:37 pm
Posts: 1
Using: C# .NET 8.0 WinForms project / PDFSharp v6.2.0

We are opening an existing PDF file that was generated by MS-Word, adding permissions and a password and then saving it again.

It works for most users and it correctly opens the PDF document without prompting for a password. However for some users, it asks for a password when trying to open the document. I guess that they are using non standard PDF reader applications.

Is there anything we can do to make it compatible for them too?

Current code:

Code:
    string ownerKey = Convert.ToBase64String(CryptoHelper.RandomKey());
    using (PdfDocument pdf = PdfReader.Open(tempPdfPath, PdfDocumentOpenMode.Modify))
    {
        pdf.SecuritySettings.OwnerPassword = ownerKey;
        pdf.SecuritySettings.UserPassword = string.Empty;
        pdf.SecuritySettings.PermitPrint = true;
        pdf.SecuritySettings.PermitModifyDocument = false;
        pdf.SecuritySettings.PermitExtractContent = false;
        pdf.Save(tempPdfPath);
    }


    internal static class CryptoHelper
    {
        // Return 16 random bytes (128-bit) every call.
        internal static byte[] RandomKey()
        {
            byte[] key = new byte[16];
            RandomNumberGenerator rng = RandomNumberGenerator.Create();
            rng.GetBytes(key);
            return key;
        }
    }


Top
 Profile  
Reply with quote  
PostPosted: Sun Aug 31, 2025 8:35 am 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 354
lanselof@gmail.com wrote:
Is there anything we can do to make it compatible for them too?

Some users reported that the experimental PDF viewer of Edge cannot open some encrypted PDF files.
Try an older encryption standard supported by Edge.

See also:
https://github.com/empira/PDFsharp/issu ... 2847879920
https://stackoverflow.com/questions/797 ... ge-137-138

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google Adsense [Bot] and 125 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group