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 Image to XPS Converter Command Line from C#, ASP, etc. web program languages

 
1. How to call Image to XPS Command Line (img2xps.exe) from C#, ASP, PHP, etc. web program languages?
A:

Sample code #1 (C# example),

Make use of the PROCESS class available in SYSTEM.DIOGNOSTICS namaspace, use the following piece of code to execute the img2xps.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:\\img2xps.exe"
;
               
string strArguments = "";
                strArguments += " D:\\temp\\sample.tif D:\\temp\\out.xps";

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

Sample code #2 (C# example),

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

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

/exeshell.html
/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:\img2xps.exe ""C:\test.tif"" ""C:\out.xps""" });
                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,

/images/err1314-1.png
/images/err1314-2.png

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

/exeshell.html

Sample code #3 (ASP example),

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

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

/exeshell.html
/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 & "img2xps\img2xps.exe"
    InFile = RootPath & "test.tif"
    OutFile = RootPath & "out.xps"
    strCommandLine = EXEFile & " " & InFile & " " & OutFile
    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.

Sample code #4 (VB.NET example),

System.Diagnostics.Process.Start("C:\img2xps.exe C:\test.tif C:\out.xps")

Sample code #5 (C# example),

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

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

/exeshell.html
/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:\img2xps.exe ""C:\test.tif"" ""C:\out.xps""");
                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.

Sample code #6 (PHP example),

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

Sample code #7 (VBScript example),

Set fso = CreateObject("Scripting.FileSystemObject")
strFolder = fso.GetParentFolderName(wscript.ScriptFullName)

strEXEFile = strFolder & "\img2xps.exe"
strInFile = strFolder & "\test.tif"
strOutFile = strFolder & "\test.xps"
strCmd = strEXEFile & " " & strInFile & " " & strOutFile

Dim objShell
Set objShell = CreateObject("WScript.Shell")
objShell.Run strCmd

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

Please by following solution to run Image to XPS conversion inside an interactive user account,

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

2. Download CmdAsUser.exe from following page,

/exeshell.html

You can also download it from following URL directly,

/download/cmdasuser.zip

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

C:\img2xps\CmdAsUser.exe Administrator . /p password C:\img2xps\img2xps.exe C:\img2xps\test.tif C:\img2xps\out.xps

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 img2xps.exe from an interactive user account with administrator privilege.

 

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