PRINTING PROBLEM, please help :~~~

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jodi
    New Member
    • Feb 2007
    • 5

    PRINTING PROBLEM, please help :~~~

    Hi, I am really newbie in Java
    I need to build an applet that prints a text, but, it can not roll the page
    I mean, when I print like
    "TEST ONE
    TEST TWOO
    TEST THREEE"
    the printer can not roll the paper below the three lines
    because I am using those fiscal printers...
    down below is the, modified, code I found in internet...
    i am trying to do that in about 4 hours without any good result.
    the page is still be swalled by the printer, making the fiscal paper losing its right position
    please, any help would be appreciated

    Code:
    import java.awt.*;
    import java.awt.font.*;
    import java.awt.geom.*;
    import java.awt.print.*;
    import java.awt.image.*;
    import java.text.*;
    import java.net.*;
    
    
    public class Example6  {
    
       //--- Private instances declarations
       private final static int POINTS_PER_INCH = 72;
       
    
       /**
        * Constructor: Example6 <p>
        *
        */
       public Example6 () {
    
          //--- Create a new PrinterJob object
          PrinterJob printJob = PrinterJob.getPrinterJob ();
    
          //--- Create a new book to add pages to
          Book book = new Book ();
    
          //--- Add the document page using a landscape page format
          PageFormat documentPageFormat = new PageFormat ();
          documentPageFormat.setOrientation (PageFormat.LANDSCAPE);
    
          //Paper paper = documentPageFormat.getPaper(); 
          Paper paper = new Paper();
          
          // Limit paper width and height
          paper.setSize(120, 120);
          paper.setImageableArea(10, 10, 80, 80);      
          // set the paper to this, edited one
          documentPageFormat.setPaper(paper);
             
          book.append (new Document (), documentPageFormat);         
    
          //--- Tell the printJob to use the book as the pageable object
          printJob.setPageable (book); 
    
          //--- Show the print dialog box. If the user click the 
          //--- print button we then proceed to print else we cancel
          //--- the process.
          if (printJob.printDialog()) {
             try {
                printJob.print();  
             } catch (Exception PrintException) {
                PrintException.printStackTrace();
             }
          }
       }
    
    
       /**
        * Class: Document <p>
        *
        * This class is the painter for the document content. In this example,
    
        */
       private class Document extends Component implements Printable {
    
    
          /**
           * Method: print <p>
           *
           * @param g a value of type Graphics
           * @param pageFormat a value of type PageFormat
           * @param page a value of type int
           * @return a value of type int
           */
          public int print (Graphics g, PageFormat pageFormat, int page) {
    
    
             //--- Create the Graphics2D object
             Graphics2D g2d = (Graphics2D) g;
    
             //--- Translate the origin to 0,0 for the top left corner
             g2d.translate (pageFormat.getImageableX (), pageFormat.getImageableY ());
    
             //--- Set the drawing color to black
             g2d.setPaint (Color.black);
    
             //--- Draw a border arround the page using a 12 point border
             //g2d.setStroke (new BasicStroke (4));
             Rectangle2D.Double border = new Rectangle2D.Double (0, 
                                                                 0, 
                                                                 pageFormat.getImageableWidth (),
                                                                 pageFormat.getImageableHeight ());
    
             g2d.draw (border);
             
             Font titleFont = new Font ("Courier New", Font.BOLD, 10);
             g2d.setFont (titleFont);
    
             g2d.drawString("w=" + pageFormat.getWidth(), 20, 20);
             //--- Validate the page
             return (PAGE_EXISTS);
          }
       }
    
    } // Example6
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    What do you mean by 'roll the page'?

    Comment

    • nickyeng
      Contributor
      • Nov 2006
      • 252

      #3
      your "roll the page" means the printer somehow cannot roll the paper?

      is it printer problem or java issue?

      Comment

      • jodi
        New Member
        • Feb 2007
        • 5

        #4
        Sorry about my English, it is not that good.
        And thank you very much in replying my post

        About the "roll the page" I mean that the printer must not roll the paper, it must only grab the paper where it will print some text... I tried doing that setting the Paper.SetSize, but was in vain...
        let me try to explain more...

        Do you know fiscal printers?
        Where the paper of the machine aren't pages, but dotted, so you can cut it...

        the image above is a fiscal printer...
        its paper isn't one paper, but a big set of paper that are one

        the problem:
        When I send a text to the printer, the printer normally prints the text, but, it still pull more paper, making my fiscal paper be deslocated to use it again

        the paper can't be pulled more than 100 in width...

        Sorry again for my English, some words just disappear... :(
        Thank you!

        Comment

        • jodi
          New Member
          • Feb 2007
          • 5

          #5
          I think I solved it
          but not sure how
          i copy and pasted the "limiting paper" piece of code on certain parts of the script
          after the "if (printDialog)" and inside the onpaint function...

          Thanks for everyone that helped me
          if I need it again, for sure i'll come here
          and for sure if I can help other, i'll try my best
          thank you

          Comment

          Working...