HTMLPrint DLL controller

Along with the DLL files, two projects are included as examples, one for calling the DLL from Visual C++ and other from Delphi.

The projects are for Visual C++ 6 and Delphi 3 to give programmers the options to open them with older versions of both compilers, but they can easily been opened by any newer version.

 

These projects are not complex, but are intended for programmers with at least minimum experience.

 

All the same options that HTMLPrints reads from the .ini file can be set using the DLL. If any options is not specified, the same default values than HTMLPrint used when no .ini file is available will be applied.

Also, if the wait option is set to 1, the DLL will wait for HTMLPrint run termination after calling it, giving back an error number. If wait is 0, far less feedback (less errors are trapped) will be provided.

 

Note: Calling a DLL from a service can be difficult. We don't grant that these DLLs will work when called from Windows services.

 

Functions:

C

Pascal (Delphi)

  • int start(char*, char*, char*, int);

  • void options(char orientation, char * printer, char * printerpapersize, char * printerbin, int defprinter, int pnmatch, int copies, int printimages, int tableback, int mono, int manually, int printfilename, int nopath, int down, int tm, int kdelay, int delay, int hfspace, int duplex);

  • void margins(double left, double top, double right, double bottom, int mm, int bodymw, int bodymh)';

  • void footer_header(char * header, char * footer, int nhfp, int nffp);

  • void dir_list(int rfl, int concatenate, int joint, int autopdir, int runinv, char * list, char * dirhtml, char *dirimages);

  • void image_metafile(int pn, int jpgq, int width, int height_scale, int metaw, int apppath, int  split, int autoscale, char * imdir, char * metadir);

  • void defaultfont(char * name, int size);   

  • int load_template(char * fname);

  • Function start(exe, p1, p3: pchar; wait: integer): integer;

  • procedure options(orientation: char; printer, psize, psource: pchar; defprinter, pnmatch, copies, printimages, tableback, mono, manually, pfile, nopath, down, tm, kdelay,delay: integer; hfspace: double; duplex: integer) ;

  • procedure margins(left, top,right,bottom: extended; mm, bodymw, bodymh: integer)';

  • procedure footer_header(h,f: pchar; nhfp,nffp: integer);

  • procedure dir_list(rfl,concatenate,joint,autopdir,runinv: integer; list, dirhtml,dirimages: pchar);

  • procedure image_metafile(pn, jpgq, width, height ,metaw, apppath, split, autoscale: integer; imdir, metadir: pchar);

  • procedure defaultfont(name: pchar; size: integer);

  • function load_template(fname: pchar): integer;

Download both DLL and Visual C++ 6 example Project at:

http://bersoft.com/htmlprint/visual.zip

Download both DLL and Delphi 3 example Project at:

http://bersoft.com/htmlprint/delphi.zip

 

Notes:

True=1; False=0; Undefined=-1.

Any null pointer, or integer with a -1 value parameter will be left undefined. All undefined parameters will be not modified from either the default ones or the settings loaded from a .ini file using load_template.

