easyPDF SDK Usermanual
PDF Creator Programming API  |  Download Free Trial  |  Contact Us to Purchase

HostArguments Property

Command-line arguments to be passed to a host application.

Only used when HostApplication is also specified.

string HostArguments { get; set; }

Property HostArguments As String

def getHostArguments(self)
def setHostArguments(self, value)
String getHostArguments() throws PrinterException
void setHostArguments(String value) throws PrinterException
function getHostArguments() 
function setHostArguments($value) 
BclPrnResult GetHostArguments(BclPrinter* pPrinter, wchar_t** poutVal);
BclPrnResult SetHostArguments(BclPrinter* pPrinter, const wchar_t* newVal);
Property HostArguments As String

bepprint +Generic -host <filename> -args <string>




When HostApplication is not specified or it is an empty string, printing occurs with ShellExecute via the "printto" or "print" verb. In other words, your document's file extension must be associated with a printing application in the Windows registry.

Sometimes this file association is a hassle. It is a complex chore that requires special attention. Besides, you might not want to reconfigure your entire system just for the sake of easyPDF.

Using the HostApplication and HostArguments properties together, you can circumvent file associations, and print directly via the host application of your choice.

All you need is an external application that is able to print a document via the command line. Ideally this host application should also take the name of the printer as a second command-line parameter.

The HostApplication property must contain the full path to the host executable. It must be a Windows exe. If your app is in Java, your executable is the Java runtime.

The HostArguments property must contain the command-line arguments to be passed to the host executable. This can be fully customized.

Note that these two properties must be used together. Using just one or the other will not function correctly.

If you prefer automatic file extension association, simply do not set HostApplication, or set it to an empty string. HostArguments is ignored when HostApplication is an empty string.

Macro Substitution

There are two special macros for HostArguments:

In addition, you may add your own command-line arguments and switches as necessary. For example, if you need a URL, user name, password, job ID, etc., you can pass all of those as needed.

Example Usage

Note that we do not recommend printing Word documents with GenericPrintJob. However, for the sake of an example, here is how to use GenericPrintJob to print with Microsoft Word.

WinWord.exe takes three command-line arguments. Start with the /j switch, followed by the input file name, and finally the name of the printer.

The macro %input% will be replaced by the input file name within double quotes. The macro %printer% will be replaced by the name of the easyPDF SDK printer inside double quotes.

In a real-world situation you should replace WinWord.exe with an application for your own custom document type. It may be either your own executable, or a 3rd party one.

Set oPrinter = CreateObject("easyPDF.Printer.8")
Set oPrintJob = oPrinter.GenericPrintJob
oPrintJob.HostApplication = "c:\Program Files\Microsoft Office\Office14\WINWORD.EXE"
oPrintJob.HostArguments = "/j %input% %printer%"
oPrintJob.PrintOut "C:\test\input.doc", "C:\test\output.pdf"

The way this works is that HostApplication and HostArguments are combined together to launch the external application. easyPDF itself does not perform any printing, the customer's HostApplication is fully responsible for printing. easyPDF simply launches the following shell command (the necessary double-quotes are automatically injected):

"c:\Program Files\Microsoft Office\Office14\WINWORD.EXE" /j "c:\test\input.doc" "easyPDF SDK 8"

Questions & Answers

Q: What if the application does not take a printer name parameter?
A: Then you should remove the %printer% from HostArguments. You are required to manually set "easyPDF SDK 8" as your default printer, and leave it permanently that way, before using GenericPrintJob. Note that changing the default printer is not thread-safe. By passing %printer% to the host, you have a chance of making the print process thread-safe, if the host application knows how to print to a specific printer, instead of the default one.

Q: What if the application does not take an input file name parameter?
A: If your application does not use an input file, then you should remove the %input% from HostArguments. However, your application won't know which file to print. Alternatively, your input file name may be a URL, database record, or any other identifier.

Q: What if my application has custom parameters, such as a URL, command-line switches, etc.?
A: Just pass them via the HostArguments parameter. Everything will be passed to your application via the command line.

Q: What if I want the old SDK 7.0 behavior of printing via file extension associations?
A: Do not use the HostApplication property, or set it to an empty string.