Running docpub from a windows service not working for Excel files

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?

The “Error converting Microsoft Office document” is an old error message. If you can, and it depends if you purchased a license or not, to upgrade DocPub and see if that addresses the issue.
https://www.pdftron.com/docpub/downloads.html

That will either “fix” the issue, or provide a better error message.

If you have not already, please read this document.
http://www.pdftron.com/pdfnet/faq_files/Converting_Documents_in_Windows_Service_or_ASP.NET_Application_using_PDFNet.pdf

Otherwise, does the error occur on all excel documents, or only certain ones?
If all excel docs, then try running DocPub from the command line (outside of any server environment). If it works there, then it is either a security/permission issue, or missing Temp folder for the server account.

If it is certain files, they probably have a macro or scripting in them that is causing a problem.

Thanks Ryan. Upgrading docpub did not solve the issue, and it happens on every Excel file, not just some. If I run it as a command line program, it converts all Office documents fine, but does not work as a service.

I read through the document you mentioned below, but the changes recommended don’t fix the issue.

I’ll run it as a command line program for now, and revisit the problem running it as a service later.

One thing that came up with another customer, was that it appears that Office in trial/unlicensed mode does not work in a service.

See this post from today.
https://groups.google.com/forum/?fromgroups#!topic/pdfnet-sdk/l3SLXOJhgZ0

Additionally, if the print spooler isn’t enabled, that can cause Excel conversions to fail (even if using Office Interop to drive the conversion). Thus, you should try enabling the print spooler if Excel conversion is failing.

For many Windows versions, you can enable the print spooler by running the following at a command line:

net start spooler