Hello,
Hello
Hello re Bert,
Thanks for your inquiry. Please use the below sample code for setting a certificate to a PDF document.
PdfFileSignature pdfVerify = new PdfFileSignature();
//bind input PDF file
pdfVerify.BindPdf(myDir + @"Google.pdf");
pdfVerify.SetCertificate(myDir + @"MySPC.pfx", "test"); // Set certificate
pdfVerify.Sign(1, "Reason", "Contact", "Location", true, new System.Drawing.Rectangle(10, 10, 50, 50)); // Sign the document with MySPC.pfx file
pdfVerify.Save(myDir + @"Google_Certified.pdf");
Console.WriteLine("Signed File Created!");
If you still face any issue, Please feel free to contact us.
Best Regards,
Hello,
I am still not there were I would like to be
this is what I want:
internal bool SignWordPDF(string inputWord, string outputPdf, string pfx)
{
Aspose.Words.Document doc = new Aspose.Words.Document(FilePath(inputWord));
using (var streamout = new MemoryStream())
{
using (var certFileStream = new FileStream(FilePath(pfx), FileMode.Open, FileAccess.Read))
{
var certificateBytes = new byte[certFileStream.Length];
certFileStream.Read(certificateBytes, 0, certificateBytes.Length);
var cert = new X509Certificate2(certificateBytes, “itissafe@3su”);
var encrdetails = new PdfEncryptionDetails(string.Empty, “Triples3861”, PdfEncryptionAlgorithm.RC4_128);
encrdetails.Permissions = PdfPermissions.DisallowAll | PdfPermissions.HighResolutionPrinting | PdfPermissions.Printing;
var options = new PdfSaveOptions { Compliance = PdfCompliance.PdfA1b };
// Set this object in the options.
options.DigitalSignatureDetails = new PdfDigitalSignatureDetails(cert, “Dit document kan niet gewijzigd worden tijdens of na verzending.”, “BizTrack”, DateTime.Now);
options.EncryptionDetails = encrdetails;
doc.Save(FilePath(outputPdf), options);
}
return true;
}
}
however when saving the file I get the following:
You have requested both PDF/A compliance and PDF encryption but these options cannot be used together
The below is working
internal bool SignWordPDF(string inputWord, string outputPdf, string pfx)
{
Aspose.Words.Document doc = new Aspose.Words.Document(FilePath(inputWord));
using (var streamout = new MemoryStream())
{
using (var certFileStream = new FileStream(FilePath(pfx), FileMode.Open, FileAccess.Read))
{
var certificateBytes = new byte[certFileStream.Length];
certFileStream.Read(certificateBytes, 0, certificateBytes.Length);
var cert = new X509Certificate2(certificateBytes, “itissafe@3su”);
//var encrdetails = new PdfEncryptionDetails(string.Empty, “Triples3861”, PdfEncryptionAlgorithm.RC4_128);
//encrdetails.Permissions = PdfPermissions.DisallowAll | PdfPermissions.HighResolutionPrinting | PdfPermissions.Printing;
var options = new PdfSaveOptions { Compliance = PdfCompliance.PdfA1b };
// Set this object in the options.
options.DigitalSignatureDetails = new PdfDigitalSignatureDetails(cert, “Dit document kan niet gewijzigd worden tijdens of na verzending.”, “BizTrack”, DateTime.Now);
//options.EncryptionDetails = encrdetails;
doc.Save(FilePath(outputPdf), options);
}
return true;
}
}:
but then I can’t set the permissions:
PdfPermissions.DisallowAll | PdfPermissions.HighResolutionPrinting | PdfPermissions.Printing;
so maybe you know the answer
re
Hi Bert,
Thanks for your inquiry.
Please check: Working with Digital Signatures using Aspose.Words for .NET
If you need both above features, please use the following C# code:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Test Signed PDF.");
PdfEncryptionDetails encrdetails = new PdfEncryptionDetails(
string.Empty,
"Triples3861",
PdfEncryptionAlgorithm.RC4_128);
encrdetails.Permissions = PdfPermissions.DisallowAll |
PdfPermissions.HighResolutionPrinting |
PdfPermissions.Printing;
CertificateHolder cert = CertificateHolder.Create(MyDir + "signature.pfx", "password");
PdfSaveOptions options = new PdfSaveOptions();
options.Compliance = PdfCompliance.Pdf15;
options.EncryptionDetails = encrdetails;
options.DigitalSignatureDetails = new PdfDigitalSignatureDetails(
cert,
"reason",
"location",
DateTime.Now);
doc.Save(MyDir + @"17.1.0.pdf", options);
Hope, this helps.
Best regards,