开发者

Using ItextSharp I am getting Unbalanced begin/end text operators. But they are Matched

开发者 https://www.devze.com 2023-04-09 08:21 出处:网络
I working on a app that uses ItextSharp to generate PDF files for students to print name tags and parking permits... However it keeps throwing: Unbalanced begin/end text operators. at the doc.close()

I working on a app that uses ItextSharp to generate PDF files for students to print name tags and parking permits... However it keeps throwing: Unbalanced begin/end text operators. at the doc.close() The blocks appear to be properly openned and closed.. Below is the function:

        Function ID_and_Parking(ByVal id As Integer) As ActionResult
        Dim _reg_info As reg_info = db.reg_info.Single(Function(r) r.id = id)
        Dim _conf_info As conf_info = db.conf_info.Single(Function(f) f.id = 0)
        Dim _LastName As String = _reg_info.last_name
        Dim _Employer As String = _reg_info.business_name
        Dim _Class_1 As String = _reg_info.tues_class
        Dim _Class_2 As String = _reg_info.wed_class
        Dim _Class_3 As String = _reg_info.thur_class
        Dim _Class_4 As String = _reg_info.fri_class
        Dim _BeginDate As String = _conf_info.conf_start_date
        Dim _endDate As String = _conf_info.conf_end_date
        If IsDBNull(_reg_info.tues_class) Then
            _Class_1 = ""
        End If
        If IsDBNull(_reg_info.wed_class) Then
            _Class_2 = ""
        End If
        If IsDBNull(_reg_info.thur_class) Then
            _Class_3 = ""
        End If
        If IsDBNull(_reg_info.fri_class) Then
            _Class_4 = ""
        End If

        'Dim pdfpath As String = Server.MapPath("PDFs")
        'Dim imagepath As String = Server.MapPath("Images")
        Dim pdfpath As String = "C:\temp\"
        Dim imagepath As String = "C:\temp\"
        Dim doc As New Document
        doc.SetPageSize(iTextSharp.text.PageSize.A4)
        doc.SetMargins(0, 0, 2, 2)

        Try
            Dim writer As PdfWriter = PdfWriter.GetInstance(doc, New FileStream(pdfpath + "/Images.pdf", FileMode.Create))
            doc.Open()
            Dim cb As PdfContentByte = writer.DirectContent
            cb.BeginText()
            cb.SetTextMatrix(100, 400)
            cb.ShowText(_LastName)
            cb.EndText(开发者_开发技巧)
            doc.Add(New Paragraph("JPG"))
            Dim jpg As Image = Image.GetInstance(imagepath + "/Asads_Tags.jpg")
            jpg.Alignment = iTextSharp.text.Image.UNDERLYING
            jpg.ScaleToFit(576, 756)
            doc.Add(jpg)
        Catch dex As DocumentException
            Response.Write(dex.Message)
        Catch ioex As IOException
            Response.Write(ioex.Message)
        Catch ex As Exception
            Response.Write(ex.Message)
        Finally
            doc.Close()

        End Try



        Return RedirectToAction("Index")


    End Function

Anyone know where I could be going wrong at??????


The Try Catch block is what caused the unbalanced start/end exception.....Once I moved the doc.close() up to the bottom of try the error went away... Oh well maybe someone else will need the insight... –

0

精彩评论

暂无评论...
验证码 换一张
取 消