8 Replies Latest reply: Sep 18, 2009 3:45 PM by 807580 RSS

    How to send a .prn file to the printer?

    807580
      Hi Guys,

      my question is pretty simple. How can I send a .prn to a printer? Would you have a code sample?

      I have examples showing how to print squares, .ps files, etc... but the problem is... I have only .prn files generated from many sources (powerpoint, excel, ms-word, ...).


      Thank in advance!
        • 1. Re: How to send a .prn file to the printer?
          807580
          Hi tzwick,

          It is not a good idea to generate .prn files from documents as such files are printer dependant. If you have 2 different printers, you'll have 2 different .prn files for the same document.
          Also, there's no direct way to print a .prn file in Java using its print API's; you have to launch a DOS command to print such file via the [*Runtime*|http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html] & [*Process*|http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Process.html] API's.

          Here's the command to print a .prn file :
          copy /b some_file.prn > LPT1
          • 2. Re: How to send a .prn file to the printer?
            Darryl Burke
            copy /b some_file.prn > LPT1
            Um, nowadays most printers aren't on LPT1 -- they connect via USB.

            @OP: Go through these links:
            [http://www.technipages.com/send-prn-file-to-printer.html]
            [http://forums.sun.com/thread.jspa?threadID=5393336]

            db
            • 3. Re: How to send a .prn file to the printer?
              807580
              DarrylBurke wrote:
              Um, nowadays most printers aren't on LPT1 -- they connect via USB.
              Indeed, but there're still a lot of old fashioned people like me. ;)
              • 4. Re: How to send a .prn file to the printer?
                807580
                Hi Chicon,

                thank you a lot for such quick answer!

                But I still have some questions....

                --> Could I send it to a network printer? Sometimes I need to send that .prn to the port 9100 of the printer and sometimes to LPR port 515. How can I do it?

                --> If I can do it, is there any java dialog that I can use to select a printer on the network. I would earn some points with my user if I do that.


                Thank you again.

                I hope you can help me!
                • 5. Re: How to send a .prn file to the printer?
                  807580
                  --> Could I send it to a network printer? Sometimes I need to send that .prn to the port 9100 of the printer and sometimes to LPR port 515. How can I do it?
                  As explained above, you'll have to use DOS commands via Runtime & Process API's.
                  If you want to send your .prn file to a network printer, you have to do something like this :
                  net use LPT1: \\your_server\your_printer
                  copy /b your_file.prn LPT1: 
                  For the LPR related question, I can't answer you.
                  --> If I can do it, is there any java dialog that I can use to select a printer on the network. I would earn some points with my user if I do that.
                  The following code will give the user the possibility to select the printer.
                  PrinterJob pj = PrinterJob.getPrinterJob();
                  pj.printDialog();
                  See the [*API documentation*|http://java.sun.com/javase/6/docs/api/java/awt/print/PrinterJob.html]
                  • 6. Re: How to send a .prn file to the printer?
                    Darryl Burke
                    tzwick, a word of advice: if you don't intend to reward Dukes for helpful answers, just don't assign Dukes to the thread.

                    10 more for the forum pickle jar?

                    db
                    • 7. Re: How to send a .prn file to the printer?
                      807580
                      Sorry. I set the answer above as helpful, I was thinking that was the correct way to grant those points to the right person.... I will try again
                      • 8. Re: How to send a .prn file to the printer?
                        807580
                        I was going to suggest trying the JDIC Desktop.print function, but that doesn't seem to be able to select printers either. https://jdic.dev.java.net/nonav/documentation/javadoc/jdic/org/jdesktop/jdic/desktop/Desktop.html#print(java.io.File)