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

 
1. How to call HTMLPrint to Any Command Line (html2any.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 html2any.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:\\html2any.exe"
;
               
string strArguments = "";
                strArguments += " -printtopdf D:\\temp\\out.pdf http://www.verypdf.com";

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

Sample code #2 (C# example),

Please by following steps to call html2any.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:\html2any.exe -printtopdf D:\\temp\\out.pdf http://www.verypdf.com" });
                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 html2any.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 & "html2any.exe"
    strCommandLine = EXEFile & " -printtopdf D:\\temp\\out.pdf http://www.verypdf.com"
    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:\html2any.exe -printtopdf C:\\out.pdf http://verypdf.com")

Sample code #5 (C# example),

Please by following steps to call html2any.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:\html2any.exe -printtopdf D:\\temp\\out.pdf http://www.verypdf.com");
                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:\html2any.exe" -printtopdf "D:\\temp\\out.pdf" "http://www.verypdf.com" ');
    $exeshell = null;
?>

Sample code #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\html2any.exe" -printtopdf C:\out.pdf http://verypdf.com
docPrint_client.exe wait "C:\VeryDOC\html2any.exe" -printtopdf C:\out.pdf http://verypdf.com

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

public partial class VeryDOC: 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\\html2any.exe -printtopdf C:\\out.pdf http://verypdf.com";
        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.

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

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

1. Please add "Everyone" user account to the folder of html2any.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:\VeryDOC\CmdAsUser.exe Administrator . /p password C:\VeryDOC\html2any.exe -printtopdf C:\out.pdf http://verypdf.com

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

 
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.