The Printer object provides methods to enumerate printers in system, print images or text on a printer. It also supports print preview. Not available for screen savers.
available: SWFKit Pro
How to use the Printer object
for (i = 0; i < Printer.printers.length; i++)
{
trace(Printer.printers[i]);
}
Printer.title = "my doc";
Printer.printerIndex = 0;
Printer.print(); //or Printer.printPreview();
During printing or print preview, 5 events will be fired. You can change the printer properties and define the print jobs in these event handlers. The event handlers are uniform for both printing and print preview, so you can get the same result in both printing and print preview.
The following pseudo code shows how will these event handlers be called.
function print_or_print_preview()
{
onPreparePrinting()
onBeginPrinting()
for (i = 0; i < pages; i++)
{
onNewPage(i);
onPrint(i);
}
onEndPrinting();
}
Printer.onPreparePrinting = function ()
{
this.pageCount = 3;
this.silent = true;
}
Printer.onBeginPrinting = function ()
{
this.orientation = true;
this.paperSize = 1;
this.copies = 3;
}
Printer.onNewPage = function (page)
{
if (page >= 2)
{
this.continuePrinting = false;
}
}
//capture screen
image = Image.captureScreen();
Printer.onPrint(page)
{
// only render the first page
if (page > 0) return;
// get the image size(not it's actual size,
//but its size should be on paper)
var size = this.getImageSize(image);
// put the image on the center of the paper
var width = this.pageWidth;
var height = this.pageHeight;
var left = (width - size.width) / 2;
var top = (height - size.height) / 2;
this.printImage(image, left, top,
size.width, size.height);
}
You can also draw text, lines or shapes on the paper.