itext ver7社区将idictionary转换为pdfdictionnay

时间:2017-10-27 12:52:57

标签: pdf itext7

我正在尝试在Visual Studio 2017中使用最新版本的iText7。我按照示例填写了一个交互式表单,我总是收到错误

  

无法转换类型为' iText.IO.Util.LinkedDictionary`2 [System.String,iText.Forms.Fields.PdfFormField]'输入' iText.Kernel.Pdf.PdfDictionary']

我试图使用trycast(fields,pdfdictionnay)而没有任何运气。调用Dim toSet As PdfFormField

时会检测到异常
Private Function CreatePDF(ByVal record As Lodging) As String

    Dim SRC As String = Server.MapPath("~\Finances\LodgingClaim.pdf")
    Dim DST As String = Server.MapPath("~\Finances\" & Guid.NewGuid.ToString & ".pdf")

    Try
        ' create a new PDF reader based on the PDF template document
        Dim pdf As New iText.Kernel.Pdf.PdfDocument(New iText.Kernel.Pdf.PdfReader(SRC), New iText.Kernel.Pdf.PdfWriter(DST))

        Dim Form As PdfAcroForm = PdfAcroForm.GetAcroForm(pdf, True)

        Dim fields As IDictionary(Of String, PdfFormField) = Form.GetFormFields()

        Dim toSet As PdfFormField

        fields.TryGetValue("Text1.0", toSet)
        toSet.SetValue(FormatCurrency(record.Day1Total, 2))

        fields.TryGetValue("Text1.1", toSet)
        toSet.SetValue(FormatCurrency(record.Day2Total, 2))

        fields.TryGetValue("Text1.2", toSet)
        toSet.SetValue(FormatCurrency(record.Day3Total, 2))

        fields.TryGetValue("Text1.3", toSet)
        toSet.SetValue(FormatCurrency(record.Day4Total, 2))

        fields.TryGetValue("Text1.4", toSet)
        toSet.SetValue(FormatCurrency(record.Day5Total, 2))

        fields.TryGetValue("Text1.5", toSet)
        toSet.SetValue(FormatCurrency(record.Day6Total, 2))
        pdf.Close()
    End Try
    Return Nothing
End Function

0 个答案:

没有答案