PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Apr 27, 2024 10:28 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Tue Nov 14, 2023 10:35 am 
Offline

Joined: Wed Apr 20, 2022 11:29 am
Posts: 2
Hi,
I am trying to sign an PDF file using PDFSharp v.1.31 (to work on c# Framework 3.5 / 4).

I create a simple project and i can do the "Hello world" sample without problems.

Once i try to use it to sign an pdf file cames the problems, can some one get me on the track?

0 - I read that for older Frameworks i need to use the 1.31, am i wrong?

1 - Does the DPDFSharp 1.31 have the capabilities to sign pdf documents or need other version? (i could not be able to know it.. i already read the versions update and i thing that works!)

2 - the code that i am using, i get 2 different errors:
2.1 - X509Certificate2 could not be found --> (i used the System.Security.Cryptography.X509Certificates;) and it "worked"
2.1 - PdfSignatureField could not be found --> and this one i can not solve!! (what can i do?)
2.2 - PdfSignature could not be found --> (what can i do?)

imports:
using System;
using System.Diagnostics;
using System.IO;
using PdfSharp;
using PdfSharp.Drawing;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
using System.Security.Cryptography.X509Certificates;
CODE:
PdfDocument document = PdfReader.Open(inputPdfPath, PdfDocumentOpenMode.Modify);

// Load the certificate
X509Certificate2 certificate = new X509Certificate2(certificatePath, certificatePassword);

// Create a signature field
PdfSignatureField signatureField = new PdfSignatureField(document.Pages[0], "SignatureField");
signatureField.Widget.Rect = new PdfSharp.Pdf.PdfRectangle(50, 50, 150, 80);
document.AcroForm.Fields.Add(signatureField);

// Create the signature
PdfSignature signature = new PdfSignature(signatureField);
signature.Certificate = certificate;
signature.ContactInfo = "Your contact info";
signature.Location = "Location";
signature.Reason = "Reason for signing";
signature.DistinguishedName = certificate.Subject;

// Save the document with the signature
document.Save(outputPdfPath);


I am new using PDFSharp, please thanks for help me!!


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 14, 2023 11:57 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 916
Location: CCAA
elio.mota wrote:
0 - I read that for older Frameworks i need to use the 1.31, am i wrong?
No link given. Any version up to 1.51 can be used.

elio.mota wrote:
1 - Does the DPDFSharp 1.31 have the capabilities to sign pdf documents or need other version? (i could not be able to know it.. i already read the versions update and i thing that works!)
Not "out of the box". Other people implemented signatures.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


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: No registered users and 360 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