Printing with java app

Hi all, I'm making a program for printing on continuous paper.
I have 2 steps to my program so far and issues in all of them:
1) Creating the print job, setting the paper size, margins, sending to printer
2) I'm printing to a file, so I can remove the last 4 byets of the file that make the printer scroll the page out.
The issues in the first part is that I can't seem to start printing at the top of the page (it always scrolls down like 2 inches). Changing the imageable area and margins don't seem to help with that or I just don't understand them. If I set margins to 0, it's just clipping the text and not printing it out properly. I also can't print more than 1 page size (height-wise), which sucks, considering I'm printing on continious paper.
    @Override
    public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
        if (page > 0) {
            return NO_SUCH_PAGE;
        Paper paper = new Paper();
        paper.setSize(612, 10000);
        double margin = 72;
        paper.setImageableArea(margin, margin, paper.getWidth() - margin * 2, paper.getHeight()
        - margin * 2);
        pf.setPaper(paper);
        Graphics2D g2d = (Graphics2D)g;
        g2d.translate(pf.getImageableX(), pf.getImageableY());
        Font big = new Font("Times New Roman", Font.PLAIN, 12);
        Font small = new Font("Times New Roman", Font.PLAIN, 8);
        int Xlocation = 20;
        int y = 20;
        int count = 20;
        int i = 1;
        while (i < count){
            g2d.setFont(small);
            g.drawString("1", Xlocation , y);
            y += 8;
            g.drawString("2", Xlocation , y);
            y+=12;
            g2d.setFont(big);
            g.drawString("3", Xlocation , y);
            y += 8;
            g2d.setFont(small);
            g.drawString("4", Xlocation , y);
            y += 20;
            i++;
        // tell the caller that this page is part of the printed document
        return PAGE_EXISTS;
    }In the second part I'm removing the last 4 bytes of the file and adding a new line so it wouldn't scroll the page out after it is done printing. This works fine.
I would like it to not prompt the user for file name, but give it a default name of something like "print.prn" and then run command prompt and enter command "copy /b print1.prn lpt1" which would send it to printer and then close command prompt. Is this possible?
the second part:
        try {
            File target = new File(filename);
            RandomAccessFile file = new RandomAccessFile(target,"rw");
            file.setLength(target.length()-4); // Strip off the last 4bytes
            file.seek(target.length()); // set pointer to the end of file
            file.writeUTF("\n"); // add new line at the end of file
            file.close();
            Runtime rt = Runtime.getRuntime();
            rt.exec("cmd.exe /c start copy /b " +filename+ " lpt1");
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex);
        }  

Anyone have any additional updates on this problem? We've just upgraded to JRE 1.6 update 10 and started seeing this on Windows XP machine. The printer that the users are trying to print to is a Lexmark T644 with a PS driver. I checked the Lexmark site and compared the driver on the users' machines with what is available on the Lexmark site. It appears that the users' machines has the latest version of the driver. I saw there was a bug open with Sun on the same type of problem on a non windows platform and related to having either an * or - in the printer name. I've verified that neither character is in the printer name in this instance. It also sounded as if on this bug that the problem could be reproduced every time. We're not seeing that either. Sometimes the printer accepts the work and other times is doesn't. Any insight on this.

