0

I've been trying to make the PODConverter work as a Service, but it just doesn't want to work. The funny thing is that we used an older version which was working fine or let's just say that it was at least doing something. We have to switch now, because the soffice.exe crashed randomly.

So I made a new testproject with the new version of the JODConverter (jodconverter-core-3.0-beta-4-dist), but I left the basic build as it is. Such as the arguments fpr the service.

My testproject doesn't do that much. It only copies a bunch of .odt files to another folder and then tries to convert them into .pdfs, but nothing is happening. No pdfs, no error .. nothing.

I have no clue why this won't work and I really hope you guys can help me out here, because this is really making me crazy.

[EDIT] Ok, I found one problem and I sort of know why it's not working: Apparently the Output is empty, but I don't know why.

[EDIT2] Found the error .. forgot part of the path to the jar. Code:

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
OhSnap
  • 376
  • 2
  • 10
  • 30

1 Answers1

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
Styxxy
  • 7,462
  • 3
  • 40
  • 45
  • Besides dumping some code, can you please explain what the TS is doing wrong and how it solves with your code (so explain your code)? – Styxxy Oct 10 '12 at 23:28