[thelist] Automatic Print .PDF?
Greg Schnippel
gschnippel at forumone.com
Mon Oct 14 09:04:00 CDT 2002
> I was wondering if it's possible to code a page to automatically print a
> .pdf when the user tries to File/Print from the browser.
My understanding is that it can't be automatic as a security precaution,
otherwise malicious script writers could trick users into sending
reams of all-black pages to their printer ;)
Here's a script we use on some of our sites, I'm not sure where it
originated from so please don't ask me any questions about the
Visual Basic mess below :p Should be able to just paste this into
the head of your 'printable version' of the page and modify the
body object to call the function 'onLoad()' (see examples below).
This article might also be of help:
http://www.webreference.com/js/tips/991029.html
-schnippy
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
<script language="JavaScript">
<!--- HIDE FROM OLD BROWSERS
var bName = ( navigator.appName == "Microsoft Internet Explorer" ) ?
"Microsoft" : navigator.appName;
var bVers = parseInt ( navigator.appVersion, 10 );
var Ns3 = ( bName == "Netscape" && bVers == 3 ) ? true : false;
var Ns4 = ( bName == "Netscape" && bVers == 4 ) ? true : false;
var Ms4 = ( bName == "Microsoft" && bVers == 4 ) ? true : false;
var v4 = ( Ns4 || Ms4 );
// IE3 workaround vbscript objects
DA = (document.all) ? 1 : 0;
window.onerror=handle_error;
function handle_error ()
{
if ( v4 )
{
var message = "\nNothing was printed. \n\nTo cancel this print job,";
message += "click on the printer icon in the toolbar above.";
}
else
{
var message = "\nSorry! The 'window.print ()' function is not\n";
message += "supported on your browser. Please update.\n";
}
alert ( message );
return ( true );
}
function print_window ()
{
if ( v4 )
window.print ();
else
handle_error ();
}
//==========================================================================
===================
// END HIDING --->
</script>
<script LANGUAGE="VBScript">
<!--- HIDE FROM OLD BROWSERS
sub print
olecmd = 6 ' Print Command
oleparam = 1
on error resume next
WB.ExecWB olecmd, oleparam
if err.number <> 0 then
if DA then
' IE4 - User Cancelled
alert "Nothing was printed."
else
' IE3 - Other Instructions
handle_error
end if
end if
end sub
// END HIDING --->
</script>
</HEAD>
<body TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#000000" VLINK="#000000"
onLoad="print_window();">
<object ID="WB" WIDTH="0" HEIGHT="0"
CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">
</object>
More information about the thelist
mailing list