在PDF文件的最后一页签名
本文关键字:一页 最后 PDF 文件 | 更新日期: 2023-09-27 18:19:09
我使用c#和iTextSharp 3.1来签署PDF文件。签名工作正常,但我想在文件的最后一页签名。我使用的代码是这样的:
reader = new PdfReader(inputPDF);
int numberOfPages = reader.NumberOfPages;
PdfStamper st = PdfStamper.CreateSignature(reader, new FileStream(outputPDF, FileMode.Create, FileAccess.Write), ''0', null, true);
PdfSignatureAppearance sap = st.SignatureAppearance;
if (logoSign != null)
{
// Scale img to fit
logoSign.ScaleToFit(100, 50);
// Set Signature position on page
logoSign.SetAbsolutePosition(300, 80);
sap.Image = logoSign;
}
sap.SetCrypto(this.myCert.Akp, this.myCert.Chain, null, PdfSignatureAppearance.VERISIGN_SIGNED);
if (SigReason.Length > 0)
sap.Reason = SigReason;
if (SigContact.Length > 0)
sap.Contact = SigContact;
if (SigLocation.Length > 0)
sap.Location = SigLocation;
if (visible)
sap.SetVisibleSignature(mySignRect, 1, null);
try
{
st.Close();
} catch(Exception e) { }
此代码表示文件的第一页。我想在文件的最后一页签名。如何设置在最后一页签名?我也想知道,相同的代码不工作在iTextSharp5.4.2。它在sap.SetCrypto()和st.Close()上给出错误。有任何想法,我如何使它在5.4.2工作。
谢谢
请尝试mkl引用的白皮书附带的示例的c#版本:http://sourceforge.net/p/itextsharp/code/HEAD/tree/tutorial/signatures/