Posted 02 November 2013 - 02:37 PM
Hello everybody,
I have written an API for easier printing when you have multiple printers in a network. It is not entirely done yet, but it should be useable.
It works by having one printer designated as the active printer, and it will forward all the print functions you call to this printer. The API supports all the functions of the native printer API. It is possible to manually or automatically select a printer as active printer. By default, it selects the printer that can print the most pages.
The API also allows the user to give labels to printers. This way, you can easily access printers, since you can give them a meaningful name.
The code can be found on pastebin: http://pastebin.com/Sg10An9P
The API selects a printer as active printer using the function comp. It takes two printers. It is possible to override this method if you want a different way to select printers. You can also set the active printer with setActivePrinter.
Labels are set using the setPrinterLabel, this function first takes the name of the printer in the network, followed by the label. The labels get stored in print.conf on your computer. If you want to change this, you can edit the variable config in the API.
Before you can use the API, you have to call the function init(). This function looks for printers in the network and makes sure one of them is designated as active printer. If you have used the API before, he will use the one you used last time. Otherwise, he will automatically select a printer among the network.
It is also possible to get a table with all the printers in the network, including the ink and paper levels. This can be done by using getPrinterTable for a table, and getPrinterTableString for a badly formatted string.
In combination with the standard printer API functions, a function called wrapWrite was added that prints the string it gets and makes sure it doesn't run of the page.
The API is not entirely done yet, I would like to add more comments in the code and do some minor improvements, but it should be useable. If you find any bugs or have any question on how to use it, please reply to this tread.
I have written an API for easier printing when you have multiple printers in a network. It is not entirely done yet, but it should be useable.
It works by having one printer designated as the active printer, and it will forward all the print functions you call to this printer. The API supports all the functions of the native printer API. It is possible to manually or automatically select a printer as active printer. By default, it selects the printer that can print the most pages.
The API also allows the user to give labels to printers. This way, you can easily access printers, since you can give them a meaningful name.
The code can be found on pastebin: http://pastebin.com/Sg10An9P
The API selects a printer as active printer using the function comp. It takes two printers. It is possible to override this method if you want a different way to select printers. You can also set the active printer with setActivePrinter.
Labels are set using the setPrinterLabel, this function first takes the name of the printer in the network, followed by the label. The labels get stored in print.conf on your computer. If you want to change this, you can edit the variable config in the API.
Before you can use the API, you have to call the function init(). This function looks for printers in the network and makes sure one of them is designated as active printer. If you have used the API before, he will use the one you used last time. Otherwise, he will automatically select a printer among the network.
It is also possible to get a table with all the printers in the network, including the ink and paper levels. This can be done by using getPrinterTable for a table, and getPrinterTableString for a badly formatted string.
In combination with the standard printer API functions, a function called wrapWrite was added that prints the string it gets and makes sure it doesn't run of the page.
The API is not entirely done yet, I would like to add more comments in the code and do some minor improvements, but it should be useable. If you find any bugs or have any question on how to use it, please reply to this tread.