【发布时间】:2014-01-18 20:32:02
【问题描述】:
这将是一个很长的问题,但很容易解决。
所以我设法将 pdf 转换为字符串,然后只需将文件名放在文本框中即可打印外部 pdf。
我还想出了如何从 pdf 字符串中提取某些文本,现在某些文本也是位于外部位置的文件(我使用 c:\temp\ 进行测试)。
这给我留下了一个问题,我提取的文本,我使用 shellexecute 打印,如果它是一个字符串就可以正常工作。但是,如果我提取的文件名不止一个,它会将其计为单个字符串,从而将位置和 .pdf 添加到该字符串中。而不是两个或多个字符串。它会做这样的事情:
如您所见,它将发送到打印机。我想一次发送一个到打印机。像这样:
我尝试过使用 Arraylist 和各种方法。但我自己缺乏知识,我无法弄清楚。
我认为“for 循环”会帮助我。有任何想法吗? 下面是我的代码。
Dim pdffilename As String = Nothing
pdffilename = RawTextbox.Text
Dim filepath = "c:\temp\" & RawTextbox.Text & ".pdf"
Dim thetext As String
thetext = GetTextFromPDF(filepath) ' converts pdf to text from a function I didnt show.
Dim re As New Regex("[\t ](?<w>((asm)|(asy)|(717)|(ssm)|(715)|(818))[a-z0-9]*)[\t ]", RegexOptions.ExplicitCapture Or RegexOptions.IgnoreCase Or RegexOptions.Compiled) ' This filters out and extract certain keywords from the PDF
Dim Lines() As String = {thetext}
Dim words As New List(Of String)
For Each s As String In Lines
Dim mc As MatchCollection = re.Matches(s)
For Each m As Match In mc
words.Add(m.Groups("w").Value)
Next
RawRich4.Text = String.Join(Environment.NewLine, words.ToArray)
Next
'This is where I need help with the code. how to have "words" putout "c:\temp\" & RawRich4.Text & ".pdf" with each keyword name
Dim rawtoprint As String = String.Join(Environment.NewLine, words.ToArray)
Dim defname As String = Nothing
defname = RawRich4.Text
rawtoprint = "c:\temp\" & RawRich4.Text & ".pdf"
Dim psi As New System.Diagnostics.ProcessStartInfo()
psi.UseShellExecute = True
psi.Verb = "print"
psi.WindowStyle = ProcessWindowStyle.Hidden
psi.Arguments = PrintDialog1.PrinterSettings.PrinterName.ToString()
psi.FileName = (rawtoprint) ' this is where the error occurs it doesn't send both files separately to the printer, it tries to send it as one name
MessageBox.Show(rawtoprint) ' This is just to test the output, this will be removed.
'Process.Start(psi)
End Sub
【问题讨论】:
-
您有已知的文件名模式吗?例如,假设它们都是 8 个字符或以 ASM 之类的字符串开头?另外,如果你的输入文件名是 1 个文件,你怎么会得到很多文件名?
标签: vb.net string pdf for-loop arraylist