I am using below code segment to sign a PDF,
using Aspose.Pdf;
using Aspose.Pdf.Facades;
using Aspose.Pdf.Forms;
const string certificateAsBase64String = “BASE64 encoded bytes”;
var certificateBytes = Convert.FromBase64String(certificateAsBase64String);
var ms = new MemoryStream(certificateBytes);
using var document = new Document(“Invoice.pdf”);
using var signature = new PdfFileSignature(document);
var pkcs = new PKCS7(ms, “”); //
signature.Sign(1, false, new System.Drawing.Rectangle(300, 100, 400, 200), pkcs);
// Save output PDF file
signature.Save(“Invoice_signed.pdf”);
But the last line threw error
System.ArgumentOutOfRangeException: ‘Index was out of range. Must be non-negative and less than the size of the collection. (Parameter ‘index’)’
with stacktrace
at System.ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessException()
at System.Collections.Generic.List`1.get_Item(Int32 index)
at #=z6sIGnsbNuXgiMkU431jdzQY21Nt2nNO6Sg==.#=zUeDtL0E=.#=zqra2huo=(Byte[] #=zxqN3OtE=, #=zHj89bs272vK26nh0wvJL1qmVRVUm214pYkN8sKo= #=zR7U5Rv4=, OcspSettings #=zQxNNSwj7GlU4, TimestampSettings #=zPUhhl2Wp622w, Boolean #=zvTW$kRg=, X509Certificate2 #=zp4lvb9qKU_uI)
at #=z6sIGnsbNuXgiMkU431jdzQY21Nt2nNO6Sg==.#=zUeDtL0E=.#=z46PVKiU=(Byte[] #=zxqN3OtE=, #=zHj89bs272vK26nh0wvJL1qmVRVUm214pYkN8sKo= #=zR7U5Rv4=, OcspSettings #=zQxNNSwj7GlU4, TimestampSettings #=zPUhhl2Wp622w, Boolean #=zvTW$kRg=)
at #=z6sIGnsbNuXgiMkU431jdzQY21Nt2nNO6Sg==.#=zUeDtL0E=.#=z46PVKiU=(Byte[] #=zxqN3OtE=, Stream #=ze1IU5_68dbjU, String #=zcrWuHS8=, OcspSettings #=zQxNNSwj7GlU4, TimestampSettings #=zPUhhl2Wp622w, Boolean #=zvTW$kRg=)
at #=z6sIGnsbNuXgiMkU431jdzQY21Nt2nNO6Sg==.#=zUeDtL0E=.#=z46PVKiU=(Byte[] #=zxqN3OtE=, Stream #=ze1IU5_68dbjU, String #=zcrWuHS8=, OcspSettings #=zQxNNSwj7GlU4, TimestampSettings #=zPUhhl2Wp622w)
at #=z6sIGnsbNuXgiMkU431jdzQY21Nt2nNO6Sg==.#=zUeDtL0E=.#=z46PVKiU=(Byte[] #=zxqN3OtE=, Stream #=ze1IU5_68dbjU, String #=zcrWuHS8=)
at #=zG5zgmaqMf_NWUoyosfDYJne5jola.#=z46PVKiU=(#=z8Zx2Kam9l1Eg7OVBOp3KCKdPsxVqDo6fy5i8O0wJuzSU #=z5f6gCx771HUm, Boolean #=zQYOuPd60eW7t, #=zBEAE4JBpHv2_Bzlcmaubjuz$YIUzEFbf6g== #=z9tWE$yM=, #=zkqpQ9FJ7o4qUFyIM4D2cw$E9uDixUwagVw== #=zT6VdQfM=, #=z1W7nKJ5zFZgjgI1ZKrOIEH7ORsidx61fVg== #=zY2M1LYQ=, Stream #=zR7U5Rv4=, String #=zDQ5F57M=, X509Certificate2 #=zp4lvb9qKU_uI, String& #=zyvC97EI=, Int32& #=zqHgIU$06tzCw)
at #=zG5zgmaqMf_NWUoyosfDYJne5jola.#=z46PVKiU=(String #=zntnlMWI=, #=zkqpQ9FJ7o4qUFyIM4D2cw$E9uDixUwagVw== #=zT6VdQfM=, #=z1W7nKJ5zFZgjgI1ZKrOIEH7ORsidx61fVg== #=zY2M1LYQ=, Stream #=zR7U5Rv4=, String #=zDQ5F57M=, X509Certificate2 #=zp4lvb9qKU_uI)
at #=zG5zgmaqMf_NWUoyosfDYJne5jola.#=z46PVKiU=(String #=zntnlMWI=, #=zkqpQ9FJ7o4qUFyIM4D2cw$E9uDixUwagVw== #=zT6VdQfM=, #=z1W7nKJ5zFZgjgI1ZKrOIEH7ORsidx61fVg== #=zY2M1LYQ=, Stream #=zR7U5Rv4=, String #=zDQ5F57M=)
at Aspose.Pdf.Forms.Signature.#=z46PVKiU=(String #=zntnlMWI=, Stream #=zR7U5Rv4=, String #=zDQ5F57M=)
at Aspose.Pdf.Forms.SignatureField.Sign(Signature signature, Stream pfx, String pass)
at Aspose.Pdf.Forms.SignatureField.Sign(Signature signature)
at Aspose.Pdf.Facades.PdfFileSignature.#=z2EJ2KGVf9sP_(Stream #=zmR5a98iRp0A5, Stream #=z5xnxeAY6wTGR, String #=zcrWuHS8=)
at Aspose.Pdf.Facades.PdfFileSignature.Save(Stream outputStream)
at Aspose.Pdf.Facades.PdfFileSignature.Save(String outputFile)
at Program.$(String[] args) in E:\Learn\Testy\AsposePdfTrial\Program.cs:line 16
Can someone help me?