PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Sun Aug 24, 2025 11:22 pm

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  [ 5 posts ] 
Author Message
 Post subject: Add password
PostPosted: Fri Aug 15, 2025 1:01 am 
Offline

Joined: Fri Aug 15, 2025 12:46 am
Posts: 3
Hi, i'm trying to set a password in a PDF document but the PdfReader method raise an exception:

The file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=8.0.0.2, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies could not be loaded. The system cannot find the file specified.

My program is in VB.Net FrameWork 4.8.1
PdfSharp loaded from Nuget (PdfSharp-GDI 6.2.1)

Imports PdfSharp.Pdf
Imports PdfSharp.Pdf.IO

Public Sub AddPassword(ByVal FileName As String, ByVal Password As String)
Try
Dim Document As PdfDocument = PdfReader.Open(FileName, PdfDocumentOpenMode.Modify)
Dim SecuritySettings As Security.PdfSecuritySettings = Document.SecuritySettings
SecuritySettings.UserPassword = Password
SecuritySettings.OwnerPassword = Password
SecuritySettings.PermitAnnotations = False
SecuritySettings.PermitAssembleDocument = False
SecuritySettings.PermitExtractContent = False
SecuritySettings.PermitFormsFill = False
SecuritySettings.PermitFullQualityPrint = True
SecuritySettings.PermitModifyDocument = False
SecuritySettings.PermitPrint = True
Document.SecurityHandler.SetEncryptionToV2With128Bits()
Document.Save(FileName)
Catch Ex As Exception
LoadErrors(Ex.Message)
End Try
End Sub


Top
 Profile  
Reply with quote  
 Post subject: Re: Add password
PostPosted: Fri Aug 15, 2025 1:19 pm 
Offline
User avatar

Joined: Thu Mar 06, 2025 10:43 am
Posts: 5
The file "'Microsoft.Extensions.Logging.Abstractions.dll" should be in the same folder where PdfSharp-gdi.dll is.


Top
 Profile  
Reply with quote  
 Post subject: Re: Add password
PostPosted: Sat Aug 16, 2025 3:06 pm 
Offline

Joined: Fri Aug 15, 2025 12:46 am
Posts: 3
Both DLLs are in the same folder.
More info:
EXE & DLL in VS2022.
The code showed below is part of a DLL that made a PDF file.
The DLL is a component library in .Net FW 4.8.1.
The PdfSharp is used to protect that file with a password.
The DLL is used in a WinForms .Net FW 4.8.1 proyect.


Top
 Profile  
Reply with quote  
 Post subject: Add password
PostPosted: Sun Aug 17, 2025 4:34 pm 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 352
Cannot reproduce with the information you provide.

Please use the IssueSubmissionTemplate to make it replicable.
https://docs.pdfsharp.net/General/Issue ... About.html

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


Top
 Profile  
Reply with quote  
 Post subject: Re: Add password
PostPosted: Tue Aug 19, 2025 4:47 pm 
Offline

Joined: Fri Aug 15, 2025 12:46 am
Posts: 3
Hi. For some reason, the DLL doesn't copy all the referencies to the EXE proyect.
The DLL has the property 'Local Copy = True'.
Only happens when the PDFSharp is referenced in a DLL.
To solve the problem, i copied the PDFSharp-GDI, via NuGet, to the EXE proyect.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 45 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