• Post Reply Bookmark Topic Watch Topic
  • New Topic

print applet

 
pavan in
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to print applet using the printer. If yes, how?
I have a button on my applet. When the user clicks on that button, the applet should be printed. My applet is not signed.
Thanks
 
pavan in
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public void printPage() {
try{
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.pageDialog(printJob.defaultPage());
printJob.setPrintable(this, printJob.defaultPage());
if(printJob.printDialog()){
printJob.print();
}
return;
}
catch(PrinterException pe) {
EuamAppletLogger.error(pe, "Exception Caught");
}
}

/**
* Prints the page at the specified index into the specified Graphics context in the specified format.
*
* @param g
* @param pg
* @param page
*
* @return int
*/
public int print(Graphics g, PageFormat pg, int page) throws PrinterException {
Graphics2D g2 = (Graphics2D) g;
if (page >= 1)
return Printable.NO_SUCH_PAGE;
g2.translate(pg.getImageableX(), pg.getImageableY());
paint (g2);
System.gc();
return PAGE_EXISTS;
}
this code pops-up 'An applet would like to print. Do you want to continue?' but the browser just hungs there. I am not able to click on yes/no option. Any thought?
Thanks
 
Tim Holloway
Bartender
Posts: 18469
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two words:
Java Sandbox
 
pavan in
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So Tim, I can not print java applets on an browser? There must be some way we can print the applet.
Any utility which converts applet to html? basically, I have jtree in applet which is to be printed. Any suggestions on how to print the jtree?
 
Tim Holloway
Bartender
Posts: 18469
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no simple correspondence between an applet's contents and HTML so it can't be converted. An applet can be made to print, however - it's just that the applet has to be signed. This is a security precaution so that rogue applets that print obscene pictures on 3700 pages can't be let loose indiscriminantly on the Internet.
A common alternative is to send the data that you want back to the server that the applet loaded from and have a servlet or JSP construct a printable page either in HTML or PDF form. That page can then be printed via the browser File/Print menu command. This isn't quite as convenient as printing straight from the applet, but sometimes you can format better and there's no need to sign the applet.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!