cancel
Showing results for 
Search instead for 
Did you mean: 

Using a button to print an applet

Former Member
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

jcgood25
Active Contributor
0 Kudos

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

sufw
Active Participant
0 Kudos

Nice hack!

Former Member
0 Kudos

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?

jcgood25
Active Contributor
0 Kudos

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

Former Member
0 Kudos

The problem is when I have this utility file included in the script block, all of my javascript does not work, but if I include the function in the file, it works. I am guessing I have the file path incorrectly worded.

jcgood25
Active Contributor
0 Kudos

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

Former Member
0 Kudos

I've also seen sometimes the browser doesn't like the inline closing of a script tag.

Try this:


<script type="text/javascript" src="/YourCompany/Common/UtilFunctions.js"></script>

I've seen this also with the TEXTAREA tag.

I don't know if it is a browser thing or a DOCTYPE thing or what

Answers (1)

Answers (1)

Former Member
0 Kudos

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.