print dialog in web application

240 views
Skip to first unread message

Sadanand

unread,
Jun 9, 2011, 7:06:02 AM6/9/11
to Cappuccino & Objective-J
hi all,
how can I show a print dialog where it list out all connected active
printers ?
Is there any class in cappuccino which give me an option to code for
it?

Thanks & Regards,
Sadanand

Aparajita Fishman

unread,
Jun 9, 2011, 12:26:22 PM6/9/11
to objec...@googlegroups.com
> how can I show a print dialog where it list out all connected active
> printers ?
> Is there any class in cappuccino which give me an option to code for
> it?

Remember, Objective-J is an extension of Javascript. You have access to all native Javascript functionality.

So to answer your question, the only thing you have available is:

window.print();

Many thanks,

Aparajita
www.aparajitaworld.com

"If you dare to fail, you are bound to succeed."
- Sri Chinmoy | www.srichinmoy.org

Sadanand

unread,
Jun 10, 2011, 1:26:46 AM6/10/11
to Cappuccino & Objective-J
Hi Aparajita,
can you please tell me what java script can be used just to get all
printer names in a string array?
I just want to display what are the printers connected to my system.

Thank you very much for your quick response .

Thanks & Regards,
Sadanand.

On Jun 9, 9:26 pm, Aparajita Fishman <aparaj...@aparajitaworld.com>
wrote:

Aparajita Fishman

unread,
Jun 10, 2011, 1:32:49 AM6/10/11
to objec...@googlegroups.com
> can you please tell me what java script can be used just to get all
> printer names in a string array?

What I was trying to say is that you can't do it. All you can do is show the print dialog by using window.print().

Jon

unread,
Jun 10, 2011, 8:34:43 AM6/10/11
to Cappuccino & Objective-J
Like Aparajita said all you can do is call window.print(). The best
way we found of dealing with printing is to create a new window with
the content you want, with window.print() in the script tags so as
soon as you show it it prints.

Here is a snippet of code you may find useful:

//Put this as "close" to the triggering of the button or even which
causes the print dialog to be shown. We create the window here as
safaris popup blocker blocks those that it thinks arent triggered by
some user input.
window.win = null; //This resets the window if it was already set,
if this isnt done the print window will only open once
window.win = window.open("#", "printwindow",
"menubar=no,location=no,resizable=yes,status=no,centerscreen=yes,width=1545,height=1100");
window.win.document.title = "Report";

//Put this when you want to display the window. In my case this is in
a delegate method from a cpurlconnection (hence the need for the above
hack)
if (window.win)
{
var reportURL = baseURL + reportViewURL + "/" +
data["print_id"];
window.win.location = reportURL; //could also do
window.win.document.write("Some html");


} //Otherwise window couldnt be set for some reason, most
likely a popup blocker.

Jon

On Jun 10, 6:32 am, Aparajita Fishman <aparaj...@aparajitaworld.com>
wrote:

Jon

unread,
Jun 10, 2011, 8:39:44 AM6/10/11
to Cappuccino & Objective-J
Forgot to add, the document being printed should be something like
this:

<html lang="en-GB">
<head>
...
<script type="text/javascript">
function Print(){document.body.offsetHeight;window.print()};
</script>
</head>
<body onload="Print()"> <-- this ensures that print is called once
the whole document has been loaded
</body>
</html>

On Jun 10, 1:34 pm, Jon <jonathan.r.h.ev...@gmail.com> wrote:
> Like Aparajita said all you can do is call window.print(). The best
> way we found of dealing with printing is to create a new window with
> the content you want, with window.print() in the script tags so as
> soon as you show it it prints.
>
> Here is a snippet of code you may find useful:
>
> //Put this as "close" to the triggering of the button or even which
> causes the print dialog to be shown. We create the window here as
> safaris popup blocker blocks those that it thinks arent triggered by
> some user input.
>     window.win = null; //This resets the window if it was already set,
> if this isnt done the print window will only open once
>     window.win = window.open("#", "printwindow",
> "menubar=no,location=no,resizable=yes,status=no,centerscreen=yes,width=1545 ,height=1100");

Maz

unread,
Jun 10, 2011, 11:25:20 AM6/10/11
to Cappuccino & Objective-J
You can also use a hidden iframe, put content in there, and then print
that.
See http://http://maz.github.com/OpenBear/ for an example of that.

Sadanand

unread,
Jun 13, 2011, 12:53:14 AM6/13/11
to Cappuccino & Objective-J
Thanks to all .

On Jun 10, 8:25 pm, Maz <ma.maz...@gmail.com> wrote:
> You can also use a hidden iframe, put content in there, and then print
> that.
> Seehttp://http://maz.github.com/OpenBear/for an example of that.
Reply all
Reply to author
Forward
0 new messages