日曜日, 6月 21, 2009

javascript call print preview

javascript call print preview


<html>
<head>
<title>Print Preview</title>
<script>
function printpr()
{
var OLECMDID = 7;
/* OLECMDID values:
* 6 – print
* 7 – print preview
* 1 – open window
* 4 – Save As
*/

var PROMPT = 1; // 2 DONTPROMPTUSER
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);

WebBrowser1.ExecWB(OLECMDID, PROMPT);
WebBrowser1.outerHTML = "";
}
</script>
</head>
<body>
<form>
<input type='button' value="Print Preview" onclick="printpr();">
</form>
</body>
</html>



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Untitled</title>

<style type="text/css">

@page {
margin-left: 13cm;
}
</style>

</head>

<script language="javascript">

// ====================================================================
// Original post: Unkown person - I lost my notes on who did this first
// Unkown source
// Modified by: Walter Torres <walter@torres.ws> [www.torres.ws]
// 2001/04/29
// I found the secret to remove the prompt!
// Original post did not have this gem to it.
//
// This accesses a built-in Windows command that can perform Magic!
// And yes, this is a Windows ONLY solution.
// In fact, it only works in IE. :(
//
// This still doesn't work with Frames! :(
//
// INPUT: intOLEcmd = integer between 1 and 37, only a few are of use
// intOLEparam = parameter integer for function - optional
// OUTPUT: none
// DEPENDANCIES: none
//
// NOTE: intOLEparam is not optional in the Object call,
// I just made it optional here to make life easier.
// All command values use '1' execept print, thus my reasoning.
//
// EXAMPLE: // This prints given window/frame WITHOUT prompt!
// objWinName.ieExecWB(6, -1)
//
// // This prints given window/frame WITH prompt!
// objWinName.ieExecWB(6)

// // This will display the Print Preview window
// objWinName.ieExecWB(7)
//
// VALUES: intOLEcmd has these possible values
// OLECMDID_OPEN = 1
// OLECMDID_NEW = 2 warning, this kills IE windows!
// OLECMDID_SAVE = 3
// OLECMDID_SAVEAS = 4
// OLECMDID_SAVECOPYAS = 5 note: does nothing in IE
// OLECMDID_PRINT = 6 note: give '-1' as param - no prompt!
// OLECMDID_PRINTPREVIEW = 7
// OLECMDID_PAGESETUP = 8
// Others have no use in IE

function ieExecWB( intOLEcmd, intOLEparam )
{
// Create OLE Object
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';

// Place Object on page
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);

// if intOLEparam is not defined, set it
if ( ( ! intOLEparam ) || ( intOLEparam < -1 ) || ( intOLEparam > 1 ) )
intOLEparam = 1;

// Execute Object
WebBrowser1.ExecWB( intOLEcmd, intOLEparam );

// Destroy Object
WebBrowser1.outerHTML = "";
}

</script>

<script>

function saveAsMe (filename)
{
document.execCommand('SaveAs',null,filename)
}
</script>

<body>

This is so cool!!!!!!!!!!!!

<p>

<input type=button value="print preview" onclick="window.ieExecWB(7);">

<input type=button value="page setup" onclick="window.ieExecWB(8);">
<p>
<input type=button value="print page w Prompt" onclick="window.ieExecWB(6);">

<input type=button value="print page w/o Prompt"
onclick="window.ieExecWB(6, -1);">

<p>
<input type=button value="Save As" onclick="saveAsMe('ww.txt');">

<input type=button value="Save Copy" onclick="window.ieExecWB(5);">

</body>
</html>


Printing Templates Guide

using css to force Landscape Print in IE

0 件のコメント: