2011-09-30 34 views
0

我工作的應用程序,使用ItextSharp生成PDF文件,供學生打印名稱標籤和停車許可證......但它一直在拋出:不平衡的開始/結束文本操作符。在doc.close() 塊似乎是正確openned和關閉..下面是函數:使用ItextSharp我得到不平衡的開始/結束文本運算符。但他們匹配

 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 

任何人都知道我可以在會錯誤??????

回答

2

Try Catch塊是什麼導致了不平衡的開始/結束異常.....一旦我將doc.close()移動到嘗試的底部,錯誤就消失了......哦,也許別人會需要洞察力... -

相關問題