I found the script from jguru to call print preview from javascript.
I dont know whats the limitations, but its works perfectly as I expected.
Here is the script :
<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>
Thanks in advance Ravi Verelly for the script.
Note about Scripting Support for Web Page Printing from microsoft
WebBrowser is known to support OLECMDID_PRINT(6,1) and OLECMDID_PAGESETUP(8) printing related commands
The trick is to create a temporary WebBrowser object with DHTML and invoke ExecWB(6, 1) on it to print the page.
ExecWB(6, 1) could fail if a user selected the Cancel button on the print dialog
for detail article click :
http://msdn2.microsoft.com/en-us/library/ms976105.aspx
ak jalanin di PSP kok gak jalan ya..?
Well. I don’t think it works fine with IE 7.
Did you test?
src: http://support.microsoft.com/kb/251133/en-us/
Regards.
for Dhunk and Jack :
I’ll try with PSP using IE7 it work, but it has some limitations.
but I forgot whats the limitations.
Maybe You could find with some experiment and some tricky
Thank you for your website 😉
I made with photoshop backgrounds for myspace or youtube and whatever
my backgrounds:http://tinyurl.com/6rbxmr
have a good day and thank you again!
hi
Excellent Job done and Thank You For the code
Most Comprehensive code for printing and other tasks,but didn’t find the page setup one?
Can You help?
Thank you very much
Hope, any good thing will go to you.
a lot of thanks.
the “javascript call print preview” code is not working !!
Confirmed: doesn’t work with Firefox 3 / IE7
Indeed, it does not work.
Thanks mate… works with IE
for some reason when I copied the code from here it didn’t work ((
But when I modified it slightly it worked just fine. I am using IE7 and didn’t try it on anything else. I think the problem was with wrong quotes originally. Sorry, if this repeatation is inappropriate, but I thought it might help someone.
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 = ”;
document.body.insertAdjacentHTML(‘beforeEnd’, WebBrowser);
WebBrowser1.ExecWB(OLECMDID, PROMPT);
WebBrowser1.outerHTML = “”;
}
Oops, it didn’t work right the first time and there is no option to change what I posted. So here is another try
!
!
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 = ”;
document.body.insertAdjacentHTML(‘beforeEnd’, WebBrowser);
WebBrowser1.ExecWB(OLECMDID, PROMPT);
WebBrowser1.outerHTML = “”;
}
!
!
Hi,
Can you pls send me the full code as email so that it would be of great use!
Thanks
Well… seems I cannot post it right here. Tag signs are screwed up. You can delete these comments, there’s no use of them like this.
It works fine in IE .
if it is not working-mostly because your IE already disable ActiveXobject. Please enable it.
Firefox is not support for this code.
Firefox browser have its own print preview function -You can call the nsIWebBrowserPrint::PrintPreview() method.
Or simple way to do is using popup window to do the print preview job.more easier ~ ^_^
Thank you! that was a huge time saver.
aweeesome. thanks for that 🙂
Do anyone tried using [ nsIWebBrowserPrint::PrintPreview() ] command in Firefox !!! Am new to the scripting language. Any suggestions will be highly appreciated !!!
Thanks in Advance
Hi
The print preview works for me. Is there a way to close the print preview window with javascript?
Thanks!!
You may try VIEWidget from
http://hexatech.com/viewidget
It works with all major browers.
It is a javascript-programmable report & technical drawing generator and print preview control.
You may use VIEWidget to generate reports or technical drawings,
display the results in a scrolling and zooming viewer on your web page and then print it.
It is a very flexible and productive RAD tool as it lets you freely draw tables or
other objects at arbitrary x-y coordinates.
Below is a simple Hello World example with two print-preview pages generated:
//get length unit
var INCH = control1.getInch();
//create document
control1.startDoc();
control1.drawString(1*INCH, 1*INCH, “Hello World from Page 1”);
//…draw other stuff here
//create 2nd page
control1.newPage();
control1.drawString(1*INCH, 1*INCH, “Hello World from Page 2”);
//…draw other stuff here
//end document
control1.endDoc();
//preview first page (page index=0)
control1.setCurrentPage(0);
control1.preview();
its nice but i need my selected content only preview into preview window
It is not working !!!!!!!!!!!!!
Any suggestions about using nsIWebBrowserPrint::PrintPreview() method for Firefox?
Desperately in need of help with implementing the nsIWebBrowserPrint::PrintPreview(). Could anyone please advice?
Folks, I gathered so much of information about implementing this nsIWebBrowserPrint::PrintPreview() in firefox. mailto arun.karthic@yahoo.com for queries regarding this.
I was curious if you ever considered changing the structure
of your website? Its very well written; I love what youve got to
say. But maybe you could a little more in the way of content so people could connect with it better.
Youve got an awful lot of text for only having one or two images.
Maybe you could space it out better?
Hurrah, that’s what I was searching for, what a data! existing here at this blog, thanks admin of this site.
We stumbled over here from a different website and thought
I may as well check things out. I like what I see so i am just
following you. Look forward to going over your web page again.
not working!