在最后一页上签署PDF文件 [英] Sign PDF file on last page
问题描述
我正在使用C#和iTextSharp 3.1来签署PDF文件。签名正在进行,但我想在文件的最后一页上签名。我使用的代码如下:
I am using C# and iTextSharp 3.1 to sign PDF files. The signing is working, but I want to sign on the last page of the file. The code I use is such :
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) { }
这个代码标志着第1页的文件。我想要在文件的最后一页上签名。如何设置在最后一页上签名。
我也想知道,相同的代码在iTextSharp5.4.2中不起作用。它在sap.SetCrypto()和st.Close()上出错。知道如何让它在5.4.2中运行。
This code signs of the 1st page of the file. I want o sign on the last page of the file. How do I set to sign on last page. I also wonder, the same code doesn't work in iTextSharp5.4.2. It gives error on sap.SetCrypto() and st.Close(). Any idea how to I make it work in 5.4.2.
谢谢
推荐答案
请尝试mkl引用的白皮书附带的C#版本示例: http://sourceforge.net/p/itextsharp/code/HEAD/tree/tutorial/signatures/
Please try the C# version of the examples that come with the white paper referenced by mkl: http://sourceforge.net/p/itextsharp/code/HEAD/tree/tutorial/signatures/
这篇关于在最后一页上签署PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!