Problem printing images on Windows browsers
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Eric_Norum
Posted On:   Friday, February 1, 2002 09:29 AM

I've put together an applet which uses the VXI-11 remote procedure calls to get images from IEEE-488 test equipment connected to ethernet via a GPIB/LAN adapter. I'm using JDK-1.3.02. On all systems I've tried (Linux netscape 4 and netscape 6, and Mac OS X Internet Explorer 5.1, Windows Internet Explorer and Netscape 4) the applet can successfully get the image from the device and display it in the browser. When I try to print the image I have problems on windows with either browser. All the other systems seem to be able to print with no problems. I tried putting some diagnostic code in the print method and found that on Linux/Mac OS X the print method is invoked three times ea   More>>

I've put together an applet which uses the VXI-11 remote procedure calls
to get images from IEEE-488 test equipment connected to ethernet via a
GPIB/LAN adapter. I'm using JDK-1.3.02. On all systems I've tried
(Linux netscape 4 and netscape 6, and Mac OS X Internet Explorer 5.1,
Windows Internet Explorer and Netscape 4) the applet can successfully
get the image from the device and display it in the browser. When I try
to print the image I have problems on windows with either browser. All
the other systems seem to be able to print with no problems.


I tried putting some diagnostic code in the print method and found that
on Linux/Mac OS X the print method is invoked three times each time I
print an image. On Windows the print method is invoked only twice.
Is something broken in the PrinterJob class on windows or am I doing
something dumb?


Here's the object I put together to do the printing

			
class ImageIconPrinter implements Printable {
ImageIcon imageIcon;

public ImageIconPrinter(ImageIcon icon) {
imageIcon = icon;
}
public int print(Graphics g, PageFormat pf, int pi) {
if (pi >= 1) {
return Printable.NO_SUCH_PAGE;
}
Graphics2D g2 = (Graphics2D)g;
g2.translate(pf.getImageableX(), pf.getImageableY());
double xscale = pf.getImageableWidth() / imageIcon.getIconWidth();
double yscale = pf.getImageableHeight() / imageIcon.getIconHeight();
double s = (xscale < yscale) ? xscale : yscale;
if (s < 1.0)
g2.scale(s, s);
g2.scale(0.98, 0.98); /* Some browsers round/clip improperly */
g2.drawImage(imageIcon.getImage(), 0, 0, null);
return Printable.PAGE_EXISTS;
}
}


And here's the code I attached to my applet `print' button


			
Paper p = new Paper();
p.setImageableArea(1.0*72., 1.5*72.0, 6.5*72.0, 8.0*72.0);
PageFormat pf = new PageFormat();
pf.setPaper(p);
PrinterJob pj = PrinterJob.getPrinterJob();
Book book = new Book();
book.append(new ImageIconPrinter(
(ImageIcon)scopeImageLabel.getIcon()), pf);
pj.setPageable(book);
if (pj.printDialog()){
try {
pj.print();
} catch (PrinterException e) {
System.err.println("PrinterException: "+e);
}
}
   <<Less
About | Sitemap | Contact