这个代码运行几个循环,程序就崩溃了,是什么原因?
怎么优化?
Dim ch1 As WinForm.CheckBox = e.Form.Controls("CheckBox1")
DataTables("报告收集").LoadFilter = "_Identify is not null"
DataTables("报告收集").Load
For Each dr As DataRow In DataTables("报告收集").Select("文件名称 is not null and 识别完成 = false")
If FileSys.FileExists(dr("文件名称")) Then
Dim pdfFile = O2S.Components.PDFRender4NET.PDFFile.Open(dr("文件名称")) '红色为文件路径
dr("页数") = pdfFile.PageCount
For i As Integer = 0 To pdfFile.PageCount - 1
If i = 0 OrElse i > 5 AndAlso i < 20 Then
Dim st As String = ""
Try
Dim pageImage As Image = pdfFile.GetPageImage(i,300) '第一个参数1为页数,从0开始,1表示第二页;第二个参数为图片清晰度,数值越大越清晰,同时保存的图片文件也就越大
FileSys.CreateDirectory(SpecialFolder.DesktopDirectory & "\报告")
Dim jpgi As String = SpecialFolder.DesktopDirectory & "\报告\" & FileSys.GetName(dr("文件名称")).SubString(0,FileSys.GetName(dr("文件名称")).LastIndexOf(".")) & i & ".jpg"
pageImage.Save(jpgi)
pageImage.Dispose() '释放内存资源
Dim doc = CreateObject("MODI.Document")
doc.Create(jpgi)
doc.OCR(2052, True, True)
Dim layout = doc.images(0).Layout
st = layout.text
If st <> "" Then
st = st.Replace(" ","")
If i = 0 Then
dr("首页字符") = st
Else
If st <> "" AndAlso st.Contains("联系") AndAlso (st.Contains("经济类型") OrElse st.Contains("陪同") OrElse st.Contains("用人单位")) Then
dr("联系信息页") = st
Exit For
End If
End If
End If
FileSys.DeleteFile(jpgi,2,2)
Catch ex As Exception
End Try
If ch1.Checked = True Then
Exit For
End If
End If
Next
dr("识别完成") = True
dr.Save()
End If
If ch1.Checked = True Then
Exit For
End If
Next
MessageBox.Show("ok")