logo
  J2PrinterWebStart
logo

also see: [J2Printer ] [J2Printer14 ]


J2PrinterWebStart

J2PrinterWorks also supports the ability to print using Sun's Java Web Start deployment technology and the JNLP APIs.  The capability allows the creation of special Java Web Start applications which can be downloaded from a web site like an applet but are then retained on the client so that thereafter they can launch and run more like a standalone application.  Java Web Start applications are also not as restricted as applets and can do a number of things that untrusted applets cannot do, including read and write local files and print.  Typically, Java Web Start programs will ask the user the first time if it OK to print and whether it doesn't need to ask again, all without the need to "sign" the program code or deal with the Java Security Model.

J2PrinterWorks supports Java Web Start printing using a special subclass of J2Printer called J2PrinterWebStart.  The J2PrinterWebStart printing class is instantiated and used just like the J2Printer printing class.  In particular, it can print any Pageable, including all the J2PrinterWorks Pageable components.  For example:

    J2PrinterWebStart j2pws = new J2PrinterWebStart();
    J2TextPrinter j2tp = new J2TextPrinter(yourJTextPane);
    j2pws.print(j2tp);

J2PrinterWebStart can also bring up the Java Web Start page setup dialog and the J2PrinterWorks print preview dialog:

    j2pws.showPageSetupDialog();
    j2pws.showPrintPreviewDialog(new JFrame());

However, Java Web Start is not quite as general as regular Java "PrinterJob" printing, and as a consequence the J2PrinterWebStart printing class introduces a few restrictions when compared to the J2Printer printing class.  In particular, Java Web Start printing does not support the following capabilities:

Because of these limitations, the following methods inherited from the J2Printer base class have no effect for the J2PrinterWebStart subclass: In addition, cancelPrinting() has no effect if setSeparatePrintThread is false, but does work if setSeparatePrintThread is true, which is the default.

Another limitation of Java Web Start printing is that it is not possible to determine the unprintable margins for a given printer (see Java Bug Parade 4809667). Therefore, unlike the case for the J2Printer base class, the J2PrinterWebStart subclass methods setLeftMargin, setRightMargin, setTopMargin, and setBottomMargin do not protect you from setting margins smaller than the printable area of the page, so it is possible your content will be clipped off if you set your margins too small.  Therefore, we recommend setting ample margins, for example 0.5 inches on all sides, unless you are sure that all the printers on which your Java Web Start application will ever be run can print with smaller margins.

© Copyright 2009, Wildcrest Associates (http://www.wildcrest.com )