Troubleshooting ABCpdf and Microsoft Office Installations

ABCpdf allows you to import Office documents in a number of ways through a choice of read modules. The MS Office read module, introduced in ABCpdf version 8, provides a better conversion process for Microsoft Office documents and ease of use. The guidance published on this page applies to older versions of ABCpdf and document conversions using the XpsAny read module.

Introduction

It can be difficult to configure MS Office and ABCpdf to convert Office documents as part of a Windows service. This is for the following reasons.

  • Windows services do not, by default, have the permissions required to launch MS Office tasks.
  • The Windows service and any MS Office task need to run as the same user so that they can communicate correctly.
  • Microsoft Office is primarily designed to run as an interactive application.
  • Services run in Session 0 on later versions of Windows and the fact that Session 0 prohibits user interaction makes it difficult to troubleshoot configuration issues.

Further, please be aware that there are risks running MS office server side, so please read "Considerations for Server-side Automation of Office".

Please ensure that your use of MS Office is in compliance with the MS Office license agreement.

Essentials

Please ensure your server software is up-to-date and a recent version of the .NET Framework installed. We normally test with .NET 4.0.

Make sure you are using a recent version of Microsoft Office. We test ABCpdf.NET with Microsoft Office 2010, the current version. This is our preferred version as we find it easiest to support. Versions prior to Office 2007 may work but are unsupported.

Make sure your MS Office installation is fully complete and activated. Attempting to automate MS Office with a partial installation may cause the MS Office setup executable to launch and block the automation. Open some documents manually to check that Office is working correctly.

You may wish to disable any Microsoft Office start up utilities to ensure that Office processes are shut down after use rather than kept alive in the background. This may be important if you're going to be changing the user at a later stage.

Build and run the doc2pdf project. If it fails then this would imply a generic configuration issue - please re-check your installation of Microsoft Office, let us know if you can't see a cause. If it succeeds (as invariably it will) it will imply a permissions issue under ASP.NET.

Deployment Scenarios

The following guide covers deployment under three different scenarios:

ASP.NET under IIS7 or later

For IIS7 or later, e.g. IIS7 on Win2008 or Vista, you can just set the identity of the application pool to a user that has certain permissions (as explained below), and optionally load the user profile.

There is no need to use a COM+ solution as required for pre IIS7 machines. Using a COM+ solution will not hurt but you must ensure that the COM+ identity and the application pool identity are the same.

Further, please note that in Windows 2008 and later the user profile is no longer loaded for COM+ applications. This means that even if you do use COM+, you will still need to set the application identity in the application pool and load the user profile. Otherwise strange things might happen when the user is not logged on, depending on whether there is a service running as the same user or not. Services do have the user profile loaded.

Follow these steps to validate Office Automation on your machine:

  1. Download and unzip the following file: ImportDoc.zip

    This file contains a simple website that converts uploaded files either via Microsoft Office or OpenOffice.org. This latter is an extra feature and you can ignore it. You don't have to use this example, by all means use your own website directly.

  2. Install the website in IIS Manager. Use a dedicated application pool and make sure all of the ABCpdf binaries are in the required locations. See ABCpdf Installation below for further details. You may need to copy ABCpdf.dll into the bin folder.
  3. Create a dedicated account for running Office Automation, for example call it OfficeAutomationUser. Assign it a password that never expires.
  4. Add this account to the IIS groups: IIS_IUSRS or IIS_WPG if they exists (basically the IIS group where you find Network Service, which is the default application pool identity).
  5. Log in using this account and open at least one Office document of the type that you intend to convert. Make sure that when opening such a document there are no pop-ups. This means making sure that Office has been activated and all the initial questions Office asks have been answered, e.g. if you are running it with a trial key, etc.
  6. Logging in using this account is also necessary to initialize the XPS print driver, otherwise you might get INVALID_PRINTER_NAME (1801) errors.
  7. Give this account (or better the IIS group that it belongs to) access permissions to the following folders, as indicated on the right. For 64-bit machines:

    C:\Windows\Temp - Modify
    C:\Windows\syswow64\config - Read
    C:\Windows\syswow64\config\systemprofile - Read
    C:\Windows\syswow64\config\systemprofile\AppData - Modify
    C:\Windows\syswow64\config\systemprofile\Desktop - Modify (Create it if it does not exist)

    For 32-bit machines:

    C:\Windows\Temp - Modify
    C:\Windows\system32\config - Read
    C:\Windows\system32\config\systemprofile - Read
    C:\Windows\system32\config\systemprofile\AppData - Modify
    C:\Windows\system32\config\systemprofile\Desktop - Modify (Create it if it does not exist)

    You can assign folder permissions by browsing to such folders in Windows Explorer and adding the user in the Security tab of the folder Properties dialog.

  8. Give this account (or better the IIS group it belongs to) COM launch and activation permissions. In Component Services (dcomcnfg.exe) go to computers and right click on MyComputer. Launch the properties dialog and go to the COM Security tab. Click on "Edit Default" under "Access Permissions". Add your user and give it full access. Repeat for "Launch and Activation Permissions".
  9. Set the identity of the application pool to OfficeAutomationUser. Also load the user profile by setting LoadUserProfile to true. You can do so in the application pool advanced settings:

    IIS Advanced Settings Identity
  10. You should be done. Check that it works.
  11. You can also try to set LoadUserProfile to false, but if you do so then you should do the following: http://support.microsoft.com/kb/184291/EN-US/. This explains how to add the XPS print driver to the default user.
  12. You may also want to use Network Service instead of a dedicated user. This might also work provided it has the required permissions (points 7 and 8) and provided you load the user profile (if you have not added the XPS print driver to the default user as explained above).

ASP.NET before IIS7

For IIS versions before IIS7, e.g. IIS5.5 or IIS6 on Windows XP or 2003, we were not able to import Microsoft Office files directly from the ASP.NET process. We therefore propose a solution based on COM+ EnterpriseServices. We will therefore rely on a ServicedComponent for performing Office Automation (a COM+ wrapper basically).

Follow these steps for validating Office Automation on your machine:

  1. Download and unzip the following MSOfficeExampleSite.zip

    This file contains an MS Visual Studio solution with two projects:

    • PdfEnterpriseServices, the ABCpdf COM+ wrapper.
    • WebUtilities, a simple website that uses PdfEnterpriseServices to convert a Word document into PDF. The PDF will be displayed directly in the browser.
  2. Launch WebUtilities.sln and build it.
  3. Install the website in IIS Manager, the website folder is ExampleSite\WebUtilities.
  4. Create a dedicated account for running Office Automation, for example call it OfficeAutomationUser.
  5. Assign a password that never expires to this account and give this account Administrator rights.
  6. Log in using this account and open at least one Office document of the type that you intend to convert. In this example we will convert a .docx document. Make sure that when opening such a document there are no pop-ups. This means making sure that Office has been activated and all the initial questions Office asks have been answered, e.g. if you are running it with a trial key, etc.
  7. Logging in using this account is also necessary to initialize the XPS print driver, otherwise you might get INVALID_PRINTER_NAME (1801) errors.
  8. From an MS Visual Studio command prompt register PdfEnterpriseServices:

      RegSvcs PdfEnterpriseServices.dll

    On x64 Windows, RegSvcs.exe in %SystemRoot%\Microsoft.NET\Framework\v2.0.50727 is 32-bit and the one in %SystemRoot%\Microsoft.NET\Framework64\v2.0.50727 is 64-bit. The version of RegSvcs.exe determines whether the COM+ Application it registers will run in a 32-bit or 64-bit process. The 32-bit or 64-bit MS Visual Studio command prompt chooses the corresponding framework directory as one of the search paths. You should use the one that matches ABCpdf you plan to use.

  9. Set the identity of PdfEnterpriseServices to OfficeAutomationUser. You can do so from Component Services, by running DCOMCNFG: right-click on the COM+ component, select properties and go to the Identity tab. You can also set the identity to the interactive user to start with but you will have to change it later on unless someone will always be logged in.
  10. Browse to default.aspx of the example website. If successful a PDF document containing the word "TEST" will be displayed by the browser.

Windows Services

Follow these steps to validate Office Automation in a Windows service. We will rely on a COM+ application for performing Office Automation. On recent Windows versions such as Win 2008 and Vista the COM+ application is probably not necessary but we recommend you start with COM+ at first.

  1. Unzip the following MSOfficeService.zip

    This file contains a MS Visual Studio 2005 solution with two projects:

    • PdfEnterpriseServices, the ABCpdf COM+ wrapper
    • TestService, a Windows test service that uses PdfEnterpriseServices to convert a Word document into PDF.
  2. Create a folder that is publicly accessible, e.g. C:\services.
  3. After building the solution (you may need to change the reference to ABCpdf in PdfEnterpriseServices), copy the content of both projects' bin\Debug folders - or bin\Release if building in release- to C:\services. Also copy any other DLLs that your projects refer to and that are not in the GAC (for .NET) or in %SystemRoot%\system32 (for native DLLs).
  4. Copy the Documents folder that you find in the zip file to C:\Services.
  5. Create a dedicated account for running Office Automation, for example call it OfficeAutomationUser.
  6. Assign a password that never expires to this account and give this account Administrator rights.
  7. Log in using this account and open at least one Office document of the type that you intend to convert. In this example we will convert a .docx document. Make sure that when opening such a document there are no pop-ups. This means making sure that Office has been activated and all the initial questions Office asks have been answered, e.g. if you are running it with a trial key, etc.
  8. Logging in using this account is also necessary to initialize the XPS print driver, otherwise you might get INVALID_PRINTER_NAME (1801) errors.
  9. From a MS Visual Studio command prompt, in C:\services, register PdfEnterprises:

      RegSvcs PdfEnterprises.dll

    On x64 Windows, RegSvcs.exe in %SystemRoot%\Microsoft.NET\Framework\v2.0.50727 is 32-bit and the one in %SystemRoot%\Microsoft.NET\Framework64\v2.0.50727 is 64-bit. The version of RegSvcs.exe determines whether the COM+ Application it registers will run in a 32-bit or 64-bit process. The 32-bit or 64-bit MS Visual Studio command prompt chooses the corresponding framework directory as one of the search paths. You should use the one that matches ABCpdf you plan to use.

  10. Set the identity of PdfEnterprises to the OfficeAutomationUser account. You can do so from Component Services (run DCOMCNFG in Vista or go to the Control Panel / Administrative Tools in XP) . Right-click on the COM+ component, select properties and go to the Identity tab.
  11. On Windows 2008 and other Windows versions it's also necessary to set the log-on identity of the service to the same user. This is because COM+ applications no longer have the user profile loaded.
  12. Install the service in the usual way, e.g. using

    installutil -i TestService.exe

We tested the service with log-on as "Network Service" or "Local Service" and both scenarios worked. "Local Account" should also work.

You should be done. Launch services from the Control Panel / Administrative Tools. The service should appear as ABCpdf test service with log-on set to Network Service and Startup Type manual. Start the service. After the service has started a file called input.pdf should appear in C:\Services\Documents. Any log messages go to C:\Services\abcpdf7.txt.

Additional Information on Configuring Office

This is not normally necessary unless the default settings have been changed.

We want the Office Application to launch as the "Launching User" when it is activated via DCOM.

  1. Launch DCOMCNFG.

    Note that there are both x86 and x64 versions of DCOMCNFG. By default on x64 versions of Windows the x64 version is launched. To launch the x86 version you will need to perform the following command line operation:

    C:\WINDOWS\SysWOW64> mmc comexp.msc /32

  2. Go to Computers > MyComputer > DCOM Config.
  3. Right-click the application that you want to automate. The application names are listed below:

    Application
    MS Access 97
    MS Access 2000/2002/2003
    MS Office Access 2007
    MS Excel 97/2000/2002/2003
    MS Office Excel 2007
    MS Office Excel 2010
    MS Word 97
    MS Word 2000/2002/2003
    MS Office Word 2007
    MS Office Word 2010

    DCOM Name
    Microsoft Access Database
    Microsoft Access Application
    Microsoft Office Access Application
    Microsoft Excel Application
    Microsoft Excel Application
    Microsoft Excel Application
    Microsoft Word Basic
    Microsoft Word Document
    Microsoft Office Word 97 - 2003 Document
    Microsoft Word 97 - 2003 Document

    On some systems Microsoft Word is not displayed and you will have to use {00020906-0000-0000-C000-000000000046} instead.

    Click Properties to open the property dialog box for this application.

  4. Click the Identity tab. Verify that The Launching User is selected.

Lowering Admin Rights

We ask that the COM+ account has Administrator rights because it requires permissions that the standard Users group does not normally have. However you can remove your Office Automation user from the Administrators group as long as you give it the following permissions:

  • It must have access to the following system folders, as indicated on the right. For 64-bit machines:

    C:\Windows\Temp - Modify
    C:\Windows\syswow64\config - Read
    C:\Windows\syswow64\config\systemprofile - Read
    C:\Windows\syswow64\config\systemprofile\AppData - Modify
    C:\Windows\syswow64\config\systemprofile\Desktop - Modify (Create it if it does not exist)

    For 32-bit machines:

    C:\Windows\Temp - Modify
    C:\Windows\system32\config - Read
    C:\Windows\system32\config\systemprofile - Read
    C:\Windows\system32\config\systemprofile\AppData - Modify
    C:\Windows\system32\config\systemprofile\Desktop - Modify (Create it if it does not exist)

    You can assign folder permissions by browsing to such folders in Windows explorer and adding the user in the Security tab of the folder Properties dialog.

  • It must have COM launch and activation permissions. In Component Services (dcomcnfg.exe) go to computers and right click on MyComputer. Launch the properties dialog and go to the COM Security tab. Click on "Edit Default" under "Access Permissions". Add your user and give it full access. Repeat for "Launch and Activation Permissions".

Important Notes for Windows 2008 / Windows 7

  1. Make sure there is a folder called "Desktop" in C:\Windows\SysWOW64\config\systemprofile for Windows 2008 Server x64 or C:\Windows\config\systemprofile for Windows 2008 Server x86. Create the folder if it does not exist.
  2. For further information: AnswerExcel 2007 automation on top of a Windows Server 2008 x64.
  3. Some people have reported that it was necessary to install the MS Office SP2 on Windows Server 2008 R2 or else MS Word would crash. To install the SP2: http://support.microsoft.com/kb/953195.
  4. Some people have reported it is necessary to set the Microsoft XPS Document Writer as the default printer.
  5. Some people have reported that it is necessary to disable UAC (User Access Control).

Registry Entries

If you are still having problems you may try the following to troubleshoot:

  1. Add a DWORD registry entry called PrintHookLog to HKLM\Software\WebSupergoo\ABCpdfNET\7 and set it to one.
  2. On 64-bit machine also add it to HKLM\Software\Wow6432Node\WebSupergoo\ABCpdfNET\7.
  3. Monitor your Windows temp directory, normally C:\Windows\Temp for files called spy_xxxx.log where xxxx is a PID. See if you can work out any possible problem by looking at the content of these files, this is normally a popup that is blocking the Office application, or send them over to us for further analysis.
  4. Remember to delete these registry entries or to set them to zero to avoid clogging your temp area with the spy log files.

ABCpdf Installation

If installing ABCpdf manually make sure that:

  • ABCpdf.dll is in the GAC (gacutil -i ABCpdf.dll) or in the same directory as the service executable.
  • The ABCpdf core engine (ABCpdf9-32.dll or ABCpdf9-64.dll) is in %SystemRoot%\system32.
  • PrintHook32.dll is in %SystemRoot%\system32 for 32-bit machines. For 64-bit machines PrintHook32.dll and PrintHook64.dll should both be in %SystemRoot%\system32 and PrintHook32.dll should also be in %SystemRoot%\SysWOW64.