I have written a Windows service in C# that monitors a directory for new files, then launches the docpub.exe as a system process to convert the document to PDF. We use Linux so we don’t need the SDK for .NET, we just want to run the conversion of Office documents to PDF so that is why we are using docpub.
Running docpub on office documents works fine from the command line. It converts DOCX, PPTX, and XLSX to PDF, but docpub fails on Excel files when launched via the windows service (but it works for Word or PowerPoint files).
This is the command we are using (which works):
.\docpub64.exe -f pdf -o C:\ConvertedDocuments --noprompt C:\excel_file.xlsx
Here is the relevant code from our C# service:
`
//Create process
System.Diagnostics.Process pProcess = new System.Diagnostics.Process();
string arguments = String.Format(@"-f pdf -o C:\ConvertedDocuments --noprompt “”{0}""", filename);
// path and file name of command to run
pProcess.StartInfo.FileName = @“C:\docpub64.exe”;
// parameters to pass to program
pProcess.StartInfo.Arguments = arguments;
// must execute as shell to capture stdout
pProcess.StartInfo.UseShellExecute = false;
//Set output of program to be written to process output stream
pProcess.StartInfo.RedirectStandardOutput = true;
pProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
pProcess.StartInfo.CreateNoWindow = true;
//Start the process
pProcess.Start();
//Get program output
string strOutput = pProcess.StandardOutput.ReadToEnd();
//Wait for process to finish
pProcess.WaitForExit();
`
And this is the output when trying to convert an Excel file:
DocPub completed: 'Processing... C:\excel_file.xlsx Unsupported format. The file can not be converted. Error: An error occurred while converting the file. Detailed error: Error converting Microsoft Office document.
We are running the service as Local System. As mentioned above, it converts Word and PowerPoint files fine, but fails on Excel files.
Any ideas?