cognidox / OfficeToPDF

A command line tool to convert Microsoft Office documents to PDFs
https://www.cognidox.com/
Other
610 stars 137 forks source link

Problem starting from TFS Network service #12

Closed AdriedB closed 6 years ago

AdriedB commented 6 years ago

Hi,

When I tried to use OfficeToPDF within a TFS batch proces (runs under Network Service), then I get the following error.

Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).

I already gave the Network Service alle the right in the DCOM Config (Component Services/DCOM Config/Microsft Wordt 97 - 2003-document)

Any help is appreciated!

Kind regards,

Adrie

vittala commented 6 years ago

Hi Adrie

When you gave DCOM permissions, you should provide rights to the Word application, rather than Word document.

Did you follow the steps suggested in https://blogs.technet.microsoft.com/the_microsoft_excel_support_team_blog/2012/11/12/microsoft-excel-or-microsoft-word-does-not-appear-in-dcom-configuration-snap-in/

Regards Vittal

vittala commented 6 years ago

Also, in the DCOM permissions for "Microsoft Word 97 - 2003-document", ensure that the NETWORK SERVICE has all "Launch and Activation Permissions".

You may also need to create the folder C:\Windows\SysWOW64\config\systemprofile\Desktop

AdriedB commented 6 years ago

Hi Vittal,

Thanks for your quick response.

On my system (W7/Office 2016) I had to set the privileges for "Microsoft Word 97 - 2003-document".

Then I got the following error:

The remote procedure call failed. (Exception from HRESULT: 0x800706BE) Unhandled Exception: System.Runtime.InteropServices.COMException: The RPC server is unavailable. (Exception from HRESULT: 0x800706BA) at Microsoft.Office.Interop.Word.ApplicationClass.Quit(Object& SaveChanges, Object& OriginalFormat, Object& RouteDocument) at OfficeToPDF.WordConverter.Convert(String inputFile, String outputFile, Hashtable options) at OfficeToPDF.Program.Main(String[] args)

but this error disappeared after creating the desktop folder as you suggested previously. C:\Windows\SysWOW64\config\systemprofile\Desktop

Unfortunately now I ran into another error message:

_Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXECFAILURE)). Did not convert

Do you have any suggestions left?

Kind regard, Adrie

vittala commented 6 years ago

Hi Adrie

Have you tried giving the user that TFS runs as (rather than just NETWORK SERVICE) full DCOM permissions (Launch & Activation / Access & Configuration Permissions)?

I'd also do a repair on your Office installation to ensure that's not the source of the problem.

Regards Vittal

AdriedB commented 6 years ago

Hi Vittal,

I switched from Network Servive to a user account to start the TFS Agent. I also added this user to the DCOM security, I repaired the installation of Office 2016.

OfficeToPdf is working with this user account locally.

But running within the TFS Agent I get another error message:

      _Object reference not set to an instance of an object._

And with the task manager I can see that Winword.exe is running and claiming more and more memory, 1.402.260K and still counting. Something is still going wrong.

Kind regards, Adrie

vittala commented 6 years ago

Hi Adrie

Difficult to say what's causing this as we can't replicate your environment here and can't see your documents.

I don't know what you're trying to make OfficeToPDF do, but sometimes in a server context it's best to avoid Office altogether (Microsoft specifically state that running Office in a server context isn't supported). What we've seen some success with (depending on the style of the documents being converted) is to use LibreOffice and it's convert-to switch. e.g.

"c:\Program Files (x86)\LibreOffice 5\program\soffice.exe" --headless --convert-to pdf "some-doc.docx"

You may find this route easier than battling Microsoft!

Regards Vittal

AdriedB commented 6 years ago

Hi Vittal,

You're right. This cost to much time to get it working.

I'll give LibreOffice a try, but our experience before was that the layout changed after opening a document with OpenOffice.

But I'will try it with LibreOffice, maybe it works for our documents.

Thanks again for your quick response!

Kind regards, Adrie

chrisribe commented 5 years ago

@AdriedB did you manage to get LibreOffice to run correctly ? I am having the same issues, the exe works when run localy on the server but not via the NetworkService account. Or any other account set in the IIS application identity pool

chrisribe commented 5 years ago

Found this solution seems the Component Services needs to be setup to use a valid account. Maybe the fact that "Network Service" as pool identity causes issues ?

1) Make sure you are able to start MS Word normally under that user account and dismiss all the dialogs that may appear (license, your info with initials, etc.). 2) Start Word once again and make sure no dialogs appear. 3) Launch dcomcnfg.exe->Console Root->Component Services->Computers->My Computer->DCOM Config->Microsoft Office Word 97 2003 ->Right Click(Properties)->Identity Tab and fill in the same user account information as for service.

Reference: https://www.php.net/manual/en/ref.com.php#120122

AdriedB commented 5 years ago

Hi Chris,

Thanks for you additional information. I haven't succeeded in getting MS Office to work in combination with the TFS service.

I do not want to work with a user account for the TFS service.

So for this moment I don't have a solution for the automatic doc/docx conversion in combination with TFS.

Kind regards, Adrie

On Wed, Aug 28, 2019, 3:28 PM ChrisRibe notifications@github.com wrote:

Found this solution seems the Component Services needs to be setup to use a valid account. Maybe the fact that "Network Service" as pool identity causes issues ?

  1. Make sure you are able to start MS Word normally under that user account and dismiss all the dialogs that may appear (license, your info with initials, etc.).
  2. Start Word once again and make sure no dialogs appear.
  3. Launch dcomcnfg.exe->Console Root->Component Services->Computers->My Computer->DCOM Config->Microsoft Office Word 97 2003 ->Right Click(Properties)->Identity Tab and fill in the same user account information as for service.

Reference: https://www.php.net/manual/en/ref.com.php#120122

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/cognidox/OfficeToPDF/issues/12?email_source=notifications&email_token=AC6OFYG4POGNAI3FZ3NSB7DQGZ4QXA5CNFSM4EKMKWXKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5LDZFQ#issuecomment-525745302, or mute the thread https://github.com/notifications/unsubscribe-auth/AC6OFYHDNHICV6VYMGZVOKLQGZ4QXANCNFSM4EKMKWXA .