There are a few ways of doing this but the best way I found was to use the push method of the _spBodyOnLoadFunctionNames array e.g.

function createprintpage(){
..
}
_spBodyOnLoadFunctionNames.push(“createprintpage”);

This array allows the addition of a function to the onload event without over-writing required functions by adding a javascript call directly to the master page body onload