cpdf을 사용하여 PDF 파일을 연결합니다.Process.Start에 전달 된 인수의 문자열 인코딩 오류
그것은이 코드에 의해 수행됩니다
이Private Shared Sub ConcatenateWithCpdf(
outputFileName As String,
inputfilenames() As String,
Optional timeout As Integer = 15000,
Optional ByRef process_exitcode As Integer = 0,
Optional ByRef process_output As String = Nothing,
Optional ByRef process_erroroutput As String = Nothing)
Dim output As New Text.StringBuilder()
Dim erroroutput As New Text.StringBuilder()
Using process As New Process()
process.StartInfo.FileName = CpdfPath()
process.StartInfo.Arguments = String.Format(
"{0} -o ""{1}""",
Join(
inputfilenames.Select(
Function(s) String.Format("""{0}""", s)).ToArray,
" "),
outputFileName)
process.StartInfo.CreateNoWindow = True
process.StartInfo.UseShellExecute = False
process.StartInfo.RedirectStandardOutput = True
process.StartInfo.RedirectStandardError = True
Using outputWaitHandle As New Threading.AutoResetEvent(False)
Using errorWaitHandle As New Threading.AutoResetEvent(False)
AddHandler process.OutputDataReceived,
Sub(sender As Object, e As DataReceivedEventArgs)
If e.Data Is Nothing Then
outputWaitHandle.Set()
Else
output.AppendLine(e.Data)
End If
End Sub
AddHandler process.ErrorDataReceived,
Sub(sender As Object, e As DataReceivedEventArgs)
If e.Data Is Nothing Then
errorWaitHandle.Set()
Else
erroroutput.AppendLine(e.Data)
End If
End Sub
process.Start()
process.BeginOutputReadLine()
process.BeginErrorReadLine()
If process.WaitForExit(timeout) AndAlso
outputWaitHandle.WaitOne(timeout) AndAlso
errorWaitHandle.WaitOne(timeout) Then
process_exitcode = process.ExitCode
End If
End Using
End Using
End Using
process_output = output.ToString
process_erroroutput = erroroutput.ToString
End Sub
내 문제는, 일부 입력 파일 이름이 같은 비 ASCII 문자가된다
이 경우 C:\Users\myuser\AppData\Local\Temp\Procuração - Processo 5001092-92.2017.4.03.6114.pdf
이 CPDF이 실패하고 이 표준 출력 오류 텍스트를 반환합니다.
cpdf 오류가 발생했습니다. 기술 세부 사항은 따라하지 :
C : \ 사용자 \ 참고 MyUser \의 AppData \ 로컬 \ 온도 \ Procurac¸a ~ O를 - Processo의 5001092-92.2017.4.03.6114.pdf을 :
분명히 그런 파일이나 디렉토리를 filename을 인수를 전달할 때 일종의 인코딩 불일치로 인해 손상되었습니다.
어떻게 해결할 수 있습니까?
다음과 같은 코드를 사용하여 파일을 확인해야 할 수 있습니다
어디서 어떻게 입력 파일 이름 목록을 가져오고 있습니까? –
@Idle_Mind, 전자 메일 첨부 파일 목록이며 원래 이름이 붙어 있습니다. 하지만 그들은 오류가 발생하는 시점에 디스크에 이미 저장되어 있으므로 해당 이름이 Windows에서 유효하다고 확신합니다. – VBobCat