Not able to sign on same pdf

Hi,


I am not able to sign on same pdf. I am doing wrong or it is not supported.

Document PdfDocument = new Document(@“C:\Users\ankur.patel\Desktop\sign\Google1.pdf”);
PdfFileSignature pdfSign = new PdfFileSignature(PdfDocument );
Aspose.Pdf.InteractiveFeatures.Forms.PKCS1 sig = new Aspose.Pdf.InteractiveFeatures.Forms.PKCS1(@“C:\Users\xyz\Desktop\Axc.pfx”, “xxxxx”);
System.Drawing.Rectangle rect = new System.Drawing.Rectangle(300, 300, 200,200);
pdfSign.Sign(1, “test”, “Ankur”, “L.A”, true, rect, sig);
pdfSign.Save();
PdfDocument.Save();
PdfDocument.Dispose();

But If am provide destination file then it works

PdfFileSignature pdfSign = new PdfFileSignature(@“C:\Users\xyz\Desktop\sign\Google1.pdf”, @“C:\Users
xyz \Desktop\sign\Google2.pdf” );
Aspose.Pdf.InteractiveFeatures.Forms.PKCS1 sig = new Aspose.Pdf.InteractiveFeatures.Forms.PKCS1(@“C:\Users\xyz\Desktop\Axc.pfx”, “xxxxx”);
System.Drawing.Rectangle rect = new System.Drawing.Rectangle(300, 300, 200,200);
pdfSign.Sign(1, “test”, “Ankur”, “L.A”, true, rect, sig);
pdfSign.Save();'

Any help would be appreciated !!!

Hi Ankur,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I think you can use the sample file as input and output file to get your desired results. Please see the following sample code in this regard:

PdfFileSignature pdfSign = new PdfFileSignature(@"C:\Users\xyz\Desktop\sign\Google1.pdf", @"C:\Users\ xyz \Desktop\sign\Google1.pdf");

Aspose.Pdf.InteractiveFeatures.Forms.PKCS1 sig = new Aspose.Pdf.InteractiveFeatures.Forms.PKCS1(@"C:\Users\xyz\Desktop\Axc.pfx", "xxxxx");

System.Drawing.Rectangle rect = new System.Drawing.Rectangle(300, 300, 200, 200);

pdfSign.Sign(1, "test", "Ankur", "L.A", true, rect, sig);

pdfSign.Save();

If you try using Adobe X to sign a document, it also requires you to save the document explicitly after applying the signature. Same is the case with Aspose.Pdf for .NET. It requires the output file name (which can be the name of the same file) explicitly to save the file after applying signature.

Please feel free to contact support in case you need any further assistance.

Sorry for the inconvenience,

Hi,


Thank you so much for your quick response.

I tried to use same file, but got exception.

IOException was unhandled

The process cannot access the file ‘C:\Users\ankur.patel\Desktop\sign\Google1.pdf’ because it is being used by another process.

Hi,


Another thing is for encrypted file I am not able to sign on that file.

Document PdfDocument = new Document(@“C:\User\sxyzl\Desktop\sign\Both.pdf”,“ownerpassword”);
PdfFileSignature pdfSign = new PdfFileSignature(PdfDocument, @“C:\Users\xyzl\Desktop\sign\Googles1.pdf”);
Aspose.Pdf.InteractiveFeatures.Forms.PKCS1 sig = new Aspose.Pdf.InteractiveFeatures.Forms.PKCS1(@“C:\Users\ankur.patel\Desktop\AnkurPatel.pfx”, “netauto2004”);
System.Drawing.Rectangle rect = new System.Drawing.Rectangle(300, 300, 200, 200);
pdfSign.Sign(1, “test”, “Ankur”, “L.A”, true, rect, sig);
pdfSign.Save();
PdfDocument.Dispose();

Error: NullReferenceExcption was unhandled
Object reference not set to an instance of an object.


Hi Ankur,,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Which version of Aspose.Pdf for .NET are you using? I tested the scenario with the latest version Aspose.Pdf for .NET 7.2.0. Please download and try the latest version and in case you still face any issue, please share your template files with us to help us reproduce your issue. Also, please share your system environment i.e. OS, .NET Framework, 32 bit or 64 bit processor etc. with us so we can check the issue in a similar environment.

Sorry for the inconvenience,

Hi,


Thank you so much for quick response. PDF .NET 7.2.0 fix the problem.

But still not able to sign on encrypted file.

Document PdfDocument = new Document(@“C:\Users\xyz\Desktop\sign\Both.pdf”,“userpassword”);
PdfFileSignature pdfSign = new PdfFileSignature(PdfDocument);
Aspose.Pdf.InteractiveFeatures.Forms.PKCS1 sig = new Aspose.Pdf.InteractiveFeatures.Forms.PKCS1(@“C:\Users\xyz\Desktop\AnkurPatel.pfx”, “xxxxx”);
System.Drawing.Rectangle rect = new System.Drawing.Rectangle(300, 300, 200, 200);
pdfSign.Sign(1, “test”, “Ankur”, “L.A”, true, rect, sig);
pdfSign.Save();

not able to use following method:
public PdfFileSignature(Document document, string outputFile);

Hi Ankur,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for the feedback.

Please share your template file with us to help us reproduce the issue at our end.

Sorry for the inconvenience,

Hi,


Thank you so much for your quick response.

I have attached pdf file with encryption.
Userpassword : abcd1234
Masterpassword : asdf1234

When i am not able to sign on same pdf.

string file = @“C:\Users\xyz\Desktop\sign\pass\Google1.pdf”;
Document PdfDocument = new Document(file,“abcd1234”);
PdfFileSignature pdfSign = new PdfFileSignature(PdfDocument);
Aspose.Pdf.InteractiveFeatures.Forms.PKCS1 sig = new Aspose.Pdf.InteractiveFeatures.Forms.PKCS1(@“C:\Users\xyz\Desktop\AnkurPatel.pfx”, “xxxx”);
System.Drawing.Rectangle rect = new System.Drawing.Rectangle(300, 300, 200, 200);
pdfSign.Sign(1, “test”, “Ankur”, “L.A”, true, rect, sig);
pdfSign.Save(file);





Hi,

Same thing happened with FlattenAllFields. not able to flatten all fields of same pdf.

string file = @"C:\Users\ankur.patel\Desktop\sign\pass\student1 - Copy.pdf";
Document PdfDocument = new Document(file);

//open document
Aspose.Pdf.Facades.Form PdfForm = new Aspose.Pdf.Facades.Form(PdfDocument);
PdfForm.FlattenAllFields();
PdfForm.Save();
PdfDocument.Save();
PdfForm.Dispose();
PdfDocument.Dispose();

Error : ObjectDisposedException was unhandeled
Cannot access a disposed object.
Object name : 'Document'.

Hi Ankur,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for sharing the template file.

I am able to generate your mentioned issue regarding signing an encrypted PDF file. Your issue has been registered in our issue tracking system with issue id: PDFNEWNET-34153. You will be notified via this forum thread regarding any updates against your reported issue.

Sorry for the inconvenience,

Hi Ankur,


We have further investigated this requirement and have come to the conclusion that a PDF file can either be encrypted or signed. These are two different ways to provide security and they cannot be present in a single document at the same time. For example, Adobe Acrobat asks to change security if one tries to sign encrypted document or encrypt signed document (i.e. output pdf will be either encrypted or signed). However another user has requested the feature to encrypt PDF with a digital certificate and we already have logged this requirement as PDFNEWNET-33384. As soon as we have made some progress towards its implementation, we would be more than happy to update you with the status of correction. Please be patient and spare us little time. We are sorry for your inconvenience.