on 05-18-2007 12:54 PM
This command does a print preview of an applet I want to print. What is the syntax to send this directly to the printer?
document.iGrid.doPrint();
I want to eliminate the right click printfeature and offer a quicker way to print.
Ryan is correct that you can't necessarily bypass the Windows printer dialog directly, but you can give it a little javascript nudge.
<b>STEP 1</b> - Create an irpt page and incorporate the concept from this stub, and as represented by the dummy path and page name in the next step, I would recommend putting it into a common folder for convenient reusability:
<body onLoad="window.print(); window.close();">
<img src="{Image}" width="{Width}" height="{Height}" border="0" alt=""/>
</body>
<b>STEP 2</b> - Add the following JavaScript function to your page (or include it in something like a /Root/Common/UtilFunctions.js file for reusability):
function UtilPrint(myApplet,iWidth,iHeight) {
var strImage = myApplet.saveImage();
var strURL = "/Root/Common/AppletPrintPage.irpt?Image=" + strImage + "&Width=" + iWidth + "&Height=" + iHeight;
var strOptions = "location=no," + "width=" + (iWidth + 20) + ",height=" + (iHeight + 30);
window.open(strURL,"PrintMe",strOptions);
}
<b>STEP 3</b> - On whatever page with an applet you want to print simply include the following html with the proper applet name and the same dimensions as the ones defined for the chart or grid:
<input type="button" id="btnPrintImage" value="Print" onClick="UtilPrint(document.APPLETNAME,640,480);"/>
<b>STEP 4</b> - Save all of the pieces and give the button a try.
The print dialog should be triggered when the page loads, but wait for the user to pick a printer or just press the OK or cancel button, followed by the popup irpt automatically closing.
Best Regards,
Jeremy Good
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your help. I have it working fine, but I would like to place the function in a js file for reusability.
<script type="text/javascript" src="../Script/UtilFunctions.js">
I have other functions within this irpt. Do I need to separate scripts or am I allowed to have custom functions and also refer to the UtilFunctions in the same irpt?
Technically the <SCRIPT/> block with the .js file is a separate script block that makes all of the functions in the file available to the page including them, so your irpt can have dedicated functions as well. Having page owned functionality on a page and including utility functions from an external file is the right combination for what you are doing.
Regards,
Jeremy
In your earlier post it didn't appear that you actually closed the js file script block like (notice the closing slash):
<script type="text/javascript" src="../Script/UtilFunctions.js"/>
<script type="text/javascript">
function PageSpecific1() {
.....
}
</script>
It should look like this and I would not use the ..slash in the path, instead use a full path like "/Root/Script/UtilFunctions.js" because this will always be there but if your current page moves it will not have the same path to the js file.
Regards,
Jeremy
This method calls the print function of the web browser. It's functionality of the web browser that is not exposed to scripting languages that specifies to show the print preview window or print direct.
There's no way around it, sorry.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
10 | |
5 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.