Similar Messages

  • Windows Macro Engine for use with Java Apps

    Does anyone know of a macro engine that can be used under windows for interaction with a Java app? None of the ones I've tried will work with Java Apps. Work great with everything else I've tried, just not Java apps.
    Will

    What exactly is a macro engine? What do you want it to do? Do you want to add scripting to your application? Or do you want to script third party applications, that don't support it themselves?

  • Cannot print on a USB printer with Java PrintService in Windows 2000. Why?

    I want to print a simple ASCII file on a USB printer under Win2K and
    found 2 problems. Here is the 2nd one.
    Even though
    PrintServiceLookup.lookupPrintServices(<DocFlavor>, <AttributeSet>)
    returns nothing when I specify any AttributeSet, I can still print on the default printer, which I get by
    PrintService defServicedefService = PrintServiceLookup.lookupDefaultPrintService();
    but only on a parallel printer (HP Laserjet 4 Plus), either directly attached or over the network. When I try the very same code on a locally USB-attached printer, the printer is obviously reacting, but nothing is printed.
    In case of a Lexmark 730 (an ink printer), the driver even lies, it has printed 100%,
    on a Samsung CLP-510 (a color laser) the ready light flashes twice, that's all.
    The file to be printed has 5 lines and a "0C"X at the end in order to force a page eject at the end.
    I tried it with JDK 1.4.2 and with Java 6, same problem.
    I should mention that I can print that little file out of the editor Textpad without any problem.

    Thanks a lot for the quick hint, but it did not help.
    I used BasicPrint.java and PrintJobWatcher.java of the samples for testing.
    Printing a GIF file works both to a parallel printer and a USB printer.
    Then I changed only the DocFlavor from DocFlavor.INPUT_STREAM.GIF to DocFlavor.INPUT_STREAM.AUTOSENSE, and that one works with my parallel printer, but on the USB printer the Ready light flashes twice, that's all.
    The ASCII file must have a "0C"X at the end to force a page eject on the parallel printer
    Maybe it is a matter of the DocFlavor, but which one?
    DocFlavor("application/octet-stream", "java.io.InputStream") works like DocFlavor.INPUT_STREAM.AUTOSENSE.
    DocFlavor.INPUT_STREAM.TEXT_PLAIN_HOST and DocFlavor.INPUT_STREAM.TEXT_HTML_US_ASCII cause sun.print.PrintJobFlavorException, and with DocFlavor.INPUT_STREAM.TEXT_PLAIN_US_ASCII just nothing happens on either printer, not even an error message.
    I am getting the impression that nobody of the developers ever cared for testing such a simple thing as a plain ASCII file under Windows.
    My printers I am using for the tests are
    1. an old parallel-attached HP Laserjet 4 Plus and
    2. a borrowed USB-attached Samsung CLP-510 color laser

  • Cannot print on a USB printer with Java PrintService in Windows 2000

    I want to print a simple ASCII file on a USB printer under Win2K and
    found 2 problems. Here is the 2nd one.
    Even though
    PrintServiceLookup.lookupPrintServices(<DocFlavor>, <AttributeSet>)
    returns nothing when I specify any AttributeSet, I can still print on the default printer, which I get by
    PrintService defServicedefService = PrintServiceLookup.lookupDefaultPrintService();
    but only on a parallel printer (HP Laserjet 4 Plus), either directly attached or over the network. When I try the very same code on a locally USB-attached printer, the printer is obviously reacting, but nothing is printed.
    In case of a Lexmark 730 (an ink printer), the driver even lies, it has printed 100%,
    on a Samsung CLP-510 (a color laser) the ready light flashes twice, that's all.
    The file to be printed has 5 lines and a "0C"X at the end in order to force a page eject at the end.
    I tried it with JDK 1.4.2 and with Java 6, same problem.
    I should mention that I can print that little file out of the editor Textpad without any problem.
    Edited by: eSchobbert on Jan 24, 2008 11:34 AM
    By mistake I entered the same message another time after modifying the Subject instead of replacing the message. Sorry for that. If I knew how to delete it, I would. So please just ignore this one

    Thanks a lot for the quick hint, but it did not help.
    I used BasicPrint.java and PrintJobWatcher.java of the samples for testing.
    Printing a GIF file works both to a parallel printer and a USB printer.
    Then I changed only the DocFlavor from DocFlavor.INPUT_STREAM.GIF to DocFlavor.INPUT_STREAM.AUTOSENSE, and that one works with my parallel printer, but on the USB printer the Ready light flashes twice, that's all.
    The ASCII file must have a "0C"X at the end to force a page eject on the parallel printer
    Maybe it is a matter of the DocFlavor, but which one?
    DocFlavor("application/octet-stream", "java.io.InputStream") works like DocFlavor.INPUT_STREAM.AUTOSENSE.
    DocFlavor.INPUT_STREAM.TEXT_PLAIN_HOST and DocFlavor.INPUT_STREAM.TEXT_HTML_US_ASCII cause sun.print.PrintJobFlavorException, and with DocFlavor.INPUT_STREAM.TEXT_PLAIN_US_ASCII just nothing happens on either printer, not even an error message.
    I am getting the impression that nobody of the developers ever cared for testing such a simple thing as a plain ASCII file under Windows.
    My printers I am using for the tests are
    1. an old parallel-attached HP Laserjet 4 Plus and
    2. a borrowed USB-attached Samsung CLP-510 color laser

  • Printing with Java

    Well, this is the third time I post this message, but I don't seem to find anyone interested in it, so I decided to put on some dukes... :-)
    I have never printed directly with Java, I have rather created pdf files or web-pages. However, Now I might be needing to print directly with Java (I will be using a ticket-printer), so I have done some investigation but I don't seem to find anything that I really like.
    I will be printing tickets, so I might use a simple image and text, only text, no special formatting or something. Any experiences, recommendations?
    Regards.

    This code could be useful for you. I don't know if it is platform independent:
    PrintingUtilities class
    import java.awt.*;
    import javax.swing.*;
    import java.awt.print.*;
    /** A simple utility class that lets you very simply print
    *  an arbitrary component. Just pass the component to the
    *  PrintUtilities.printComponent. The component you want to
    *  print doesn't need a print method and doesn't have to
    *  implement any interface or do anything special at all.
    *  <P>
    *  If you are going to be printing many times, it is marginally more
    *  efficient to first do the following:
    *  <PRE>
    *    PrintUtilities printHelper = new PrintUtilities(theComponent);
    *  </PRE>
    *  then later do printHelper.print(). But this is a very tiny
    *  difference, so in most cases just do the simpler
    *  PrintUtilities.printComponent(componentToBePrinted).
    *  7/99 Marty Hall, http://www.apl.jhu.edu/~hall/java/
    *  May be freely used or adapted.
    public class PrintUtilities implements Printable {
      private Component componentToBePrinted;
    /*  public static void printComponent(Component c, int device) {
        new PrintUtilities(c).print();
      public PrintUtilities(Component componentToBePrinted) {
        this.componentToBePrinted = componentToBePrinted;
      public void print(int device) {
        PrinterJob printJob = PrinterJob.getPrinterJob();
        printJob.setPrintable(this);
        //if(printJob.printDialog())
         try {
            printJob.setPrintService(printJob.lookupPrintServices()[device]);
            printJob.setCopies(1);
            printJob.print();
            //System.out.println(printJob.getPrintService());
          } catch(PrinterException pe) {
            System.out.println("Error printing: " + pe);
      public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
        if (pageIndex > 0) {
          return(NO_SUCH_PAGE);
        } else {
          Graphics2D g2d = (Graphics2D)g;
          g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
          disableDoubleBuffering(componentToBePrinted);
          componentToBePrinted.paint(g2d);
          enableDoubleBuffering(componentToBePrinted);
          return(PAGE_EXISTS);
      /** The speed and quality of printing suffers dramatically if
       *  any of the containers have double buffering turned on.
       *  So this turns if off globally.
      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);
    An Example of use:
    import java.awt.*;
    import java.awt.print.*;
    import java.io.*;
    import javax.swing.*;
    public class PrintExample {
      public static void main(String[] args) {
        JFrame F = new JFrame() {
             public void paint(Graphics g) {
                  g.drawString("Printing a simple line!",20,20);
                  g.drawString("I hope this was useful",20,40);
        PrintUtilities printing = new PrintUtilities(F);
        Object[] array = PrinterJob.getPrinterJob().lookupPrintServices();
        for (int i=0; i<array.length;i++) System.out.println(i+" : "+array);
    System.out.print("Choose Printer device#: ");
    int device = askInteger();
    printing.print(device);
    private static int askInteger() {
         InputStreamReader ip = new InputStreamReader(System.in);
         BufferedReader br = new BufferedReader(ip);
         try {
         while(!false) {
         String read = br.readLine();
         try {
         return Integer.parseInt(read);
              } catch (NumberFormatException ex) {
              System.out.print("Write an integer please > ");
         } catch (IOException exception) {
         return -1;
    Some problems appears when I'm printing pictures.
    Please post a message if you figure out what to do.

  • Problem with java app.

    Hi!
    I did not knew where to put this, but, here it goes:
    We have purchased program based on Java (j2re1.4.2_03) and have experienced problems with running other applications like MS office or IE. The problem is that when the Java app is runing, when opening MS word it sometimes freezes. To unfreez MS word wehave to flash open and hide Java app. We and the developers are at loss. What to do?
    PS: if you know the solution or there is another topic about this question pelease write the link. I could not find smoething similar in Google.

    It is not problem in Word. It is not system (Win XP)
    problem. We had system and word reinstalled and
    nothing changed (on several computers). It shows the
    same symptoms. The problem repeats when opening
    Internet explorer where pages have java scripts
    implemented. On word it happens ocasionally.
    Is there at least some direction to point out to our
    developers. Where could be the root of the problem?I am concerned that I should have to tell you what to have the developers to look at. They are the developers after all this is their problem to solve. I don't mean to be trite here but they will know more about what their program does than anyone here will. And if it is a bug in Java then they need to tell you exactly what it is.
    Anyway their are two possible problem sources here I think.
    1) The program interacts with other programs in some way that is detrimental. I have no idea what this program does because you haven't said. But perhaps for example it's using some Office components in some way and making them upset. (This could also possibly explain the IE problem)
    2) The real issue is that the Java program has a bug whereby it consumes all the CPU resources on the system till such time that it is interacted with or otherwise decides to stop behaving that way. This is a bug in the code for the program. Again though other than this not much more can be said because one would have to see the code for the program. I think it's most likely the cause of your problem.
    Last, yes there are bugs in Java itself that can cause problems but not generally in the matter you describe. Again though even if this should turn out to be one of those times it is up to the developers to identify this.
    You need to have the developers solve this for you. This is good as blind direction is going to get I think.

  • Since recent upgrade, I can't see any of my projects in Shutterfly. Their customer support says it may be issue with Java app and Adobe Flash Player

    see above-- are there known issues with these apps?

    Your Java player (if relevant) is not clearly indicated in your plugins list, and your Flash player is several versions behind. If Apple has an update site, you might check that first. Mozilla's site is here: http://www.mozilla.org/plugincheck/

  • Servlet communication with Java App.

    Hi currently I am working on a project in which with the current design I have to implement a servlet, which can communicate to other servlets and/or Java applications via calling their methods. I know that RMI would be ideal for this however, I do not want to have to setup or configure anything on the server end. Another approach I thought of was to extend the abilities of the servlet and Java app to communicate at the "socket" level, however this can cause issues when communicating through a firewall , I am sure there are workarounds. The last thing that I thought of was having the servlet and application communicate via the HTTP protocol and using HTTPMessage to pass arguments. This approach seems to be the easiest but I would have rather liked to access the Object methods of the two applications rather than send args back and forth. Again as mentioned technologies like RMI and CORBA would probably benifit me. While I don't know too much about CORBA I do know that RMI would require administration work which I would not like to deal with mostly b/c of paperwork and red tape.
    Any advice would be appreciated.
    thank you,
    Peyman m.

    HI,
    I think if your client is RMI, then you need to have RMI server running to answer that client.
    While here you have servlet as your server side component. So, I think in its orginal form servelet can not reply to RMI implelemnted client.
    The best approach I feel for the situatioin described by you is using java based HTTP classes.

  • 6680: Camera access with Java app

    I have no problem with Symbian apps accessing my 6680's camera. AgileMessenger and ShotCode are good examples of this.
    But Java apps, e.g. Shoot&Send and MXit just show a blank white screen when it's supposed to show what the camera is seeing. And when you press Shoot, the app will generate an error. Friends with a 6680 experience the same problem. Is this a known issue? Firmware: v4.04.07, 22-08-05, RM-36

    Hi
    I'm running Shoot&Send successfully on a 6680 with exactly the same firmware version as you have. Be sure that you installed the Series60 version of Shoot&Send.
    Best is you open http://wap.shootsend.com/ with the native phone browser (not Opera), and your device model will be detected correctly.
    Silvano

  • Traping all Events with Java App

    Is it possible to trap all mouse event from Java code even when the java app is not in focus? Lets say a VB app is running and then Java needs to know that that VB app has been clicked?
    ANy useful tip on this?

    Is it possible to trap all mouse event from Java code
    even when the java app is not in focus? No.
    You will have to do this with native code.

  • Memory died, replaced but now can't print with apple apps

    User installable memory died, kernel failures, finally froze, replaced, all better but had to use Diskwarrior to clean up mess on hard drive. Now everything works BUT I can't print from Apple apps. MSOffice updated and prints, Safari, appleworks etc. don't all crash when printing. Cleaned out Printing PPD's, printer defs in Library, reinstalled printers from scratch, disk repair, etc. Even rezapped PRAM again. No luck.
    Seems like this is tied to an apple OS function I haven't found yet.
    Anybody got any ideas before I reinstall the OS?
    thanks

    Thanks Greg,
    Well, bottom line, had to nuke the HD and reinstall the entire system. Everything is fine. Seems the archive and install couldn't deal with the degree of disk confusion caused from the declining memory prior to failure.
    thanks

  • Crappy Fonts with Java Apps .....

    Well having spent days trying to get the fonts sorted out on Archlinux & Openbox, i was finally down to the Interface on Java Apps looking rubbish.
    To resolve this i added the following to ~/.bashrc
    ## Set Java Fonts
    export JAVA_FONTS=/usr/share/fonts/TTF
    export _JAVA_OPTIONS='-Dawt.useSystemAAFontSettings=on'
    Just thought i would Shared with the community, just incase anyone else suffers with the same problems

    whitetimer wrote:
    @ngoonee
    Isn't that where the search facility comes in handy and yes a little tweak such as that would probably be better placed in the wiki ....
    @llawwehttam
    It had me pulling my hair out trying to find a solution, so i am pleased to have helped you out ......
    Search is limited in application, you'd have to be pretty specific in how you search. I remember an old sci-fi novel I read where there were people whose job was merely to craft 'probes' (in the age of google, search terms) into large computer databases. Without those 'probers' nothing of meaning would ever be found, even though all human knowledge existed on those databases.
    In general, if something is meant to be a hint for others, the forum is the worst place to put it. First preference is to patch upstream, second to update the wiki, third to post in the ML, last is forums. Some may disagree on 3rd and 4th, interchanging them, but the first and 2nd options are pretty clear.

  • Problem with java apps

    Hello,
    I'm having a weird problem with some java apps that I'm trying to use (netbeans and frostwire). Looks like they aren't recognizing where the mouse pointer is. If I click Frostwire's window close button, it minimizes instead. The same thing is happening with netbeans, where I can't even access the menus with my mouse. I have the latest jdk and xfce4 packages installed.
    Any hints on how I can fix this?
    Thanks,
    Gustavo

    Do you use beryl ? it causes (or atleast used to cause) some strange behaviour with Java applications

  • Preventing multiple instances of same application - started with "java app"

    I need to ensure that only one instance of an application runs at any given time.
    As far as I know launching it twice with "java appName" will run each in its own memory space, so it is not immediately obvious how to achieve it. I considered using a database entry or environment variable, but those would need to be cleared on exit and therefore be at risk of not being cleared if the application crashes or hangs.
    Is there a Java API call that would allow me to do a check for other instances of the same application... safely?

    Create a ServerSocket on a fixed port number that isn't used by any other application. If you get a BindException, your application is alread running.

  • Maverick don't work properly with java app

    I've upgraded from lion to maverick today and had to install java again. Now one of my java apps starts just like it were before, but can't see any files throught "browse" button. It shows some folders and devices without icons (just title), and don't show other files at all (no icons, no titles). Since this app is critical for my business, I'll sell macbook if I won't fix it. How can I solve it? Can I downgrade to lion?

    rusmanson wrote:
    Yes, it's enabled. Java applet starts, and works, but file browsing through it is not working, though it works in Firefox.
    Found this on another post.  Hopefully it might help:
    To all Java users: remember that when you access a Java site, you are warned that some applets might be insecure. If you allow them to run, Safari might eventually block them anyway, because the applets are not signed or are known to have caused trouble. If you still wish to run them, do this:
    1. Go to the Safari menu and select Preferences.
    2. Click on the Security icon.
    3. Make sure that the "Enable Java Script" and "Allow Java" options are checked.
    4. Click on the "Manage Website Settings" button.
    5. Make sure to choose "Allow Always" from the dropdown menu in the window that appears near the name of the site where the applets reside. If you only choose "Allow", some applets will not run.
    Again, remember that using Java these days may pose a security threat. Whenever that happens, Apple will update the OS and disable Java.

Maybe you are looking for

  • JSF Presentation Error

    I am implementing a custom JSF page as a presentation for a process. To model this implementation, I used the JSF sample found in \ORABPMStudioHome\samples\advanced\JSF-Screenflow_FoodDelivery.exp. I have a module entitle TestModule. This module has

  • Is there a way to block all internet on my teenagers IPhone4s?

    I would like to block internet usage on my teenagers IPhone4S during select times. Is there a way to do this?

  • Please help meee!!!

    I was using my ipod touch 5th gen and then, it didn't turn on anymore and it was fully charged... Basically is dead... I don't know how to turning it on again! I tried to connect my ipod in the PC and it didn't work, I can't do the "recovery mode" be

  • Goldengate extracting from Archive log

    Dear All, We are conducting a replication of Oracle Database. Due to high load on Production server, the client is providing us a near DR database server for extraction. This database server is using Oracle Data Guard to be in Sync with Production se

  • Read System Analysis Data Error - Sol 10 u5 x86

    This morning, smpatch analyze and update via updatemanager will not work, giving this error: "Read System Analysis Data Error There is an error in reading system analysis data. Click on "Check for Updates" to restart a system analysis. If the problem