可以参考:
- Public Sub CallImgToPdfAsync(urls As Object(, ), outputPdf As String)
- 'Dim exePath As String = "C:\Users\Administrator\source\repos\imgTopdf\bin\Debug\ImgToPdf.exe"
- Dim exePath As String = Directory.GetCurrentDirectory() + "\Dll\topdf\ImgToPdf.exe"
- ' urls参数是二维数组,每行所有列用逗号分隔
- Dim arguments As New System.Text.StringBuilder()
- If urls IsNot Nothing Then
- Dim rows As Integer = urls.GetLength(0)
- Dim cols As Integer = urls.GetLength(1)
- Dim first As Boolean = True
- For r As Integer = 0 To rows - 1
- Dim arr As New List(Of String)()
- For c As Integer = 0 To cols - 1
- Dim val As String = ""
- If urls(r, c) IsNot Nothing Then val = urls(r, c).ToString().Trim()
- arr.Add(val)
- Next
- If arr(0) <> "" Then
- If Not first Then arguments.Append(" ")
- arguments.Append(String.Join(",", arr))
- first = False
- End If
- Next
- End If
- If Not String.IsNullOrWhiteSpace(outputPdf) Then
- If arguments.Length > 0 Then arguments.Append(" ")
- arguments.Append("-o ")
- arguments.Append(outputPdf)
- End If
- ' MessageBox.Show(arguments.ToString(), "调用参数")
- Task.Run(Sub()
- Dim psi As New ProcessStartInfo() With {
- .FileName = exePath,
- .Arguments = arguments.ToString(),
- .UseShellExecute = False,
- .RedirectStandardOutput = False,
- .RedirectStandardError = False,
- .CreateNoWindow = True,
- .WorkingDirectory = IO.Path.GetDirectoryName(exePath)
- }
- Dim proc As New Process()
- proc.StartInfo = psi
- proc.Start()
- proc.WaitForExit()
- ' 进程结束后尝试打开输出 PDF(静默尝试)
- Try
- If Not String.IsNullOrWhiteSpace(outputPdf) AndAlso IO.File.Exists(outputPdf) Then
- Try
- Process.Start(outputPdf)
- Catch
- ' 忽略打开失败
- End Try
- End If
- Catch
- End Try
- proc.Dispose()
- End Sub )
- End Sub
复制代码
|
|
lexianfeng