This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JAVA Printing Help

 
Nagaraj Pattar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody share your java expertise with me.. ??

I have a java program which uses PrintService API to create a PrintJob for printing text content. I am trying to make this program to have a typewriter effect.

Confused, Let me explain, As soon as you type a key, it should appear on the page @ the printer. The next letter should appear next to the previous letter and so on. There should not be any buffering, for eg., read an entire line and then print it on the paper.

I have tried my best but the problem is: As soon as type next letter, the printer (Print Service ) resets the printer page. The printer then Prints the next letter in the next page.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15436
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

I must admit I don't know much about the Java printing API, but I think that what you want is not really possible.

What kind of printer are you using? If it's an inkjet printer or a laser printer, then it's most likely not going to work. These printers do not print a letter each time when the computer sends one character to the printer. Rather, the computer sends the information for a whole page to the printer, which the printer then processes and prints. I doubt that it is possible to print letter by letter on such printers.
 
Nagaraj Pattar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its similar to a dot matrix printer where you have infinite length paper source.


My other requirement is little bit different:

Okay, Assume that the program is sending data to the printer page by page.. Everytime you request for printing the printer repositions the page by moving the page inward / outward.

Is it possible to avoid ? The printer should start printing the next page assuming that the page positioning is already done / manually done..

??? Please help
 
Maneesh Godbole
Saloon Keeper
Posts: 11092
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try writing to LPT1
If I remember correctly that is the default parallel printer port (at least on windoze) and you can open a "stream" to it, treating it just like any other file.

Disclaimer: Things might have changed over the years. Way back around 2003, I had designed a hardware which would accept characters at runtime and the hardware would convert them to Braille. This hardware was attached to the LPT1 port and I remember having code which would communicate to the port using FileWriter. This was using java 1.2
 
Nagaraj Pattar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Maneesh,

thanks for your reply, I have tried that as well. nothing is in my favor.. The printer still writes the new character in a new page.



is my code, where ArrayList contains a list of String objects. This code constructs a temporary file and then the file is given as input to the printer job.

once the file is printed on to the printer, next call to the same method, readjusts the paper by pulling inside before printing..

I want to avoid the readjusting of the paper.. I would like the printer to continue to print from the same position without pulling the paper inside..

Any attributes we have to pass to the print service api ?
 
Maneesh Godbole
Saloon Keeper
Posts: 11092
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In future, while posting code, please UseCodeTags. I have edited your original post this time. As you can see the code tags make the code much more easier to read and understand.

I have tried that as well. nothing is in my favor.. The printer still writes the new character in a new page.

Which part of the code you posted tries to print to LPT1?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic