Partners Contact US Site Map Blog
A professional PDF Converter, PDF Writer, PDF Creator, PDF Editor, HTML Converter, Postscript Converter, AutoCAD DWG Converter, as well as PCL Converter, etc.  

Call DOC to Any Converter Command Line from C#, ASP, PHP etc. web program languages

 
1. How to call DOC to Any Command Line (doc2any.exe) from C#, ASP, PHP, etc. web program languages?
A:

Example #1 (C# example),

Make use of the PROCESS class available in SYSTEM.DIOGNOSTICS namaspace, use the following piece of code to execute the doc2any.exe file,
~~~~~~~~~~~~~~~~~
using System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Diagnostics
;

namespace
ConsoleApplication1
{

    class
Program
    {
       
static void Main(string[] args)
        {
                Process proc = new Process
();
                proc.StartInfo.FileName = @"C:\\doc2any.exe"
;
               
string strArguments = "";
                strArguments += " D:\\temp\\sample.doc D:\\temp\\out.pdf";

                Console.WriteLine(strArguments
);
                proc.StartInfo.Arguments = @strArguments
;
                proc.Start
();
                proc.WaitForExit
();
        }
    }
}
~~~~~~~~~~~~~~~~~

Example #2 (C# example),

Please by following steps to call doc2any.exe inside a special user account,

1. Please download and install EXEShell COM Library (freeware) from following URL first,

http://www.verydoc.com/exeshell.html
http://www.verydoc.com/download/exeshell.zip

2. Please use following C# code to run the conversion inside a special user account,

~~~~~~~~~~~~~~~~~
using System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;

namespace
ConsoleApplication1
{
    class
Program
    {
       
static void Main(string[] args)
        {
                System.Type otype = System.Type.GetTypeFromProgID("exeshell.shell");
                Object o = System.Activator.CreateInstance(otype);
                otype.InvokeMember("RunCommandLine", System.Reflection.BindingFlags.InvokeMethod, null, o,
                       
new object[] { "UserName", "Password", @"C:\doc2any.exe ""C:\test.doc"" ""C:\out.pdf""" });
                otype = null;
        }
    }
}
~~~~~~~~~~~~~~~~~

Remark:
You may encounter Error 1314 in some Windows systems when you switch between user accounts, this is caused by permission setting, please by following steps to solve this 1314 Error,

ERROR 1314:
~~~~~~~~~~~~~
1314 A required privilege is not held by the client. ERROR_PRIVILEGE_NOT_HELD
~~~~~~~~~~~~~

To resolve this issue:
1. Click Start, click Run, type "secpol.msc", and then press ENTER.
2. Double-click "Local Policies".
3. Double-click "User Rights Assignment".
4. Double-click "Replace a process level token".
5. Click "Add", and then double-click the "Everyone" group
6. Click "OK".
7. You may have to logout or even reboot to have this change take effect.

Please refer to following two screenshots to understand above steps,

http://www.verydoc.com/images/err1314-1.png
http://www.verydoc.com/images/err1314-2.png

Please look at following page for the details about ERROR 1314,

http://www.verydoc.com/exeshell.html

Example #3 (ASP example),

Please by following steps to call doc2any.exe inside a special user account,

1. Please download and install EXEShell COM Library (freeware) from following URL first,

http://www.verydoc.com/exeshell.html
http://www.verydoc.com/download/exeshell.zip

2. Please use following ASP code to run the conversion inside a special user account,

~~~~~~~~~~~~~~~~~
<%
    Set comEXEShell = Server.CreateObject("exeshell.shell")
    RootPath = Server.MapPath(".") & "\"
    EXEFile = RootPath & "doc2any\doc2any.exe"
    DOCFile = RootPath & "test.doc"
    PDFFile = RootPath & "out.pdf"
    strCommandLine = EXEFile & " " & DOCFile & " " & PDFFile
    response.write strCommandLine & "<br>"
    comEXEShell.RunCommandLine "UserName", "Password", strCommandLine
    Set comEXEShell = Nothing
%>
~~~~~~~~~~~~~~~~~

Remark:
You may encounter Error 1314 in some Windows systems when you switch between user accounts, this is caused by permission setting, please refer to the steps in #2 to solve the 1314 Error.

Example #4 (VB.NET example),

System.Diagnostics.Process.Start("C:\doc2any.exe C:\test.doc C:\out.pdf")

Example #5 (C# example),

Please by following steps to call doc2any.exe inside a special user account,

1. Please download and install EXEShell COM Library (freeware) from following URL first,

http://www.verydoc.com/exeshell.html
http://www.verydoc.com/download/exeshell.zip

2. Please use following C# code to run the conversion inside a special user account,

~~~~~~~~~~~~~~~~~
using System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
EXESHELLLib;

namespace ConsoleApplication1
{

    class
Program
    {
       
static void Main(string[] args)
        {
                EXESHELLLib.shell EXEShell = new EXESHELLLib.shellClass
();
                EXEShell.RunCommandLine("
UserName", "Password", @"C:\doc2any.exe ""C:\test.doc"" ""C:\out.pdf""");
                EXEShell = null
;
        }
    }
}
~~~~~~~~~~~~~~~~~

Remark:
You may encounter Error 1314 in some Windows systems when you switch between user accounts, this is caused by permission setting, please refer to the steps in #2 to solve the 1314 Error.

Example #6 (PHP example),

<?php
    $exeshell =new COM("exeshell.shell") or die("Can't start exeshell");
    $exeshell->
RunCommandLine("UserName", "Password", ' "C:\doc2any.exe" "C:\test.doc" "C:\out.pdf" ');
    $exeshell = null;
?>

Example #7 (Run conversion via "docPrint_Service.exe" application),

docPrint Service can be used to run a Command Line from current active user account or a special user account, this tool is useful to overcome permission restrictions in SYSTEM and Non-Interactive user accounts.

Please by following steps to use docPrint Service,

1. Download docPrint_Service.zip and unzip it to a folder,

2. Run docPrint_Service.exe application, you will see an icon appear in tray area,

3. You can run following command lines to test it first, "docPrint_client.exe" will deliver the Command Line to docPrint_Service.exe application, docPrint_Service.exe application will execute the Command Line from active user account automatically,

docPrint_client.exe nowait "C:\VeryDOC\doc2any.exe" C:\test.doc C:\out.pdf
docPrint_client.exe wait "C:\VeryDOC\doc2any.exe" C:\test.doc C:\out.pdf

4. You can call "docPrint_client.exe" from your code, please refer to a simple C# code at below,

public partial class rundoc2any: System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Process proc = new Process();
        proc.StartInfo.FileName = "C:\\VeryDOC\\docPrint_client.exe";
        string strArguments = "wait C:\\VeryDOC\\doc2any.exe C:\\test.doc C:\\test.pdf";
        Console.WriteLine(strArguments);
        proc.StartInfo.Arguments = @strArguments;
        proc.Start();
        proc.WaitForExit();
        Response.Write("File has been successfully converted");
    }
}

5. Close Remote Desktop and leave this user logged in.

*Please Notice: After you reboot the server, you need login your server via Remote Desktop with this user account ("doc2pdf_service.exe" was installed inside this user account), and close Remote Desktop, leave this user logged in, when you call docPrint_client.exe application, the conversion will be executed from this user account automatically.

Example #8 (Run conversion inside an interactive user account from service or web applications),

Please by following solution to run doc2any.exe inside an interactive user account,

1. Please add "Everyone" user account to the folder of doc2any.exe, give "Full Control" permission to "Everyone" user account,

2. Download CmdAsUser.exe from following page,

http://www.verydoc.com/exeshell.html

You can also download it from following URL directly,

http://www.verydoc.com/download/cmdasuser.zip

3. Run following command line to test CmdAsUser.exe application,

C:\doc2any\CmdAsUser.exe Administrator . /p password C:\doc2any\doc2any.exe C:\test.doc C:\out.pdf

If you can run above command line in Command Line Window correctly, please call above command line from PHP by shell_exec() function or other web applications, then you will get it work properly.

Please notice, you need modify "Administrator" and "password" parameters in above command line, CmdAsUser.exe will launch doc2any.exe from an interactive user account with administrator privilege.

Example #9 (Convert a MS Word document into PDF from ASP and ASP.NET),

Step 1:
Configure MS Word like recommended below: (Click image to see big screenshot)



1. type dcomcnfg in the command prompt and press Enter;
2. find and select Microsoft Word Document in the Applications list, then press the Properties button;
Note: If you have Windows 2003\2008 then type dcomcnfg in the command prompt, expand the Component Services group, expand the Computers group, expand the My Computer group, expand the DCOM Config group, find and select the Microsoft Word Document -> right mouse click -> Properties.
3. click the Identity tab. Check the "This user" checkbox, press Browse and specify the Administrator account;
4. enter and re-enter the Administrator password;
5. click the Security tab. Check the "Use custom access permissions" checkbox, press Edit and add the ASPNET, IUSR_ and IWAM_ user accounts (it is good if you can add EVERYONE user account);
Note: If you have Windows 2003\2008 also add the "NETWORK SERVICE" user account;
6. check the "Use custom launch permissions" checkbox, press Edit and add the ASPNET, IUSR_ and IWAM_ user accounts (it is good if you can add EVERYONE user account);
Note: If you have Windows 2003\2008 also add the "NETWORK SERVICE" user account;
7. reboot the computer;

See Also:
HOWTO: Configure Office Applications to Run Under the Interactive User Account.
HOWTO: Configure Microsoft Word and Excel to run under Interactive User's Account.

Step 2:
You can use following ASP code to call doc2any.exe to convert DOC file or DOCX file to PDF file,

ASP Source Code 1,
<%
    dim WSH,script
    script = "C:\wwwroot\doc2any.exe C:\wwwroot\test.doc C:\wwwroot\test.pdf"
    Set WSH=CreateObject("WScript.Shell")
    WSH.Run(script)
    set WSH =nothing
%>

ASP Source Code 2, (View more)
<%
    Set comEXEShell = Server.CreateObject("exeshell.shell")
    RootPath = Server.MapPath(".") & "\"
    EXEFile = RootPath & "doc2any\doc2any.exe"
    DOCFile = RootPath & "test.doc"
    PDFFile = RootPath & "out.pdf"
    strCommandLine = EXEFile & " " & DOCFile & " " & PDFFile
    response.write strCommandLine & "<br>"
    comEXEShell.RunCommandLine "UserName", "Password", strCommandLine
    Set comEXEShell = Nothing
%>

Note: You need give following permissions to C:\wwwroot folder,

Set "Scripts and Executables" option to your IIS folder,


Add IUSR_XXX and IWAM_XXX user accounts to your IIS folder, and give "Change" and "Read" permissions to these user accounts,



Example #10 (How to call doc2any.exe from a Windows Service?),

If you wish call doc2any.exe from a Windows Service, you need arrange this service run under an interactive user account (e.g., "Administrator" user account), please refer to following screenshot, (Click image to see big screenshot)

How to call doc2any.exe from a Windows Service?

Note: On 64bit Windows 2008 (R2) system, please create a new "Desktop" directory inside of "C:\Windows\SysWOW64\config\systemprofile\", creating this directory and rebooting server, then doc2any.exe works, this is a profile problem on Windows 2008 (R2) system.

On Windows 2008 Server x64, please make this folder.

C:\Windows\SysWOW64\config\systemprofile\Desktop

On Windows 2008 Server x86, please make this folder.

C:\Windows\System32\config\systemprofile\Desktop

This operation will take away office automation problems in Windows 2008 system, a Desktop folder is necessary in the "systemprofile" folder to open file by MS Office. This folder is disappear from Windows 2008 system, so you need create this folder by manual, Windows 2003 has the folder, so Windows 2003 hasn't this problem.

Example #11 (32-bit Automation Servers Not Found in DCOMCNFG.EXE in Windows 7 64-bit OS),

Problem:

When I first ran DCOMCNFG.EXE in my Windows 7 64-bit operating system, I could not find my 32-bit automation servers in the list as compared to when I did it in any 32-bit operating systems. The legacy application that was using the automation servers were running well so there must be no problem with the installation of the legacy application nor with the automation servers themselves.

Solution:

Run this from the command line: MMC comexp.msc /32

Thanks to this thread from the MSDN forum where I got the answer.

For more info, see: Running 32-Bit and 64-Bit Snap-ins on 64-Bit Windows Operating Systems

Known Issue:

After running it from the command line, I noticed that succeeding calls to DCOMCNFG.EXE would always show my 32-bit components. This must be what the Technet article meant by "bypassing the MMC decision-making process". This may not be an issue at all since you can switch back to the 64-bit version when you need to.

I found out that the way to see 32 bit legacy automation server applications in dcomcnfg is to use the following command line: "MMC comexp.msc /32". As long as you use this command line in a DOS window or using the Run command window, all the 32 bit automation server applications will be displayed, even when running on Windows 7 64 bit.

Example #12 (IIS 7 cannot access 32-bit COM dll through COM+ service),
View Solution

 
View more DOC to Any Converter FAQ
 
See Also:
Excel 2007 automation on top of a Windows Server 2008 x64
Considerations for server-side Automation of Office
Microsoft Support Page: HOWTO set up a user-defined service (Article ID: Q137890)
How To Create a Service under Windows
How To Create a User-Defined Service
 
See Also:
PDF to Image Converter :: PDF Extract TIFF :: HTML Converter :: PDFcamp Printer :: DocConverter COM :: PDF to Word Converter :: PDF to Text Converter :: Image to PDF Converter :: Image to PDF OCR :: PDF to HTML Converter :: AutoCAD DWG and DXF to PDF Converter :: PCL to PDF Converter :: Document Printer (docPrint) :: VeryPDF PDF Editor :: PDF Password Remover :: Encrypt PDF :: PDF Split-Merge :: PDF Stamper :: VeryPDF PDFPrint :: Advanced PDF Tools :: PDF Editor Toolkit :: Text to PDF Converter :: PowerPoint to Flash :: PowerPoint Converter

Home | Site Map | VeryPDF.com | VeryPCL.com | Contact | Blog
Copyright © 2002- VeryDOC.com Company. All Rights Reserved.