Metafile,EMF,WMF,RTF,Rich Text Format To PDF Converter Command Line  Home  HTML-Converter  Command-Line  Document  FAQ

Call VeryPDF HTML Converter Command Line from C#, ASP, etc. web program languages

1. How to call HTML Converter Command Line (htmltools.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 htmltools.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:\\htmltools.exe"
;
               
string strArguments = "";
                strArguments += "-width 612 -height 792 -emfheight 792 -nocenter"
;
                strArguments += " D:\\temp\\sample.html 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 htmltools.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:\htmltools.exe ""Http://www.verypdf.com"" ""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 htmltools.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 & "htmltools\htmltools.exe"
    HTMLFile = "http://www.google.com"
    PDFFile = RootPath & "google.pdf"
    strCommandLine = EXEFile & " " & HTMLFile & " " & 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:\htmltools.exe C:\test.html C:\out.pdf")

Example #5 (C# example),

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

Example #7 (Java example),

String line = "";
Runtime runtime = Runtime.getRuntime();

Process process = runtime.exec("cmd.exe /c c:\\htmltools\\htmltools.exe -width 1280 -height 800 -nocenter -bwidth 1280 -bheight 800 -margin 10x10x10x10 c:\\Projects\\ProductBuilder_PickList\\PickList.html c:\\temp\\PickList.pdf");

//Flush our buffer so the process can finish.
BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
while ((line = input.readLine()) != null)
{
    // Don’t need to do anything here unless you want to see the output.
    // System.out.println(line);
}
process.waitFor();

Example #8 (Java example),

cmd =
"C:\\htmltools.exe http://www.verypdf.com C:\\out.pdf"
pb = new ProcessBuilder(cmd);
pb.redirectErrorStream(true);
process = pb.start();
// have to handle to process output
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
    // this can be logged
    System.out.println(line);
}
w = process.waitFor();
// only proceed if 0

Example #9 (Java example),

import java.io.*;
import java.util.*;
public class test {
    /**
    * @param args
    */
    public static void main(String[] args)
    {
        // TODO Auto-generated method stub
        try
        {
            String ss="<html><head><title>test1</title></head><body>test Shajin</body></html>";
            BufferedWriter out = new BufferedWriter(new FileWriter("C:\\htmlfile\\test2.htm"));
            out.write(ss);
            out.close();
            Runtime rt=Runtime.getRuntime();
            String url="htmltools.exe"+" C:\\htmlfile\\test2.htm"+" test13.pdf";
            Process pp=rt.exec(url);
            System.out.println(url);
            int exitval=pp.exitValue();
            System.out.println("process val-->"+exitval);
        }
        catch(Exception e)
        {}
    }
}

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

Please by following solution to run HTML to PDF conversion inside an interactive user account,

1. Please add "Everyone" user account to the folder of htmltools.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:\htmltools\CmdAsUser.exe Administrator . /p password /c C:\htmltools\htmltools.exe http://www.google.com C:\htmltools\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 htmltools.exe from an interactive user account with administrator privilege.

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 #11 (Run conversion inside an interactive user account via docPrint Service),

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,

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

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:\VeryPDF\htmltools.exe" C:\test.htm C:\out.pdf
docPrint_client.exe wait "C:\VeryPDF\htmltools.exe" C:\test.htm 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 runexe : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Process proc = new Process();
        proc.StartInfo.FileName = "C:\\VeryPDF\\docPrint_client.exe";
        string strArguments = "wait C:\\VeryPDF\\htmltools.exe C:\\test.htm 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.
 

See Also:

Metafile/RTF/Image To PDF Command Line
Convert Windows Metafile (EMF, WMF), RTF and Image formats to Vector and Raster PDF files directly, it doesn't depend on Printer Drivers.


Document Converter Professional (docPrint Pro)
docPrint Document Converter Professional is a software product that dynamically converts MS Office 97/2000/XP/2003, WordPerfect, HTML, AutoCAD DWG, PostScript, EPS, PDF, MS Visio and many other document types to PDF, PostScript, EPS, JPEG, TIFF, PNG, PCX and BMP etc formats. It works in both GUI version and Command Line version. With docPrint Document Converter Professional you can convert your documents from and to PDF, EPS, PS, JPEG, TIFF, BMP, PCX, PNG files easily. (See user manual)

DocConverter COM Component (+HTML2PDF.exe)
Convert HTML, DOC, RTF, XLS, PPT, TXT etc. files to PDF files, it is depend on PDFcamp Printer product.

Tip: How to convert a HTML file or Web Pages to PDF file via Command Line?

If you encounter any problems, please feel free to contact us at support@verypdf.com.

Contact:
    support@verypdf.com
    /


VeryPDF.com | VeryDOC.com | VeryPCL.com | Links | Contact

Copyright © 2002- VeryPDF.com, Inc. All rights reserved.
Send comments about this site to the webmaster.