我需要在文本文件中解析这个pdf文档。为此,我使用iTextSharp动态链接库。我的整个PDF文档解析都是正确的,除了pdf文档中有一个包含行的表。它解析了那个表,但是如果表的一个单元格中有一些空间,那么我在转换后的文本文档中看不到这个空间。下面是表格的格式。
Col1 Col2 Col3 Col4 Col5
1 Test1 2 5 Test6
2 3 Test7
3 Test6 9 Test8
我看到的输出如下:
1 Test1 2 5 Test6 <LF>
2 3 Test7<LF>
3 Test6 9 Test8<LF>
<LF> is line feed.
有没有办法,我也能看到那些空间?下面是PDF解析代码:
Public Sub ExtractTextFromPdf(path As String)
Dim its As ITextExtractionStrategy = New LocationTextExtractionStrategy()
Dim HeadLine As String
Using reader As New PdfReader(path)
Dim str As New StringBuilder()
For i As Integer = 1 To reader.NumberOfPages
Dim thePage As String = PdfTextExtractor.GetTextFromPage(reader, i, its)
Dim pdf31460Lines As String() = thePage.Split(ControlChars.Lf)
For Each EachLine As String In pdf31460Lines
str.AppendLine(EachLine)
If EachLine.Contains("SNEW") Then
HeadLine = EachLine
End If
Next
Next
InsertParsedFileHeader(str.ToString(), HeadLine)
' ParsedFileWithSeperator = Regex.Replace(ParsedFileWithSeperator, "\s+", "~")
End Using
End Sub
我已经找了3-4天了,找不到正确的答案。
任何帮助都将不胜感激。我需要在.net-C#或VB.net中这样做
发布于 2014-09-17 19:57:32
我想出来了。为此,我使用了pdfBox。它有点慢,但它是完全免费和非常准确的解析pdf文档。如果有人感兴趣,下面是pdf框的链接。
http://www.squarepdf.net/pdfbox-in-net
https://stackoverflow.com/questions/25857679
复制相似问题