2012-04-19 22 views
0

我一直在试图使PODConverter工作作为一项服务,但它只是不想要的工作。有趣的是,我们使用了一个工作正常的旧版本,或者说我们至少在做一些事情。我们必须现在切换,因为soffice.exe随机崩溃。PODConverter服务(vb.net)的.odt为.pdf

所以我用新版本的JODConverter(jodconverter-core-3.0-beta-4-dist)做了一个新的测试项目,但是我保持原样。如服务的争论。

我testproject没有做那么多。它只会将一堆.odt文件复制到另一个文件夹中,然后尝试将它们转换为.pdf,但没有任何事情发生。没有pdf,没有错误..没有。

我不知道为什么这是不行的,我真的希望你们能帮助我在这里,因为这实在是让我疯了。

[编辑]好吧,我发现了一个问题,我有点知道为什么它不工作:显然,输出是空的,但我不知道为什么。

[EDIT2]找到错误..忘记路径到罐的一部分。 代码:

Imports System 
Imports System.Configuration 
Imports System.IO 
Imports System.Text 
Imports System.Collections.Generic 

Module Module1 
    Private OutputMsg As System.Text.StringBuilder = Nothing 
    Private ErrorMsg As System.Text.StringBuilder = Nothing 


    Sub Main() 

     Dim FilesToDelete = Directory.GetFiles("D:\temp") 
     For Each File In FilesToDelete 
      System.IO.File.Delete(File) 
     Next 
     Dim FilesToConvert = System.IO.Directory.GetFiles("D:\Source", "*.odt", IO.SearchOption.TopDirectoryOnly) 
     Dim loopCounter As Integer = 0 
     Dim fileCounter As Integer = 0 

     Try 
      For Each file In FilesToConvert 
       loopCounter += 1 
       fileCounter += 1 
       System.IO.File.Copy(file, "D:\temp\" + System.IO.Path.GetFileName(file)) 
       'Prüfe, ob die Blockgröße erreicht ist oder die letzte Datei übertragen wurde! 
       If fileCounter = FilesToConvert.Count Then 
        convertFiles() 

        loopCounter = 0 
       End If 
      Next 
     Catch ex As Exception 
      MsgBox(ex.ToString) 
     End Try 
    End Sub 

    Private Sub convertFiles() 

     Try 
      Dim proc As New Process 
      proc.StartInfo.WorkingDirectory = "D:\jodconverter-core-3.0-beta-4-dist\jodconverter-core-3.0-beta-4" 
      proc.StartInfo.FileName = "C:\Program Files (x86)\Java\jre6\bin\java.exe" 
      proc.StartInfo.Arguments = "java -jar lib/jodconverter-core-3.0-beta-4.jar -o pdf d:\temp\*.odt" 
      proc.StartInfo.UseShellExecute = False 
      proc.StartInfo.RedirectStandardOutput = True 
      proc.StartInfo.RedirectStandardError = True 
      proc.StartInfo.RedirectStandardInput = True 


      OutputMsg = New System.Text.StringBuilder() 

      AddHandler proc.OutputDataReceived, AddressOf OutputHandler 
      AddHandler proc.ErrorDataReceived, AddressOf ErrorHandler 

      proc.Start() 
      proc.BeginOutputReadLine() 

      proc.WaitForExit() 
      'Me.SetExitCode(proc.ExitCode) 

     Catch ex As Exception 
      MsgBox(ex.ToString) 
     End Try 
    End Sub 
    Private Sub OutputHandler(ByVal sendingProcess As Object, _ 
    ByVal outLine As DataReceivedEventArgs) 
     Try 
      ' Collect the sort command output. 
      If Not String.IsNullOrEmpty(outLine.Data) Then 
       ' Add the text to the collected output. 
       OutputMsg.Append(Environment.NewLine + outLine.Data) 
      Else 
       MsgBox("Outline is empty!") 
      End If 

     Catch ex As Exception 
      MsgBox(ex.ToString) 
     End Try 
    End Sub 

    Private Sub ErrorHandler(ByVal sendingProcess As Object, _ 
    ByVal outLine As DataReceivedEventArgs) 

     ' Collect the sort command output. 
     If Not String.IsNullOrEmpty(outLine.Data) Then 

      ' Add the text to the collected output. 
      ErrorMsg.Append(Environment.NewLine + outLine.Data) 
     Else 
      MsgBox("Error is empty!") 
     End If 
    End Sub 
End Module 

回答

0
Dim InstruccionJava As String = "java -jar lib\jodconverter-core-3.0-beta-4.jar " 
Dim RutaConvertidor As String = rutaServer & "\Convertidor" 

Dim proc As New Process 
proc.StartInfo.WorkingDirectory = RutaConvertidor & "\lib" 


Dim Argunment As String = "-jar " & RutaConvertidor & "\lib\jodconverter-core-3.0-beta-4.jar " & Ruta & " " & Rutahtml 
proc.StartInfo.FileName = "java" '"C:\Archivos de programa\Java\jre7\bin\java.exe" 
proc.StartInfo.Arguments = Argunment 
proc.StartInfo.UseShellExecute = False 
proc.StartInfo.RedirectStandardOutput = True 
proc.StartInfo.RedirectStandardError = True 
proc.StartInfo.RedirectStandardInput = True 
proc.Start() 
proc.BeginOutputReadLine() 
proc.WaitForExit() 
Dim OutputMsg As System.Text.StringBuilder = Nothing 
OutputMsg = New System.Text.StringBuilder() 
Dim redireccion As String = "Descargas/" & nombre & ".pdf" 
Me.visor.Attributes("src") = redireccion 
lberror.Text = OutputMsg.ToString 
+0

除了倾倒一些代码,能否请您解释一下什么是TS是做错了,它如何与你的代码(这样解释你的代码)可以解决? – Styxxy 2012-10-10 23:28:28