next up previous contents
Next: Properties Up: FFish Script Objects Reference Previous: close   Contents

Printer

Description
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

  1. Lists all printers in system
    for (i = 0; i < Printer.printers.length; i++)
    {
        trace(Printer.printers[i]);
    }
    
  2. Sets the title of the document to print
    Printer.title = "my doc";
    
  3. Selects a printer to use
    Printer.printerIndex = 0;
    

  4. Does print or print preview
    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();
    }
    

  5. Handles the onPreparePrinting event
    In the onPreparePrinting event handler, you should set the total count of pages you want to print. You can also change the printer used to print or set the title of the document in it. If you don't want to launch a print dialog, set the silent property to true. Remember to use the "this" pointer to access the properties or methods of the Printer object. For the "this" pointer contains the printer context used to differentiate between printing and print preview.
    Printer.onPreparePrinting = function ()
    {
        this.pageCount = 3;
        this.silent = true;
    }
    

  6. Handles the onBeginPrinting event
    In the onBeginPrinting event handler, you can set several properties of the printer such as orientation, paper size or copies of the document to print. The properties may have been set in the print dialog before this event after the onPreparePrinting event, but you still can change them in this event handler.
    Printer.onBeginPrinting = function ()
    {
        this.orientation = true;
        this.paperSize = 1;
        this.copies = 3;
    }
    

  7. Handles the onNewPage event
    The onNewPage will be fired before rendering a new page. In this event you can abort printing by set the continuePrinting property to false;
    Printer.onNewPage = function (page)
    {
        if (page >= 2)
        {
            this.continuePrinting = false;
        }
    }
    

  8. Handles the onPrint event
    This event handler is used to render the page. The Printer provides properties and methods to draw text, images, lines, etc.
    The following code shows how to print the screen.

    //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.

    .
    Draw text.
    You must set the font, bkColor, textColor, bkMode properties before drawing text. If the bkMode is set to opaque, the character cells will be filled with the bkColor. Otherwise the background will remain untouched.

    .
    Draw lines.
    You must set the pen property before drawing a line.

    .
    Draw shapes.
    You must set the pen and the brush properties before drawing a shape. The pen is used to draw the frame of the shape, the brush is used to fill the shape. If you only want to draw the frame of the shape, set brush to hollow.




Subsections
next up previous contents
Next: Properties Up: FFish Script Objects Reference Previous: close   Contents
Copyright ©2000-2010 Shanghai TopCMM Software Technologies. All Rights Reserved.