The script should be placed in a page where you want to print from. If it is a checkout page - it should be there, and some "Print order" button should activate it:
<input type="button" value="print order" onclick="writeCheckout()">
The script should be in the <head> of this page. The "new" page (i.e. popup window) with all it's data will be created automatically.
This script should contain the code for cookie processing, looking like smth like this (without "data" parameter, it will be done internally):
function writeCheckout() {
// [ code for cookie processing ]
// let's assume that all data will be stored in a variable that you will print then:
var data = xxx; // something taken from the cookie
a = window.open("","","width=200,height=200,toolbar=no,...."

a.document.open();
a.document.write("<html><head></head><body onload='print()'>"

;
a.document.write(data);
a.document.write("</body></html>"

;
a.document.close();
}
I think this is the most simple way I could explain this.