Printing HTML with Java Printing Service(JDK1.4 beta)

Hi there!
I'm currently checking out the new Java Printing Service (JPS) in the new JDK1.4 beta. This looks like a very promising printing API, with amongst others printer discovery and support for MIME types - but I have some problems with printing HTML displayed in a JEditorPane.
I'm developing an application that should let the user edit a (HTML)document displayed in a JEditorPane and the print this document to a printer. I have understood that this should be peace-of-cake using the JPS which has pre-defined HTML DocFlavor amongst others, in fact here is what Eric Armstrong says on Javaworld (http://www.javaworld.com/javaone01/j1-01-coolapis.html):
"With JPS, data formats are specified using MIME types, for example: image/jpeg, text/plain, and text/html. Even better, the API includes a formatting engine that understands HTML, and an engine that, given a document that implements the Printable or Pageable interface, generates PostScript. The HTML formatting engine looks particularly valuable given the prevalence of XML data storage. You only need to set up an XSLT (eXtensible Stylesheet Language Transformation) stylesheet, use it to convert the XML data to HTML, and send the result to the printer."
After one week of reasearch I have not been able to do what Armstrong describes; print a String that contains text of MIME type text/html.
I have checked the supported MIMI types of the Print Service returned by PrintServiceLookup.lookupDefaultPrintService(). This is the result:
DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(MediaSizeName.ISO_A4);
aset.add(new Copies(2));
PrintService[] service = PrintServiceLookup.lookupPrintServices(flavor,aset);
if (service.length > 0) {
System.out.println("Selected printer " + service[0].getName());
DocFlavor[] flavors = service[0].getSupportedDocFlavors();
for (int i = 0;i<flavors.length;i++) {
System.out.println("Flavor "+i+": "+flavors.toString());
Selected printer \\MUNIN-SERVER\HP LaserJet 2100 Series PCL 6
Flavor 0: image/gif; class="[B"
Flavor 1: image/gif; class="java.io.InputStream"
Flavor 2: image/gif; class="java.net.URL"
Flavor 3: image/jpeg; class="[B"
Flavor 4: image/jpeg; class="java.io.InputStream"
Flavor 5: image/jpeg; class="java.net.URL"
Flavor 6: image/png; class="[B"
Flavor 7: image/png; class="java.io.InputStream"
Flavor 8: image/png; class="java.net.URL"
Flavor 9: application/x-java-jvm-local-objectref; class="java.awt.print.Pageable"
Flavor 10: application/x-java-jvm-local-objectref; class="java.awt.print.Printable"
As you can see there is no support for text/html here.
If anyone has a clue to what I'm missing here or any other (elegant, simple) way to print the contents of a JEditorPane, please speak up!
Reply to: [email protected] or [email protected] or here in this forum

Since you have 'printable' as one of your flavors, try this using a JTextPane (assuming you can dump your HTML into a JTextPane, which shouldn't be a big problem)...
1. Have your JTextPane implement Printable
ie. something like this:
public class FormattedDocument extends JTextPane implements Printable 2. Read your HTML into the associated doc in the text pane.
3. Implement the printable interface, since you have it as one of your available flavors (I'd imagine everybody has printable in their available flavors). Something like this:
public int print(Graphics g, PageFormat pf, int pageIndex) {
        Graphics2D g2 = (Graphics2D) g;
        g2.translate((int)pf.getImageableX(), (int)pf.getImageableY());
        g2.setClip(0, 0, (int)pf.getImageableWidth(), (int)pf.getImageableHeight()); 
        if (pageIndex == 0)
            setupPrintView(pf);
        if (!pv.paintPage(g2, pageIndex))
            return NO_SUCH_PAGE;
        return PAGE_EXISTS;
    }Here's my setupPrintView function, which is executed once on page 0 (which still needs some polishing in case I want to start from page 5). It sets up a 'print view' class based on the root view of the document. PrintView class follows...
public void setupPrintView(PageFormat pf) {
View root = this.getUI().getRootView(this);
        pv = new PrintView(this.getStyledDocument().getDefaultRootElement(), root,
                           (int)pf.getImageableWidth(), (int)pf.getImageableHeight());Note of obvious: 'pv' is of type PrintView.
Here's my PrintView class that paints your text pane line by line, a page at a time, until there is no more.
class PrintView extends BoxView
    public PrintView(Element elem, View root, int w, int h) {
        super(elem, Y_AXIS);
        setParent(root);
        setSize(w, h);
        layout(w, h);
    public boolean paintPage(Graphics2D g2, int pageIndex) {
        int viewIndex = getTopOfViewIndex(pageIndex);
        if (viewIndex == -1) return false;
        int maxY = getHeight();
        Rectangle rc = new Rectangle();
        int fillCounter = 0;
        int Ytotal = 0;
        for (int k = viewIndex; k < getViewCount(); k++) {
            rc.x = 0;
            rc.y = Ytotal;
            rc.width = getSpan(X_AXIS, k);
            rc.height = getSpan(Y_AXIS, k);
            if (Ytotal + getSpan(Y_AXIS, k) > maxY) break;
            paintChild(g2, rc, k);
            Ytotal += getSpan(Y_AXIS, k);
        return true;
// find top of page for a given page number
    private int getTopOfViewIndex(int pageNumber) {
        int pageHeight = getHeight() * pageNumber;
        for (int k = 0; k < getViewCount(); k++)
            if (getOffset(Y_AXIS, k) >= pageHeight) return k;
        return -1;
}That's my 2 cents. Any questions?

Similar Messages

  • Problem with java print

    Hi, I'm have problems with java print (g2d). For example i want to print a String "ABC**************************DEF" on paper size 80mm width (invoice paper). I can print all that string with paper A4 size, but with paper size 80mm i have problem with that String, the result is "C*****************D" lost AB and EF. I think i had problem with paper size, pls help me. Thank you so much.
    My code is below:
    package app.util;
    To change this template, choose Tools | Templates
    and open the template in the editor.
    @author HUU NGHIA
    // Printing Sample code
    // This code demonstrates the Java 2 print mechanism
    import com.connection.Product;
    import java.awt.;
    import java.awt.print.;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.Vector;
    // Define a class that is called per page that needs printing. It implements
    // the one and only method in the Printable interface : print. Note that
    // this is quite separate from the PrinterJob class print() method.
    // This method does not actually do any printing. All it does is write text
    // and/or graphics onto the passed page (graphics context). The calling
    // printer job object will then pass this page to the printer.
    public class PrinterController {
    public static void print(Vector<Product> products) {
    // Create an object that will hold all print parameters, such as
    // page size, printer resolution. In addition, it manages the print
    // process (job).
    PrinterJob job = PrinterJob.getPrinterJob();
    // It is first called to tell it what object will print each page.
    job.setPrintable(new PrintObject(products));
    // Then it is called to display the standard print options dialog.
    if (job.printDialog()) {
    // If the user has pressed OK (printDialog returns true), then go
    // ahead with the printing. This is started by the simple call to
    // the job print() method. When it runs, it calls the page print
    // object for page index 0. Then page index 1, 2, and so on
    // until NO_SUCH_PAGE is returned.
    try {
    job.print();
    } catch (PrinterException e) {
    e.printStackTrace();
    class PrintObject implements Printable {
    Vector<Product> products;
    public PrintObject(Vector<Product> products) {
    this.products = products;
    public int print(Graphics g, PageFormat f, int pageIndex) {
    Graphics2D g2 = (Graphics2D) g; // Allow use of Java 2 graphics on
    // the print pages :
    System.out.println("f.getImageableX(): " f.getImageableX());
    // A simple circle to go on the second page (index = 1).
    switch (pageIndex) {
    case 0:
    printInvoiceTemplate(g2, products);
    return PAGE_EXISTS;
    // case 1 : g2.setColor(Color.red); // Page 2 : print a circle
    // g2.draw(circle);
    // return PAGE_EXISTS;
    default:
    return NO_SUCH_PAGE; // No other pages
    public String getDate(){
    Date d = new Date();
    SimpleDateFormat sp = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
    return sp.format(d);
    private void printInvoiceTemplate(Graphics2D g2, Vector<Product> products) {
    //System.out.println("#######" cardInfo.getTranType());
    int alignY = 40;
    int alignXCenter = 60;
    int enterSpace = 15;
    int xProductName = 10;
    int xUnit = 85;
    int xAmt = 110;
    int xTotal = 155;
    int yEndData = 0;
    int totalAll = 0;
    g2.setColor(Color.black); // Page 1 : print a rectangle
    g2.setFont(new Font("Verdana", 0, 8));
    g2.drawString("ABC", alignXCenter, alignY);
    g2.drawString("123WWW", alignXCenter, alignY enterSpace *1);
    g2.drawString("Phone: (08)62891633", alignXCenter, alignY enterSpace*2);
    g2.setFont(new Font("Verdana", 1, 12));
    g2.drawString("Invoice", alignXCenter - 10, alignY enterSpace*4);
    products = new Vector<Product>();
    for (int i = 0; i < 10; i+) {
    Product product = new Product();
    product.setProductName("ZESTORETIC TAB 20MG B/28" i);
    product.setUnit("v"+i);
    product.setAmt(5+i);
    product.setPrice(50000+i);
    products.add(product);
    for (int i = 0; i < products.size(); i+) {
    System.err.println(i);
    int total = products.get(i).getAmt()*products.get(i).getPrice();
    g2.drawString(i+1+"."products.get(i).getProductName(), xProductName+2, alignY enterSpace(8+(i*2)));
    g2.drawString(products.get(i).getUnit(), xUnit+5, alignY enterSpace*(9(i*2)));
    g2.drawString(products.get(i).getAmt()"x"+AppUtils.formatPrice(products.get(i).getPrice())"", xAmt+5, alignY enterSpace*(9(i*2)));
    g2.drawString(AppUtils.formatPrice(total), xTotal+15, alignY enterSpace*(9(i*2)));
    yEndData = 9+(i*2);
    totalAll = totalAll total;
    System.out.println(yEndData);
    g2.drawLine(xProductName, alignY enterSpace*(yEndData 1), 210, alignY enterSpace*(yEndData 1));
    g2.drawString(AppUtils.formatPrice(totalAll)" VND", xAmt, alignY enterSpace*(yEndData 2));
    g2.drawString("Thank you", alignXCenter, alignY enterSpace*(yEndData 4));
    g2.drawString("***", alignXCenter 30, alignY enterSpace*(yEndData + 5));
    public static void main(String[] args) {
    PrinterController.print(null);
    }

    When you posted you didn't use code tags, as a result the forum software has interpreted some of your characters in your program as screen formatting codes and has corrupted your post--the most easily observable change is the bolded characters in you post. Please repost your code using code tags so people will be helping with uncorrupted code.

  • HT4910 Print calendar with AirPrint printer?

    How can I print calendar with AirPrint printer?

    There is an App called CalPrint which can print calendar information.
    See: https://itunes.apple.com/us/app/calprint-for-iphone-calendar/id385149531?mt=8

  • Help with code to print HTML in Java 5

    Hi,
    The following code works and runs successfully..
    However, the printing in Java 1.4.2_03 is better than Java 5 (latest version).
    i.e in particular the characters are not monospaced compared with compiling with Java 1.4.2_03. e.g si so ss squashed together.
    This issue does not seem to occur when running the same code in Java 1.4.2_03. (I haven't tried other 1.4.2 java versions).
    Any help would be appreciated. We really need this working under Java 5 or bust.
    Here is the complete listing ... PrintHtml.java (it uses the DocumentRenderer)
    and following this is the input file.
    import javax.swing.text.html.HTMLDocument;
    import java.net.URL;
    import java.net.MalformedURLException;
    import java.io.IOException;
    import java.io.DataInputStream;
    import java.io.InputStream;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import javax.swing.text.html.*;
    import java.lang.reflect.*;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Rectangle;
    import java.awt.Shape;
    import java.awt.print.PageFormat;
    import java.awt.print.Printable;
    import java.awt.print.PrinterException;
    import java.awt.print.PrinterJob;
    import javax.swing.JEditorPane;
    import javax.swing.text.Document;
    import javax.swing.text.PlainDocument;
    import javax.swing.text.View;
    import javax.swing.text.html.HTMLDocument;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.print.*;
    import java.text.ParseException;
    public class PrintHtml {
         * Utility helper to convert HTML Text to HTML Document.
         * @param baseUrl URL to be used in order
         * to resolve relative HTML references, in lieu of an
         * HTML BASE tag. May be null, if not required or HTML
         * BASE tag is to be used.
         * @see jbox.view.jfx.JboxHtmlEditor
         * @see jbox.utility.JboxPrint
         * @see jbox.utility.JboxPrintUtil
      public static HTMLDocument htmlTextToHtmlDoc(String htmlText, URL baseUrl)
              try
              //  JboxHtmlEditorKit editorKit = new JboxHtmlEditorKit();
                HTMLEditorKit editorKit = new HTMLEditorKit();
                HTMLDocument doc = (HTMLDocument)editorKit.createDefaultDocument();
                   if (baseUrl != null)
                        try
                             doc.setBase(baseUrl);
                        catch(Exception e)
                             //JboxTraceManager.trace(e);
                   StringReader reader = new StringReader(htmlText);
                   editorKit.read(reader, doc, 0);
             return doc;
              catch(Exception e)
                   //JboxTraceManager.trace(e);
                   return null;
       public static void main(String[] args) {
          System.out.println("printing...");
          HTMLDocument x = new HTMLDocument();
          DocumentRenderer invoice = new DocumentRenderer();
          //invoice.setScaleWidthToFit(false);
          String s = "";
          try {
            BufferedInputStream bis = new BufferedInputStream(new FileInputStream("mark.html"));
            InputStreamReader in = new InputStreamReader(bis , "ASCII");
            StringWriter sw = new StringWriter();
            while (true) {
               int datum = in.read();
               if (datum == -1) break;
               sw.write(datum);
            in.close();
            s = sw.toString();
            System.out.println("s="+s);
          catch (IOException e) {
             System.err.println(e);
          HTMLDocument htmldoc = htmlTextToHtmlDoc(s, null);
          invoice.print(htmldoc);
    // the good old infamous DocumentRenderer.
    /*  Copyright 2002
        Kei G. Gauthier
        Suite 301
        77 Winsor Street
        Ludlow, MA  01056
    class DocumentRenderer implements Printable {
    /*  DocumentRenderer prints objects of type Document. Text attributes, including
        fonts, color, and small icons, will be rendered to a printed page.
        DocumentRenderer computes line breaks, paginates, and performs other
        formatting.
        An HTMLDocument is printed by sending it as an argument to the
        print(HTMLDocument) method. A PlainDocument is printed the same way. Other
        types of documents must be sent in a JEditorPane as an argument to the
        print(JEditorPane) method. Printing Documents in this way will automatically
        display a print dialog.
        As objects which implement the Printable Interface, instances of the
        DocumentRenderer class can also be used as the argument in the setPrintable
        method of the PrinterJob class. Instead of using the print() methods
        detailed above, a programmer may gain access to the formatting capabilities
        of this class without using its print dialog by creating an instance of
        DocumentRenderer and setting the document to be printed with the
        setDocument() or setJEditorPane(). The Document may then be printed by
        setting the instance of DocumentRenderer in any PrinterJob.
      protected int currentPage = -1;               //Used to keep track of when
                                                    //the page to print changes.
      protected JEditorPane jeditorPane;            //Container to hold the
                                                    //Document. This object will
                                                    //be used to lay out the
                                                    //Document for printing.
      protected double pageEndY = 0;                //Location of the current page
                                                    //end.
      protected double pageStartY = 0;              //Location of the current page
                                                    //start.
      protected boolean scaleWidthToFit = true;     //boolean to allow control over
                                                    //whether pages too wide to fit
                                                    //on a page will be scaled.
    /*    The DocumentRenderer class uses pFormat and pJob in its methods. Note
          that pFormat is not the variable name used by the print method of the
          DocumentRenderer. Although it would always be expected to reference the
          pFormat object, the print method gets its PageFormat as an argument.
      protected PageFormat pFormat;
      protected PrinterJob pJob;
    /*  The constructor initializes the pFormat and PJob variables.
      public DocumentRenderer() {
        pFormat = new PageFormat();
        pJob = PrinterJob.getPrinterJob();
    /*  Method to get the current Document
      public Document getDocument() {
        if (jeditorPane != null) return jeditorPane.getDocument();
        else return null;
    /*  Method to get the current choice the width scaling option.
      public boolean getScaleWidthToFit() {
        return scaleWidthToFit;
    /*  pageDialog() displays a page setup dialog.
      public void pageDialog() {
        pFormat = pJob.pageDialog(pFormat);
    /*  The print method implements the Printable interface. Although Printables
        may be called to render a page more than once, each page is painted in
        order. We may, therefore, keep track of changes in the page being rendered
        by setting the currentPage variable to equal the pageIndex, and then
        comparing these variables on subsequent calls to this method. When the two
        variables match, it means that the page is being rendered for the second or
        third time. When the currentPage differs from the pageIndex, a new page is
        being requested.
        The highlights of the process used print a page are as follows:
        I.    The Graphics object is cast to a Graphics2D object to allow for
              scaling.
        II.   The JEditorPane is laid out using the width of a printable page.
              This will handle line breaks. If the JEditorPane cannot be sized at
              the width of the graphics clip, scaling will be allowed.
        III.  The root view of the JEditorPane is obtained. By examining this root
              view and all of its children, printView will be able to determine
              the location of each printable element of the document.
        IV.   If the scaleWidthToFit option is chosen, a scaling ratio is
              determined, and the graphics2D object is scaled.
        V.    The Graphics2D object is clipped to the size of the printable page.
        VI.   currentPage is checked to see if this is a new page to render. If so,
              pageStartY and pageEndY are reset.
        VII.  To match the coordinates of the printable clip of graphics2D and the
              allocation rectangle which will be used to lay out the views,
              graphics2D is translated to begin at the printable X and Y
              coordinates of the graphics clip.
        VIII. An allocation Rectangle is created to represent the layout of the
              Views.
              The Printable Interface always prints the area indexed by reference
              to the Graphics object. For instance, with a standard 8.5 x 11 inch
              page with 1 inch margins the rectangle X = 72, Y = 72, Width = 468,
              and Height = 648, the area 72, 72, 468, 648 will be painted regardless
              of which page is actually being printed.
              To align the allocation Rectangle with the graphics2D object two
              things are done. The first step is to translate the X and Y
              coordinates of the graphics2D object to begin at the X and Y
              coordinates of the printable clip, see step VII. Next, when printing
              other than the first page, the allocation rectangle must start laying
              out in coordinates represented by negative numbers. After page one,
              the beginning of the allocation is started at minus the page end of
              the prior page. This moves the part which has already been rendered to
              before the printable clip of the graphics2D object.
        X.    The printView method is called to paint the page. Its return value
              will indicate if a page has been rendered.
        Although public, print should not ordinarily be called by programs other
        than PrinterJob.
      public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) {
        double scale = 1.0;
        Graphics2D graphics2D;
        View rootView;
    //  I
        graphics2D = (Graphics2D) graphics;
        disableDoubleBuffering(jeditorPane);
    //  II
        jeditorPane.setSize((int) pageFormat.getImageableWidth(),Integer.MAX_VALUE);
        jeditorPane.validate();
    //  III
        rootView = jeditorPane.getUI().getRootView(jeditorPane);
    //  IV
        if ((scaleWidthToFit) && (jeditorPane.getMinimumSize().getWidth() >
        pageFormat.getImageableWidth())) {
          scale = pageFormat.getImageableWidth()/
          jeditorPane.getMinimumSize().getWidth();
          graphics2D.scale(scale,scale);
    //  V
        graphics2D.setClip((int) (pageFormat.getImageableX()/scale),
        (int) (pageFormat.getImageableY()/scale),
        (int) (pageFormat.getImageableWidth()/scale),
        (int) (pageFormat.getImageableHeight()/scale));
    //  VI
        if (pageIndex > currentPage) {
          currentPage = pageIndex;
          pageStartY += pageEndY;
          pageEndY = graphics2D.getClipBounds().getHeight();
    //  VII
        graphics2D.translate(graphics2D.getClipBounds().getX(),
        graphics2D.getClipBounds().getY());
    //  VIII
        Rectangle allocation = new Rectangle(0,
        (int) -pageStartY,
        (int) (jeditorPane.getMinimumSize().getWidth()),
        (int) (jeditorPane.getPreferredSize().getHeight()));
    //  X
        if (printView(graphics2D,allocation,rootView)) {
          return Printable.PAGE_EXISTS;
        else {
          pageStartY = 0;
          pageEndY = 0;
          currentPage = -1;
          return Printable.NO_SUCH_PAGE;
      /** The speed and quality of printing suffers dramatically if
       *  any of the containers have double buffering turned on.
       *  So this turns if off globally.
       *  @see enableDoubleBuffering
      public static void disableDoubleBuffering(Component c) {
        RepaintManager currentManager = RepaintManager.currentManager(c);
        currentManager.setDoubleBufferingEnabled(false);
      /** Re-enables double buffering globally. */
      public static void enableDoubleBuffering(Component c) {
        RepaintManager currentManager = RepaintManager.currentManager(c);
        currentManager.setDoubleBufferingEnabled(true);
    /*  print(HTMLDocument) is called to set an HTMLDocument for printing.
      public void print(HTMLDocument htmlDocument) {
        setDocument(htmlDocument);
        printDialog();
    /*  print(JEditorPane) prints a Document contained within a JEDitorPane.
      public void print(JEditorPane jedPane) {
        setDocument(jedPane);
        printDialog();
    /*  print(PlainDocument) is called to set a PlainDocument for printing.
      public void print(PlainDocument plainDocument) {
        setDocument(plainDocument);
        printDialog();
    /*  A protected method, printDialog(), displays the print dialog and initiates
        printing in response to user input.
      protected void printDialog() {
        if (pJob.printDialog()) {
          pJob.setPrintable(this,pFormat);
          try {
            pJob.print();
          catch (PrinterException printerException) {
            pageStartY = 0;
            pageEndY = 0;
            currentPage = -1;
            System.out.println("Error Printing Document");
    /*  printView is a recursive method which iterates through the tree structure
        of the view sent to it. If the view sent to printView is a branch view,
        that is one with children, the method calls itself on each of these
        children. If the view is a leaf view, that is a view without children which
        represents an actual piece of text to be painted, printView attempts to
        render the view to the Graphics2D object.
        I.    When any view starts after the beginning of the current printable
              page, this means that there are pages to print and the method sets
              pageExists to true.
        II.   When a leaf view is taller than the printable area of a page, it
              cannot, of course, be broken down to fit a single page. Such a View
              will be printed whenever it intersects with the Graphics2D clip.
        III.  If a leaf view intersects the printable area of the graphics clip and
              fits vertically within the printable area, it will be rendered.
        IV.   If a leaf view does not exceed the printable area of a page but does
              not fit vertically within the Graphics2D clip of the current page, the
              method records that this page should end at the start of the view.
              This information is stored in pageEndY.
      protected boolean printView(Graphics2D graphics2D, Shape allocation,
      View view) {
        boolean pageExists = false;
        Rectangle clipRectangle = graphics2D.getClipBounds();
        Shape childAllocation;
        View childView;
        if (view.getViewCount() > 0 &&
              !view.getElement().getName().equalsIgnoreCase("td")) {
          for (int i = 0; i < view.getViewCount(); i++) {
            childAllocation = view.getChildAllocation(i,allocation);
            if (childAllocation != null) {
              childView = view.getView(i);
              if (printView(graphics2D,childAllocation,childView)) {
                pageExists = true;
        } else {
    //  I
          if (allocation.getBounds().getMaxY() >= clipRectangle.getY()) {
            pageExists = true;
    //  II
            if ((allocation.getBounds().getHeight() > clipRectangle.getHeight()) &&
            (allocation.intersects(clipRectangle))) {
              view.paint(graphics2D,allocation);
            } else {
    //  III
              if (allocation.getBounds().getY() >= clipRectangle.getY()) {
                if (allocation.getBounds().getMaxY() <= clipRectangle.getMaxY()) {
                  view.paint(graphics2D,allocation);
                } else {
    //  IV
                  if (allocation.getBounds().getY() < pageEndY) {
                    pageEndY = allocation.getBounds().getY();
        return pageExists;
    /*  Method to set the content type the JEditorPane.
      protected void setContentType(String type) {
        jeditorPane.setContentType(type);
    /*  Method to set an HTMLDocument as the Document to print.
      public void setDocument(HTMLDocument htmlDocument) {
        jeditorPane = new JEditorPane();
        setDocument("text/html",htmlDocument);
    /*  Method to set the Document to print as the one contained in a JEditorPane.
        This method is useful when Java does not provide direct access to a
        particular Document type, such as a Rich Text Format document. With this
        method such a document can be sent to the DocumentRenderer class enclosed
        in a JEditorPane.
      public void setDocument(JEditorPane jedPane) {
        jeditorPane = new JEditorPane();
        setDocument(jedPane.getContentType(),jedPane.getDocument());
    /*  Method to set a PlainDocument as the Document to print.
      public void setDocument(PlainDocument plainDocument) {
        jeditorPane = new JEditorPane();
        setDocument("text/plain",plainDocument);
    /*  Method to set the content type and document of the JEditorPane.
      protected void setDocument(String type, Document document) {
        setContentType(type);
        jeditorPane.setDocument(document);
    /*  Method to set the current choice of the width scaling option.
      public void setScaleWidthToFit(boolean scaleWidth) {
        scaleWidthToFit = scaleWidth;
    }The sample input file is "mark.html":::
    <html>
    <head>
    <style type="text/css">
    <!--
    ol { list-style-type: decimal; margin-top: 10; margin-left: 50; margin-bottom: 10 }
    u { text-decoration: underline }
    s { text-decoration: line-through }
    p { font-weight: normal; font-size: medium; margin-top: 15 }
    dd p { margin-top: 0; margin-left: 40; margin-bottom: 0 }
    ol li p { margin-top: 0; margin-bottom: 0 }
    address { color: blue; font-style: italic }
    i { font-style: italic }
    h6 { font-weight: bold; font-size: xx-small; margin-top: 10; margin-bottom: 10 }
    h5 { font-weight: bold; font-size: x-small; margin-top: 10; margin-bottom: 10 }
    h4 { font-weight: bold; font-size: small; margin-top: 10; margin-bottom: 10 }
    h3 { font-weight: bold; font-size: medium; margin-top: 10; margin-bottom: 10 }
    dir li p { margin-top: 0; margin-bottom: 0 }
    h2 { font-weight: bold; font-size: large; margin-top: 10; margin-bottom: 10 }
    b { font-weight: bold }
    h1 { font-weight: bold; font-size: x-large; margin-top: 10; margin-bottom: 10 }
    a { color: blue; text-decoration: underline }
    ul li ul li ul li { margin-right: 0; margin-top: 0; margin-left: 0; margin-bottom: 0 }
    menu { margin-top: 10; margin-left: 40; margin-bottom: 10 }
    menu li p { margin-top: 0; margin-bottom: 0 }
    table table { border-color: Gray; margin-right: 0; border-style: outset; margin-top: 0; margin-left: 0; margin-bottom: 0 }
    sup { vertical-align: sup }
    body { margin-right: 0; font-size: 14pt; font-family: SansSerif; color: black; margin-left: 0 }
    ul li ul li ul { list-style-type: square; margin-left: 25 }
    blockquote { margin-right: 35; margin-top: 5; margin-left: 35; margin-bottom: 5 }
    samp { font-size: small; font-family: Monospaced }
    cite { font-style: italic }
    sub { vertical-align: sub }
    em { font-style: italic }
    table table table { border-color: Gray; margin-right: 0; border-style: outset; margin-top: 0; margin-left: 0; margin-bottom: 0 }
    ul li p { margin-top: 0; margin-bottom: 0 }
    ul li ul li { margin-right: 0; margin-top: 0; margin-left: 0; margin-bottom: 0 }
    var { font-weight: bold; font-style: italic }
    table { border-color: Gray; margin-right: 7; border-style: outset; margin-top: 7; margin-left: 7; margin-bottom: 17 }
    dfn { font-style: italic }
    menu li { margin-right: 0; margin-top: 0; margin-left: 0; margin-bottom: 0 }
    strong { font-weight: bold }
    ul { list-style-type: disc; margin-top: 10; margin-left: 50; margin-bottom: 10 }
    center { text-align: center }
    ul li ul { list-style-type: circle; margin-left: 25 }
    kbd { font-size: small; font-family: Monospaced }
    dir li { margin-right: 0; margin-top: 0; margin-left: 0; margin-bottom: 0 }
    th p { font-weight: bold; padding-left: 2; padding-bottom: 3; padding-right: 2; margin-top: 0; padding-top: 3 }
    ul li menu { list-style-type: circle; margin-left: 25 }
    dt { margin-top: 0; margin-bottom: 0 }
    ol li { margin-right: 0; margin-top: 0; margin-left: 0; margin-bottom: 0 }
    li p { margin-top: 0; margin-bottom: 0 }
    strike { text-decoration: line-through }
    dl { margin-top: 10; margin-left: 10; margin-bottom: 10 }
    tt { font-family: Monospaced }
    ul li { margin-right: 0; margin-top: 0; margin-left: 0; margin-bottom: 0 }
    dir { margin-top: 10; margin-left: 40; margin-bottom: 10 }
    pre p { margin-top: 0 }
    th { border-color: Gray; border-style: solid; padding-left: 3; padding-bottom: 3; padding-right: 1; padding-top: 1 }
    pre { font-family: Monospaced; margin-top: 5; margin-bottom: 5 }
    td { border-color: Gray; border-style: inset; padding-left: 3; padding-bottom: 3; padding-right: 1; padding-top: 1 }
    td p { padding-left: 2; padding-bottom: 3; padding-right: 2; margin-top: 0; padding-top: 3 }
    code { font-size: small; font-family: Monospaced }
    small { font-size: x-small }
    big { font-size: x-large }
    -->
    </style>
    </head>
    <body>
    <p style="margin-top: 0">
    </p>
    <table width="500" cellspacing="20" border="1">
    <tr>
    <td height="330" valign="top">
    <table border="0">
    <tr>
    <td>
    <font size="2">This is to certify that [[Client Name]], born
    on [[Client Date of Birth]], of [[Client Residential
                    Address]], was the holder of motor vehicle driver
    licence number [[Client Licence Number]], first issued on
    [[First Issue Date of Holding]] and expired on [[Holding
                    Expiry Date]].<br></font>
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    <table width="500" border="2">
    <tr>
    <td>
    <table width="480" border="0">
    <tr>
    <td align="right">
    <font size="2"><br>
    <b>Fred Flintstone<br>Manager</b><br>Records Services Division<br>State
    Police<br>An authorised person for the purposes of the
    Road Act 1986</font>
    </td>
    </tr>
    <tr>
    <td align="left">
    <font size="2"><b>User ID: wzvqv7<br>Dated: 29 November 2006</b>
    </font>
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </body>
    </html>

    I have finally cracked it!!!!!!!!!!!!!!!!
    The issue is definitely with Java Sun. "Uneven character spacing when printing JTextComponent"
    It is raised on the http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6488219
    And currently in OPEN state, and raised on 31 Oct 2006 and mentions it was caused by fix 4352983.
    So where do we go from here. It's not good because I have tried all later version of the JVM and the issue is still there.
    Why? Because it hasn't been fixed yet. Read the bug report above, as it gives more insight -- and mentions the workaround is NOT good for existing code.
    So the way forward is to use an earlier version of the JVM 5.
    I download the JVM version 1.5.0 (starting version) and works Ok... I would probably think version prior to 4352983 would be Ok too.
    Please vote for this.... We have a workaround (use older version of the JVM).
    So I am very happy.

  • Forms 10gR2 printing issue with Java Plug-in 1.6.0_21

    Hi All,
    I replaced Jinitiator by Java Plug-in 1.6.0_21. I’m using forms 10gR2. I modified formsweb.cfg file and most of the other functionality work fine. I overwrote the default functionality of the menu item ‘Print Button’ by the following java script
    *'File name :- print.html'*
    <html>
    <head>
    <title>Print</title>
    <style type="text/css">
    font-family:"arial";
    color: #303030;
    </style>
    </head>
    <body onload="printsetup();">
    <div style="border: 1px solid; padding:10px">
    <div style="font-size:larger;text-decoration:bold;padding-bottom:10px;text-align:center">Print capture beginning. Please wait...</div>
    <div style="text-align:center">(This window will close automatically.)</div>
    </div>
    <script>
    function printform()
    window.opener.print();
    window.close();
    function printsetup()
    window.resizeTo(600,250);
    var t=setTimeout("printform()",1000);
    </script>
    </body>
    </html>
    It was working fine with Jinitiator since I installed java sun I always receive the following error message
    Line: 19
    Char: 1
    Error: 'window.opener' is null or not an object
    Code: 0
    URL: http://localhost.domain:port/forms/webutil/start/print.html.
    Thanks & Regards,
    Walid

    The problem you are both reporting is unclear. If I understand at all what you are doing, it would seem that you are calling window.opener, but the window has no name. In newer browser versions (I believe IE 7 and newer) what I think you are trying to do won't work anymore. Take a look at this:
    http://msmvps.com/blogs/paulomorgado/archive/2007/11/02/how-to-close-browser-windows-in-windows-internet-explorer-7.aspx
    Also check out MyOracleSupport Note 865745.1
    The example in the note has been tested with Forms 10.1.2.3 and 11.1.1.4 using 1.6.0_23 in IE8 and FF3.6 and appears to work correctly.

  • Help with Java Printing-Custom paper sizes

    Hi,
    I'm trying to print documents with custom paper sizes out of java.
    I can print fine when I don't try to set the MediaSize to a custom size or when I use already named constants like: "MediaSizeName.JIS_B4"
    The error message I get is this:
    java.lang.ClassCastException
         at javax.print.attribute.AttributeSetUtilities.verifyAttributeValue(Unknown Source)
         at javax.print.attribute.HashAttributeSet.add(Unknown Source)
         at hello.Printy.printDocument(Printy.java:103)
         at hello.Printy.main(Printy.java:135)
    The offending line(103) looks like this:
    pras.add(new MediaSize(1,10,MediaSize.INCH ));The function that its from looks like this:
    public  void printDocument()
    try
              System.out.println("input file name is");
         System.out.println(inputFileName);
    PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
    DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
    PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
    PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
    PrintService printPrintService = null;
    // didn't work pras.add(new MediaSize(1,10,MediaSize.INCH) );
    PrintService service = ServiceUI.printDialog(null, 200, 200,printService, defaultService, flavor, pras);
    if (service != null)
         System.out.println("There is a service aunty-may!!");
    DocPrintJob job = service.createPrintJob();
    FileInputStream fis = new FileInputStream(getInputFileName());
    DocAttributeSet das = new HashDocAttributeSet();
    //pras.add(new MediaSize((float)3.25, (float)4.75, Size2DSyntax.INCH ) );
    // - works
    //pras.add(MediaSizeName.JIS_B4);
    pras.add(new MediaSize(1,10,MediaSize.INCH ));
    //pras.add(new MediaSize(1,10,MediaSize.INCH) );
         System.out.println("Doc has been set to custom size");
    Doc doc = new SimpleDoc(fis, flavor, null);
    job.print(doc, pras);
         System.out.println("any doc for you?");
    catch (Exception e)
    e.printStackTrace();
    }Any help with this would be greatly appreciated. I'm new to java but I've programmed a bunch in c++.

    Hmm ... no real help, but I found this note in the API:
    MediaSize is not yet used to specify media. Its current role is as a mapping for named
    media (see MediaSizeName). Clients can use the mapping method
    MediaSize.getMediaSizeForName(MediaSizeName) to find the physical dimensions of
    the MediaSizeName instances enumerated in this API. This is useful for clients which
    need this information to format & paginate printing.

  • Remote Desktop Services Printer Redirection with easy print not working as Desired

    Hi,
     I have a Terminal Server Farm with a number of Windows Server 2008 R2 Remote Desktop Session Host Servers in the Environment. There is also a RD Gateway server which is used to connect to the RD Session host servers in the environment. We
    had configure the policy "Use Terminal Services easy Print Driver First" for all the RD Session Host servers. Everything was working well untill a couple of users Complaint about slow printing on Easy Print. While trying to troubleshoot the issue we came
    to know that when we by-pass the RD Gatewat and make a Direct connection to the RD Session Host Servers we are able to Print Really fast using Easy Print. Only When we use the RD gateway server we get the problem with the Printing.
     As we could not get through this problem and we are not in a condition to by-pass RD Gateway for connections we decided to put the TS Easy print Driver as a Second option. We went ahead and identified the 3 printers for which printing was slow. we
    Installed the Drivers for the same printers on all the Terminal Server and Disabled the policy "Use Termianl Server Easy print Driver First". After this we were able to print fast on the 3 printers having Slow printing issues. All the other Printers were using
    Easy print.
    After a day we realised that there were more than 20 drivers for Different printers installed in the Print Server Properties. We started getting viered problems with the Printing on all the Terminal servers like, Print Spooler Service Crashing, Hanging,
    Users not able to redirect printers at all. To avoid this we Removed the Driver Packages but they came back the very next day.
     I am not sure what could be causing this kind of behavior. I would really appriciate if someone can help he with these two problems
    1) Easy print Working Slow only when using RD Gateway Server
    2) Printer Drivers Getting installed on Terminal Servers when Easy Print Policy is disabled.

    1) Easy print Working Slow only when using RD Gateway Server
    > Difficult to track down especially through forum. Looking for some known issues/hotfixes
    954743 FIX: After you apply hotfix 954744, printing performance may be significantly slower when you print documents by using Terminal Services Easy Print
    http://support.microsoft.com/?id=954743  
    The Remote Desktop Easy Print (RD Easy Print or TS Easy Print) uses the XPS print driver that ships with .NET Framework.
    2) Printer Drivers Getting installed on Terminal Servers when Easy Print Policy is disabled.
    > If Easy print is not the first driver then it installs the driver if they are InBox drivers
    > If these are non-inbox drivers - This is because administrators are RDPing to the server from another PC with several printer/drivers installed.
    When they RDP with printer redirection enabled, the drivers get automatically installed.
    To avoid this, either turn off printer redirection at server level from RDP-TCP properties - might not be feasible if users need redirected printers
    Else make sure that when admins RDP, printer redirection is turned off so that drivers are not automatically installed
    This was a major issue in 2k3, i havent tested it in 2k8 though
    This behavior is related to the change you made in Easy print driver behavior
    Sumesh P - Microsoft Online Community Support

  • Print resolution with DNG converter 5.7 beta

    I am using Lightroom 1.4.1, Vista 32bit sp2, Canon 350D and 550D cameras and Canon i9950 printer.  In order to open Canon RAW files from the 550D I am converting to DNG with the latest Adobe DNG converter (5.7.0212 beta).  I use ACR 4.1 compatibility in accordance with the guidance given on the DNG Converter preference page.  I have today noticed some abnormal behaviour that the beta release page asks me to report here.
    Converting 550D file to dng using the ACR 4.1 compatibility, opening the dng in Lightroom and printing the full (18M) frame at 6x4 inch, with the print options set to 480dpi and medium sharpening, I obtain a print which has a resolution of 100dpi or less.
    Crop the image to quarter size and print as 1 above - print resolution normal (480).
    Convert a 350D image (8M) and print as 1 above - print resolution normal
    Print 550D RAW using Canon DPP - print resolution normal
    Convert 550D file to dng using ACR 5.4 compatibility.  Opens OK in LR1.4.1 (fortunately), print as 1 above and print resolution is normal.
    The only apparent difference between converting at ACR 4.1 and 5.4 compatibility is the print resolution - the 5.4 version seems to open and be stable with LR 1.4.1.  To use 5.4 compatibility is an obvious workaround - are there any pitfalls when using this version?

    samuelphoto wrote:
    How do I get it to work within Bridge when I use the command "Get Photos from Camera..."?
    You can't...DNG Converter is a stand alone app and can't be used with Bridge...since you are working with Bridge CS4. if there is no built in support for your camera, you'll have to do a finder copy and then convert. Also note that you are not limited to using DNG Converter 5.7. You can use the most recent DNG Converter which is 6.2 (the 6.3 version is an RC and not yet released). But, that won't help Bridge CS4 either...
    You can use the Canon software to do the import from camera or card...

  • Printing chinese w/ Java Print Service API become garbled characters

    I'm using XP platform and I've a plain text file on my drive.
    Now, what I want to do is, to read the text file in, then print it, that's all.
    However, the printout become messy, just some garbled characters.
    I did try to change quite a different ways to read the file, but the printout is still messy.
    Is there anything wrong? Can somebody give me a help?
    package com.ysf.document.client.ups;
    import java.io.FileReader;
    import java.io.IOException;
    import javax.print.*;
    import javax.print.attribute.*;
    public class Class1
       public static void main(String[] args)
          String filename = "c:\\temp\\abcd.txt";
          DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
          PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
          // locate a print service that can handle it
          PrintService[] pservices = PrintServiceLookup.lookupPrintServices(flavor, aset);
          // create a print job for the chosen service
          int printnbr = 1;
          DocPrintJob pj = pservices[printnbr].createPrintJob();
          try
             int c;
             FileReader f = new FileReader(filename);
             StringBuffer buffer = new StringBuffer();
             c = f.read();
             while (c != -1)
                buffer.append((char) c);
                c = f.read();
             Doc doc = new SimpleDoc(buffer.toString().getBytes("BIG5"), flavor, null);
             pj.print(doc, aset);
          } catch (IOException ie)
             System.err.println(ie);
          } catch (PrintException e)
             System.err.println(e);
    }

    For #1, indeed, it's my overlook, I've corrected it already.
    For #2, it shows, java.lang.ArrayIndexOutOfBoundsException: 1.
    It's mainly because my printer do not support this flavor.
    My printer supports only:
    image/gif
    [B OR java.io.InputStream OR java.net.URL
    image/jpeg
    [B OR java.io.InputStream java.net.URL
    image/png
    [B OR java.io.InputStream OR java.net.URL
    application/x-java-jvm-local-objectref
    java.awt.print.Pageable OR java.awt.print.Printable
    application/octet-stream
    [B OR java.net.URL OR java.io.InputStream
    Up to now, still no solution to it. Anybody help.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Printing Problems with JAVA

    Hello,
    I have problems with the following Code.
    import java.text.NumberFormat;
    import javax.print.Doc;
    import javax.print.DocFlavor;
    import javax.print.DocPrintJob;
    import javax.print.PrintException;
    import javax.print.PrintService;
    import javax.print.PrintServiceLookup;
    import javax.print.SimpleDoc;
    public class Printer {
         private PrintService[] printers;
         private int choosenPrinter;
         private StringBuffer text;
          * Der Konstruktor legt einen Array der verfügbaren Drucker an.
          * @param stdPrinter Der aktuell ausgewählte Drucker(-index)
         public Printer(int stdPrinter) {
              printers = PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.AUTOSENSE, null);
              if (printers.length > 0){
                   choosenPrinter = 0;
                   setChoosenPrinter(stdPrinter);
              } else choosenPrinter = -1;
          * Liefert einen Array mit Namen der verfügbaren Drucker.
          * @return Namen der verfügbaren Drucker
         public String[] getPrinters() {
              String[] retPrinters = new String[printers.length];
              for (int i = 0; i < printers.length; i++) {
                   retPrinters[i] = printers.getName();
              return retPrinters;
         * @return Liefert den Index des aktuell ausgewählten Druckera
         public int getChoosenPrinter() {
              return choosenPrinter;
         * Setzt den Index des aktuell ausgewählten Druckers neu,
         * wenn der Index gültig ist.
         * @param choosenPrinter Der neu ausgewählte Index
         public void setChoosenPrinter(int choosenPrinter) {
              if (choosenPrinter <= printers.length) {
                   this.choosenPrinter = choosenPrinter;
         * Druckt eine oder mehere Quittungen über die übergebenen Daten
         * @param buchung Buchung die in der Quittung enthalten sein soll.
         * @param haendler Händler der in die Quittung aufgenommen werden soll.
         * @param kunde Kunde der in die Quittung aufgenommen werden soll.
         * @param config Das aktuelle Configobjekt.
         * @param times Anzahl der Quittungen die gedruckt werden sollen.
         * @return true wenn der Druck erfolgreich angestoßen wurde, false sonst
         public boolean printBuchung() {
              if (choosenPrinter == -1) return false;
              PrintService printer = printers[choosenPrinter];
              String ls = System.getProperty("line.separator");
              NumberFormat nf = NumberFormat.getInstance();
              nf.setMaximumFractionDigits(2);
              nf.setMinimumFractionDigits(2);
              text = new StringBuffer();
              if ('T' == 'T') {
                   text.append("Q U I T T U N G");
                   text.append(ls);
              String temp = text.toString();
              temp = temp.replace("ä", "ae");
              temp = temp.replace("ö", "oe");
              temp = temp.replace("ü", "ue");
              temp = temp.replace("ß", "ss");
              for (int i=0; i<1000; i++) {
                   DocPrintJob docPJ = printer.createPrintJob();
                   Doc doc;               
                   doc = new SimpleDoc(temp.getBytes(), DocFlavor.BYTE_ARRAY.AUTOSENSE, null);
                   try
                   docPJ.print(doc, null);
                   catch (PrintException e)
                        return false;
                   catch (Exception e)
                        // TODO Auto-generated catch block
                        e.printStackTrace();
              return true;
    }The programm sends the printing job to Windows XP but nothing is happend. Have anybody a tip for me?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    I tried this and it shut off Firefox accessing the internet. had to uninstall FF and Adobe and do a reinstall to get my internet back up and working. This only effected my browser not my pop3 mail

  • Adding Print Button With Java Script to Print of Different Pages Differently

    Hi,
    I am in the process of making a form and most of it is done and now I want to be able to print off two of the pages but to different printers, I have one that needs to be printed off on a regular A4 printer and another that needs to go to a label printer. I have both of the names for the printers and I have tried something but it just doesnt do anything at all (this is suggested by adobe I think?)
    var pp = this.getPRintParam();
    var printamount = this.getValue("Quantity_Boxes");
    pp.printerName = "Zebra Technologies ZTC GK420t";
    pp.firstPage = 3;
    pp.lastPage = 3;
    pp.NumCopies = 2*printamount;
    this.print();
    I tried it without the first and last page and nothing happens, I am useing a shared printer which works when I do cmd + P which the full printer name is Zebra Technologies ZTC GK420t @ User's iMac. (I have also tried putting the full name in aswell)
    This is just to test one page so far but is there any way that one button will be able to print off 2 different pages to 2 different printers?
    If someone knows how this would be a great help!
    Thanks,
    Bruce

    Thanks for that, I have it working now but it shows the dialog box with no settings changed should i use:
    pp.interactive = pp.constants.interactionLevel.automatic ?
    Thanks,
    Bruce
    EDIT:
    It printed but only the first page but it printed on the right amount quantity was 2*3 wich was the result of the Quantity_Box value
    I want it to print page 3 through the Zebra Printer and have page 2 printed to a different printer, is this possible through one button?

  • Monitor Print Queue with java program

    I'm plan to write a client/server based application which control the printing for every user. I've no idea how to start on the application.
    1. Is it possible to monitor the print queue or print job using java application?
    2. How does the server react if the client sending the print job to there? How's the client can trigger the signal during printing and send to the server?
    Thank you!

    I'm plan to write a client/server based application
    which control the printing for every user. I've no
    idea how to start on the application.You should establish feasibility first, before planning to write anything
    1. Is it possible to monitor the print queue or print
    job using java application?Not really. Print queues are highly system-dependent things and some e.g. Windows can really only be accessed via system calls in a native language.
    2. How does the server react if the client sending
    the print job to there?Err, it prints the file?
    How's the client can trigger the signal during printing and send to the server? What signal?
    But I suspect the answer to the first question makes the others irrelevant.

  • How to print Text with Java

    I am new to java, learning fast, lots of new stuff every day. i want to develop an application that can print a report (Text mostly eg. Like an Invoice) to a printer. i am searching the net still cant find nothing that i can understand. Help please

    To learn java printing, you may want to visit:
    http://java.sun.com/j2se/1.4.2/docs/guide/jps/
    or
    http://java.sun.com/docs/books/tutorial/2d/printing/
    Or you can download reporting tool, please visit:
    http://jasperreports.sourceforge.net/
    or
    http://www.elixirtech.com/
    Okie! God bless :)

  • Printing dashboard with network printer

    Is there any way to send/print the dashboard page to physical network printer? i am having links to HTML print and PDF print. But i want to print with network printer. please give some suggetion.
    thanks

    Currently there is no out of the box solution. But with some amount of work you can make it very robust by using ibots and BI Publisher Java APIs. You need to basically call the delivery manager API from the ibot. You can pass the output of a dashboard to the API which can print to a local printer. I have an example in my blog entry here http://oraclebizint.wordpress.com/2008/02/01/oracle-bi-ee-101332-calling-bi-publisher-java-apis-from-ibots-storing-reports-in-file-system-using-delivers-and-bi-publisher-scheduler/. Though this talks about storing the reports in a file system, the idea is the same. Instead of a file-system destination use printer as the destination.
    Thanks,
    Venkat
    http://oraclebizint.wordpress.com

  • Printing HTML file to printer

    Hi,
    I'm getting
    sun.print.PrintJobFlavorException: invalid flavor
    at sun.print.Win32PrintJob.print(Win32PrintJob.java:327)
                InputStream is = new BufferedInputStream(new FileInputStream("temp.html"));
                PrintService service = PrintServiceLookup.lookupDefaultPrintService();
                DocPrintJob job = service.createPrintJob();
                DocFlavor flavor = DocFlavor.INPUT_STREAM.TEXT_HTML_UTF_8;
                Doc doc = new SimpleDoc(is, flavor, null);
                job.print(doc, null);
                is.close();Or, how do I print HTML code (generated on the fly, not from any file) to printer?

    Whether you can depends on what the printer you're using is capable of. The chance of it working is small, tho. Run this pgm and see what your default printer will accept.
    import javax.print.DocFlavor;
    import javax.print.PrintService;
    import javax.print.PrintServiceLookup;
    public class DocFlavorLister
        public static void main(String args[])
            PrintService service =
                PrintServiceLookup.lookupDefaultPrintService();
            System.out.println(service + " supports :");
            DocFlavor[] flavors = service.getSupportedDocFlavors();
            for (int i = 0; i < flavors.length; i++)
                System.out.println("\t" + flavors);

Maybe you are looking for

  • PO and Requisition Notifications

    Using standard functionality in R12, 1. When purchasing buyer returns the requisition with a reason, can the requestor, req approver be notified via email about this? How? 2. Let say, the PO approver (someone from finance dept) rejects the PO due to

  • Dropouts and poor performance

    I'm on a long copper run, getting about as hi speed as expected around 3M (so profile looks ok) But ping times regularly in high hundreds of ms or timeout (several times a minute), normally 60-80ms Trace route & pings below during one of these period

  • Pretty big problem

    I'm making a messenger and I can't get it to find a couple files I need. I'm using my own packages and interfaces and I can't get them to find each other. I was wondering if I could send it to someone to take a look at because there are a bunch of fi

  • PC5400 Memory

    I wanted to add a gig of ram to my macbook pro. I was going to buy the OCZ 1024MB PC5400D DR2 667MHz SODIMM Memory Will this be compatible with the macbook pro considering the mac runs PC5300 ram? Thanks

  • 443 projects after iphoto library import - what the hey?

    I recently imported 9500+ images to A3 via file->import->iphoto library and while all the images are in the A3 library, they are randomly split into a total of 443 projects (yes, I counted them thank you very much). Is it possible to import the iphot