Vb.net 将PDF导入SQL

Vb.net 将PDF导入SQL,vb.net,sql-server-2008,Vb.net,Sql Server 2008,我有一个pdf文件,我把它转换成单独的HTML文件, 我的目标是将它们导入MS SQL,以便在表中搜索特定标识符和 在网页上显示结果 我能够读取所有的html文件,并将其放入SQL表中,但转换器正在切割完整的句子,因为它们被拆分为多个div容器 <div class="S2"> DA0-17.0</div> <div class="S5"> 1416</div> <div class="S2"> Required when the su

我有一个pdf文件,我把它转换成单独的HTML文件, 我的目标是将它们导入MS SQL,以便在表中搜索特定标识符和 在网页上显示结果

我能够读取所有的html文件,并将其放入SQL表中,但转换器正在切割完整的句子,因为它们被拆分为多个div容器

<div class="S2"> DA0-17.0</div>
<div class="S5"> 1416</div>
<div class="S2"> Required when the subscriber is the same person as the patient. If</div>
<div class="S5"> 2698</div>
<div class="S2"> the subscriber is not the same person as the patient, do not use</div>
<div class="S2"> this element.</div>
<div class="S4"> CODE</div>
<div class="S4"> DEFINITION</div>
<div class="S2"> 18</div>
<div class="S2"> Self</div>
希望有人能帮助我解决这个问题,或者为我指出解决这个问题的正确方向。 完整的代码可根据要求提供。 谢谢你抽出时间, 罗伯特

Ps:这是基于应用程序的,不是基于web的

在答复Edper时:

Dim fFileName As String
Dim dListing As New DirectoryInfo(My.Settings.ImportDir)
Dim aFileArray As FileInfo() = dListing.GetFiles()
Dim fFiles As FileInfo
    For Each fFiles In aFileArray
    fFileName = fFiles.Name
    Dim fStream = New FileStream(My.Settings.ImportDir + "\" + fFileName, FileMode.Open)
    Dim sReader = New StreamReader(fStream)
回复Edper.
我想要的是:

在HTML文件中(大约700个)是具有不同类名的div容器

 <div class="S2"> Required when the subscriber is the same person as the patient. If</div>
 <div class="S5"> 2698</div>
 <div class="S2"> the subscriber is not the same person as the patient, do not use</div>
 <div class="S2"> this element.</div>
当订户与患者是同一个人时,
必需。如果
2698
订户与患者不是同一个人,请勿使用
这个元素。
我可以为每个事件创建insert语句,但是我希望
之间的“描述”是一行很长的文本,目前它被分成3个部分,我不想,我不知道如何组合它们。
我对VB.NET的知识相当有限,我一直在努力学习,我在经典ASP中表现得非常高效,但在这种情况下,这是行不通的

很抱歉,我的问题表述得很糟糕。

我简直不知道该怎么进一步解释

您可以在表单中删除
Webbrowser
控件,然后将其设置为
visible=false
,这样就不会显示它了。然后只需为字符串生成器声明一个全局变量,如:

Dim builder As New StringBuilder
然后,当您获得此代码中的所有HTML文件时,您可能会这样做:

Dim fFileName As String
Dim dListing As New DirectoryInfo(My.Settings.ImportDir)
Dim aFileArray As FileInfo() = dListing.GetFiles()
Dim fFiles As FileInfo

For Each fFiles In aFileArray
    WebBrowser1.Navigate(dListing&"\"&fFiles)
Next
当使用
WebBrowser1\u DocumentCompleted
事件完全加载html时,您将从多个
div中获得所有类(如
S2
),如:

    Dim elems As HtmlElementCollection
    elems = WebBrowser1.Document.GetElementsByTagName("DIV")

    For Each elem As HtmlElement In elems

        If (elem.GetAttribute("className") = "S2") Then
            builder.Append(elem.InnerHtml).Append(" ")
        End If
    Next

    'Do something for string builder (i.e. builder.ToString()) here before clearing the String Builder like this could be where you insert the records to your table probably

    builder.Clear()

是否希望将同一类的div作为一个句子插入到表中?你在这个问题上使用Webbrowser控件吗?@Edper,我用部分代码更新了我的问题。是的,我希望它是一个句子而不是多个部分。所以,让我再次澄清。您已将PDF文件转换为HTML文件。但是你的问题是你的类被分成多个div?您想将这些多个div(一个类)放到一个句子中,然后添加到数据库表中吗?我真的不确定你在这里想要完成什么,所以请更具体地回答你的问题,并针对你希望其他人关注的领域,以便我们能够帮助你。谢谢。很抱歉,我没有看到你回答的最后一部分基本上回答了我的问题。因此,我想您有一个HTML文件,为什么不加载到用户看不到的webbrowser上,但您可以从后面处理它呢。因为从webbrowser获取类(虽然ID是理想的)比从流获取类更容易。@Edper有没有办法让我给您发送一条私人消息?谢谢您的回答Edper,不过我马上就要回家了,所以我明天会尝试这个建议,然后我会接受它:)谢谢!我还有一个问题要问你,我最终得到的字符串和现在得到的相同,这种方法有什么不同?在我的例子中,我把所有的类S2放在一个字符串中,而不是分开的字符串中。对你来说也是这样吗?因为你在原来的帖子里说,你希望它是一句话,而不是多个部分。或者我完全误解了你的问题:-)我的意思是:我在一个字符串中获取所有S2,并且能够将其输入数据库,但问题是“描述”被分解为多个部分,我希望它是一个部分,是否有可能扫描S5和S4,并获得这两条线之间的线?@RobertdeJonge你的意思是像S5 1416和2698一样作为值,然后你的S4有代码和定义。所以,你想让它成为S2中整个句子的一部分,我们把它放在一个字符串中?还是要分开?因为如果只有一个,那么你也可以测试S4和S5。
    Dim elems As HtmlElementCollection
    elems = WebBrowser1.Document.GetElementsByTagName("DIV")

    For Each elem As HtmlElement In elems

        If (elem.GetAttribute("className") = "S2") Then
            builder.Append(elem.InnerHtml).Append(" ")
        End If
    Next

    'Do something for string builder (i.e. builder.ToString()) here before clearing the String Builder like this could be where you insert the records to your table probably

    builder.Clear()