Convert odt to pdf

Asked

Viewed 54 times

-1

I need to convert files from the .ODT for .PDF, if I run the following command in cmd it works:

cd C:\Program Files\LibreOffice\program>
soffice.exe --headless --convert-to pdf --outdir C:\temp\ C:\temp\a.odt 

Yet I converted him to c# and it doesn’t work, someone knows what’s wrong?

        String fileName = Path.GetFileName(@"C:\temp\a.odt");
        string fileDir = Path.GetDirectoryName(@"C:\temp");
        //soffice.exe --headless --convert-to pdf --outdir C:\temp\ C:\temp\a.odt
        var pdfProcess = new Process();
        pdfProcess.StartInfo.FileName = @"C:\Program Files\LibreOffice\program\soffice.exe";
        pdfProcess.StartInfo.Arguments =
            String.Format("--headless --convert-to pdf --outdir C:\temp C:\temp\a.odt"
                                  , fileName);
        //  pdfProcess.StartInfo.WorkingDirectory = fileDir;
        //pdfProcess.StartInfo.RedirectStandardOutput = true;
        //pdfProcess.StartInfo.RedirectStandardError = true;
        //pdfProcess.StartInfo.UseShellExecute = false;
        //\"{0}\"
        pdfProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
        pdfProcess.StartInfo.CreateNoWindow = true;
        pdfProcess.Start();
        pdfProcess.WaitForExit();
        pdfProcess.Close();
        //string output = pdfProcess.StandardOutput.ReadToEnd();
        //string error = pdfProcess.StandardError.ReadToEnd();
        Console.WriteLine("teste 1");
        //Console.WriteLine(output);
        Console.WriteLine("teste 2");
        Console.Read();
  • What is the error shown?

  • No error message is generated simply the file does not appear in the directory and no exception occurs.

  • can solve in the Arguments line I added the @ before typing the quotes @"-headless --Convert-to pdf --outdir C: temp C: temp a. odt";

1 answer

0

can solve in the Arguments line I added the @ before typing the quotes thus

            pdfProcess.StartInfo.Arguments = @"--headless --convert-to pdf --outdir C:\temp C:\temp\a.odt";

Browser other questions tagged

You are not signed in. Login or sign up in order to post.