一些插件和程序可以做到这一点;是否有任何示例或教程如何使用.net和itextSharp ??
执行此操作我需要签名pdf并在所有页面上盖章并添加另一个签名。 打开文件时,文档上的第一个签名必须有效。
提前致谢。
答案 0 :(得分:8)
当您要求打开文件时文档上的第一个签名必须有效时,我假设您最初谈的是在当前Adobe Reader版本中打开。
在这种情况下,您首先必须知道允许和不允许的更改取决于第一个签名本身。请查看this answer,了解Adobe自Acrobat版本9以来所考虑的“允许和禁止更改”的信息。阅读器。
因此,采取签名的pdf并在所有页面上标记图像并添加另一个签名并且不会使(在Adobe软件的眼中)无效的过程中的初始签名,即签署的pdf必须
未经认证(即初始签名仅为批准签名)
或通过注释,表单填写和数字签名认证,允许(即初始签名是允许这些类型的更改的证书签名)并且具有空签名您可以在其中填写签名字段。
如果签名的pdf已经包含多个签名,则它们都不会通过锁定信息添加任何其他限制。
(此外,我认为PDF既不加密也不包含动态XFA表格;这会使事情变得更复杂。)
如果满足这些要求,您可以使用从静态PdfStamper
方法检索的PdfStamper
public static PdfStamper CreateSignature(PdfReader reader, Stream os, char pdfVersion, string tempFile, bool append)
最终bool
参数值必须为true
(即您必须使用追加模式才能使初始签名无效。)
使用此PdfStamper
,您可以通过注释在文档页面上添加图片。 iText in Action — 2nd Edition示例TimetableAnnotations3.java / TimetableAnnotations3.cs说明了如何使用PdfStampers.
然后像往常一样添加签名,创建新签名字段或使用空签名字段。您可以在白皮书Digital Signatures for PDF documents中找到有关签名过程的详细信息;可以找到与该白皮书中的Java样本等效的C#样本here on sourceforge。
PS:在这篇文章中,我总是在Adobe软件的眼中强调 。在谈论经过认证的PDF时,Adobe非常接近PDF standard。对于已签名但未经证明的PDF,Adobe会应用与为认证文档指定的规则类似的规则。
答案 1 :(得分:1)
Public Function sign(keystore As String, level As Integer, src As String, name As String, dest As String, sig As String, pass As String)
' Try
'Dim store As System.Security.Cryptography.X509Certificates.X509Store = New System.Security.Cryptography.X509Certificates.X509Store
'store.Open(System.Security.Cryptography.X509Certificates.OpenFlags.ReadOnly)
'Dim sel As System.Security.Cryptography.X509Certificates.X509Certificate2Collection
' If sig <> "" And pass <> "" Then
Try
Dim y As Int16 = 200
' For i As Integer = 0 To sel.Count - 1
Dim pdfReader As PdfReader = New PdfReader(src)
Dim signedPdf = New FileStream(dest, FileMode.Create)
Try
Dim cert As X509Certificate2 = New X509Certificate2(sig, pass)
Dim cp As Org.BouncyCastle.X509.X509CertificateParser = New Org.BouncyCastle.X509.X509CertificateParser()
Dim chain As Org.BouncyCastle.X509.X509Certificate() = New Org.BouncyCastle.X509.X509Certificate() {cp.ReadCertificate(cert.RawData)}
Dim stamper As PdfStamper
stamper = PdfStamper.CreateSignature(pdfReader, signedPdf, "0"c, Nothing, True)
Dim signatureAppearance As PdfSignatureAppearance = stamper.SignatureAppearance
'signatureAppearance.SignatureGraphic = Image.GetInstance(pathToSignatureImage)
signatureAppearance.SetVisibleSignature(name)
signatureAppearance.CertificationLevel = level
Dim externalSignature As IExternalSignature = New X509Certificate2Signature(cert, "SHA-1")
' Dim digest As IExternalSignature = New BouncyCastleDigest
' signatureAppearance.s
'signatureAppearance.SetVisibleSignature(New Rectangle(50,50,50,
signatureAppearance.SignatureRenderingMode = PdfSignatureAppearance.RenderingMode.NAME_AND_DESCRIPTION
MakeSignature.SignDetached(signatureAppearance, externalSignature, chain, Nothing, Nothing, Nothing, 0, CryptoStandard.CADES)
' MakeSignature.
' End If
' Catch ex As Exception
'MsgBox(ex.Message)
' End Try
Catch ex As Exception
MsgBox("Signature File Password is not correct for the user Id :" & error_userid)
'Exit Function
End Try
Catch ex As Exception
End Try
Return 0
End Function