Reputation: 623
I have a scenario where I need to get signature information from a pdf with the iText7 library. The signature may or may not exist. When I instantiate a new SignatureUtil
object for a PDF that does not have any digital signatures I get the exception
"There is no associate PdfWriter for making indirects."
. If an signature is there it works fine. I'm not sure how to correct this exception.
UPDATED to include code sample
Using reader As New PdfReader(pdfPath),
pdf As New PdfDocument(reader)
Dim util As New SignatureUtil(pdf)
Dim signModel As String = "[Signature: {0} - {1}]"
For Each signame As String In util.GetSignatureNames()
Dim whoisthis As PdfSignature = util.GetSignature(signame)
returnVal &= String.Format(
signModel,
whoisthis.GetName(),
whoisthis.GetReason
)
Next
End Using
Upvotes: 1
Views: 2611
Reputation: 12312
The exception is thrown because there is no AcroForm in the document and SignatureUtil
tries to add it, but there is no associated PdfWriter
.
As a workaround you can check if a document contains an AcroForm:
PdfAcroForm.getAcroForm(document, false) != null
And only create SignatureUtil
if there is an AcroForm. If there is no AcroForm there will be no signature fields.
Upvotes: 4