project pages:  
PHPCoreStdfuncs PDOAccess CoreTable CoreGroup CoreForm CustomPrint
PHPCoreStdfuncs PDOAccess CoreTable CoreGroup
Personal Projects:
MyQuotes - Ihr persönlicher Aktienrechner
 

CustomPrint - A Firefox extension for WebDeveloppers who like to print HMTL

This addon is useful if you ou have a WebApplication that should somehow print a report, a bill or whatever.

Problem

If you just do
self.print();
or
parent.frames['print_content'].print();

to Print the page itself or the content a frame / Iframe, you will always have the Problem that you cant control the users Printer settings. You can't define the page orientation, neighter borders, you cant even disable the url printed on the paper.

Solution

This extentions helps you to do such things

It works quite easy. Once the Extension is installed and active Web Developpers have access to a global JS-object called customPrintService. If you know FireBug's console Object: Its quite the same mechanism. So your Website JavaScript is able to call:

var printerSettings = {"print_orientation": 1};
customPrintService.printFrame("print_content", printerSettings);

Explanations

Note the key "print_orientation" : It is the key in the Preferences-Branche of the selected Printer that about:config shows!

All Keys that about:config has in the Printersection are available. Be sure to set the proper type! the type in your settings Array must be the same as in the about:config.

To set the Printer use the special key "printerName".

Download

CustomPrint (0.8.4)

If you are like to see the sourcecode just rename the file .xpi to a .zip and extract it. It's GPL 3 licenced.

Older Version

CustomPrint (0.8.3)

CustomPrint (0.8.2)

The Version 0.8.2 supports also full document printing and works also under Linux.
Thanks for these enhancements and for reviewing to Lukasz Dargiewicz.

CustomPrint (0.8.1)

Demo

Click on a button to print the Content of the Iframe or the whole Document eighter in Portrait Orientation or in Landscape Orientation.

Orientation Portrait Orientation Landscape
The whole page
The Iframe below

NOTE: Of Course in productional environment you would hide the iframe by "style='visibility:hidden'"

Code Snippets of this demo

Javascript

Placed e.g. in a script Tag in the Header

function printFrame(orientation) {
        if (typeof(customPrintService) == "undefined") {
                alert("You need to install the Extension to run the demo.");
        }
        else {
                var printOptions = {"print_footerleft":"", "print_footercenter":"", "print_footerright":"", "print_headerleft":"",  "print_headercenter":"",  "print_headerright":""};
                printOptions["print_orientation"] = orientation;

                customPrintService.printFrame("print_content", printOptions);
        }
}

function printPage(orientation) {
        if (typeof(customPrintService) == "undefined") {
                alert("You need to install the Extension to run the demo.");
        }
        else {
                var printOptions = {"print_footerleft":"", "print_footercenter":"", "print_footerright":"", "print_headerleft":"",  "print_headercenter":"",  "print_headerright":""};
                printOptions["print_orientation"] = orientation;

                customPrintService.printDocument(printOptions);
        }
}

HTML

Placed in the body of your Website

<p>
<button onclick="printFrame(0)">Orientation Portrait</button>
<button onclick="printFrame(1)">Orientation Landscape</button>
</p>
<iframe src="demo_page.html" name="print_content"></iframe>