Related options are grouped together. Enter all variable  names in lowercase (in Delphi it doesn't matter).

The C and Delphi DLL files are different, although they have the same file name, do not interchange them.

Functions

Parameters

start. The error numbers list below show the values that are returned by start.

This is the only mandatory function, all other ones are optional.

exe;

HTMLPrint file name.

p1;

Parameter one, pointing to HTML or image file to be printed.

p3

Parameter three, indicating page range. Can be left blank to print all pages.

wait

If wait is True the DLL will wait for HTMLPrint run termination after calling it, giving back an error number. If wait is not True less only errors 2, 3 and 4 may be returned.

options

orientation

 

printer

pnmatch

defprinter

 

Each printer can be identified with its name or a number between 0 and the number of installed printers -1. So if there are 4 printers the printer number may be 0, 1, 2 or 3.
If printer is nul,  the default printer will be used, if not the value  will be used to set the default printer. Printer can be set by number or name or partial name.
To see the printer names and values in your system, start HTMLPrint and scroll down to the bottom of the help page, there you will see the list of printers in your system along with their numerical values.

If defprinter is ON, no matter which printer is selected by printer, the default system printer will be used.

If pnmatch is True any partial printer name matching will select the first printer in the printer list that matches with printer, otherwise, printer has to be exactly equal to the printer name to be selected.

printerpapersize
printerbin

Both PrinterBin and PrinterPaperSize can be set by specifying a part of the full name.
Example: Setting the paper size to ‘A4' is the same than ‘A4 210 x 297’).
If the text appears in more than 1 printer, the first printer with the matching subtext will be selected.

copies

Sets how many copies are printed.

printimages

If False, images will not be printed.

tableback

If False, table background colors will not be printed.

mono

If True, monochrome printers will always print black.

manually

If True HTMLPrint will show a Setup Printer Dialog and will start visibly.

printFileName

This option may be useful when using printer drivers that generate files instead actually printing. If False the file will be named accordingly to the document title, otherwise it will have the same filename than the document, but with different file extension.

nopath

This option is handy if all the images are in the same directory than the HTML file, but the images references point to another paths. When nopath=True the images paths will be ignored.

down, tm

Only if Down  is True online images will be printed.

tm  (timeout) indicates the number of milliseconds that the connection should wait for the image become readable.
Images are downloaded synchronously, therefore a high timeout value (if the Internet connection is slow or is not working) will delay the printing work.

kdelay, delay

Delay between printing files:

kdelay can be 0 (None), 1 (Max. num. sp. jobs) or 2 (Milliseconds):

  • None: there will be no delay between printing different files.

  • Max. number of spooler jobs: The next file in the list of files to be printed or in the directory, will be printed only after the number of printing jobs in Windows spooler is equal or less than the value assigned to Delay.

  • Milliseconds: The next file will be printed only after the specified lapse of milliseconds passed since the previous job was sent to the printer or, when printing files one at a time (passing the file name in the command line), the delay value will be the time that the printing job will wait before being sent to the printer.

Therefore, according to the type of delay specified, the value assigned to Delay will indicate either the number of jobs in Windows spooler or milliseconds.

Delay can have any value between 0 and 99999.

hfspace

HFSpace sets the separation between the header/footer and the page text. It is measured in pixels.

duplex

0 = Use printer settings

1 = Simplex

2 = LongEdge

3 = ShortEdge

margins

left, top, right, bottom,
mm

The Bottom margin cannot be set in the TRIAL version.

If mm is True LEFT, TOP, RIGHT and BOTTOM margins must be set in millimeters, without fractions, otherwise the may be set in decimal inches.

To set the margins in millimeters select Set margin in millimeters, otherwise select Set margin in inches; depending on the selected option USE_MILLIMETERS  will be ON or OFF.

marginwidth, marginheight

marginwidth  and marginheight are Screen margins and are expressed in pixels.
The Screen margins define how the document look on the screen, but nevertheless they will be added to printing margins at printing time. Previous versions of HTMLPrint used by default 10 for marginwidth and 0 for marginheight.

Although Screen margin are specified in pixels, they will be recalculated to the printer resolution. Therefore the 10 pixels margin on the screen (at 96 DPI) will be scaled to 62 pixels on a 600 DPI printer.

footer_header

header, footer,

nhfp, nffp

If nhfp or nffp are True, the first page footer or header will not be printed at all. Notice that the TRIAL version always prints all footers, including the first one.

Use header and footer to specify the HTML content to be printed.

dir_list

rfl,

list

If rfl (ReadFromList) is True, HTMLPrint  will print all pages listed in the List file, instead printing the filename passed as a parameter. Nevertheless a filename always must be passed as a first argument, no matter if it is not going to be printed, otherwise HTMLPrint will start as a visible program.
List
value should be an ASCII file with a list of HTML pages or images.
Write just one filename in each line of the file list and save the file as text only.
If
dirhtml or dirimages are True the files will be loaded always from the directory, not from the list.

concatenate, joint

This two options only work with HTMLPrint 5, since the new list format in v6 precludes them.

Concatenate and Joint only work when printing files from a List file.

If Concatenate is True and several pages are included in the list all pages will be concatenated into a single file before printing, separated by <PAGE> tags.
The non-standard tag: <PAGE> causes printing to end on the current page and a new page is started. It has no effect on the displayed document. Of course also the Page-break property can be set in the CSS to do the same thing.

If both Concatenate and Joint are True the pages will be separated by <P> tags, without any page break between different documents. If Concatenate is False, Joint will have no effect at all.

When HTML documents are concatenated all them will share the same title and filename than the first page list document, and  only the options set in the document <HEAD> section will take effect.
If the concatenated pages are located in different directories and have relative links to images, some images will not be printed as expected, since all links will be relative to the first page list document placement.

Warning: Do not concatenate more pages that the amount your system can handle!

autopdir, runinv

dirhtml, dirimages

If the directory specified in dirhtml or dirimages exists, HTMLPrint will print all the HTML or image files in that directory instead the file passed as first parameter. 
DirectoryHTML
allows printing all files with .HTM or .HTML file extension in the specified directory. 
DirectoryIMAGES
allows printing all files with .BMP, .PNG, .JPEG, .JPG or .GIF file extension in the specified directory.
In both cases subdirectories are not scanned.
This options
override ReadFromList, so if DirectoryHTML or DirectoryIMAGES are True, ReadFromList will be always False.
If both
DirectoryHTML and DirectoryImages are specified, the HTML files will be printed before the images.
If any HTML files inside the specified
DirectoryHTML are also used as headers or footers of other pages, they will not be printed. 
Autopdir
and RunInv are only taken in account if DirectoryHTML or DirectoryImages is specified. If Autopdir is True, the program will keep running and printing any incoming files in the specified directory.
In such way you can simply drop a copy of any files you want to be printed to the specified directory in order to print them.

The HTML files will be automatically erased after they are sent to the printing queue.
HTMLPrint doesn't check if the printing work was done or if the printer is actually connected.

Only HTML files will be erased, not any related images.
When autopdir is True HTMLPrint will run in visible mode to allow stopping the program, unless RunInv  is True.
If Autopdir and RunInv  are True the program will keep running in directory printing mode until Windows shuts-down.

Note: HTMLPrint will run invisibly only when both RunInv is True and you start HTMLPrint with at least one parameter in the command line.

When printing files in a directory, you even can pass a nonexistent file as parameter, because the program will just print the files placed in the designated directory instead that file.

image_metafile

Note: Metafiles only will be saved correctly under Windows 2000/XP/2003/Vista or newer.

pn

If pn=0, the HTML Document will print normally, if =1 Bitmaps will be generated, if =2, JPEGs will be saved and if =3 metafiles will be generated.

If used for margins set pn to 0;

imdir,

width, height_scale,

split,

autoscale,

jpgq

 

When printing images you'll get your printout as a collection of BMPs or JPEGs files that you can view, store, modify, and print with other applications, without producing piles of scribbling-paper.

A directory with the same name than the file being printed will created inside the imdir, there images will be generated for each document page and named image_1, image_2 and so on. The file extension will be wither .BMP or .JPG, depending on your selection.

If imdir doesn't exists it will be created, but if it is not specified, HTMLPRINT directory will be used instead.

If a subdirectory with the name of the file being printed already exists, a number will be appended to the directory name to avoid overwriting the files in the existing directory.

Width sets the width to which the HTML is to be formatted.  Text would typically wrap at this width; if the document contents can't be successfully wrapped to the specified width, it will be increased automatically.

If split is True Height_scale sets the images splitting height, with a limit of 4000 pixels.

Depending on the HTML Document height, several images may be generated, or one single image will be enough. Different from metafiles generation, the images do not correspond to printing pages in the HTML document, but the document is split based only the height_scale value.

If split is False Height_scale sets the scale (in percent). If after scaling the document, it still doesn't fit in 4000 pixels the image will include only the first part of the document.

On the contrary, if autoscale is True the scaling will be automatically adjusted, so the documents will be reduced as needed to fit them in 4000 pixels.

Jpgq sets the level of the JPEG compression, and so the quality of the generated images.

It is not possible to create images with more than 4000 pixels of height.

metaw, metadir

Metaw sets the metafiles width in pixels.

When printing metafiles you'll get your printout as a collection of metafiles that you can view, store, modify, and print with other applications, without producing piles of scribbling-paper. After creating the metafiles you can use HTMLPrint or any application supporting them to view the metafiles.

A directory with the same name than the file being printed will created inside the metadir, there metafiles will be generated for each document page and named page_1.wmf, page_2.wmf and so on.

If metadir doesn't exists it will be created, but if it is not specified, HTMLPRINT directory will be used instead.

If a subdirectory with the name of the file being printed already exists, a number will be appended to the directory name to avoid overwriting the files in the existing directory.

apppath

If apppath is True, the file name original path will be appended to the directory where the images or metafiles are saved.

Example: if the file is  c:\myfiles\dir1\retro.htm, the directory to be created will be named cmyfilesdir1retro.htm

defaultfont

name, size

Font size must be set in points without fractions. If the HTML page has any tag specifying font formatting, it will invalidate the .ini file font settings.

load_template

fname

fname indicates .ini file where the settings are already saved.

After loading the settings from a configuration file, if you want to modify only a few of them, pass null pchar's or -1 integer values as parameters to left the corresponding options unmodified.

Always include file full path.