Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Print simple jpeg image using java

 
Kunal Sapru
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My requirement is to print a simple barcode JPEG image using java (or javascript). My default printer is barcode thermal printer.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you done so far? And please read this.
 
Kunal Sapru
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for not explaining the entire situation.
Actually I'm developing an asset management solution using struts, hibernate, MySQL etc.
The requirement is to attach barcodes to every asset. I searched on google and found barcode4j is being used by many developers.
Now I've used this library to generate barcodes and save the images in jpeg format.
Now I need to print the images directly to my thermal printer i.e. TSC-TTP-244-Plus. Someone with .NET experience suggested me to send .PRN files to the thermal printer but I couldn't find any class in barcode4j for doing the same.

If I right click the JPEG image and use photo printing wizard the image prints just fine (although with little alignment problems but that can be taken care of) but I'm unable to do the same using java.

I also tried the below code but it prints an extremely small image and it spans over 5-6 ribbon labels.
Barcode Thermal printer resolution is : 203 dpi


 
Kunal Sapru
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've found the solution !
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and what was the solution?
 
Kunal Sapru
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

There was a mistake in my process....
There is no need to print image on the barcode labels....
since the resolution of my thermal printer is 203 dpi...the images will not come properly...

Now, I used the Software CD that came with my thermal printer to create a customized label with Header, footer and the barcode...
Then I crated the PRN file by checking 'print to file' option....
After that I used the PRN file as a template and wrote code for creating prn file using my java application....
I created a separate class for this purpose . In this I used a StringBuilder variable and stored the contents of the PRN file...and used String variables for label and text fields....

Then I used the command COPY /B <prn-file path> <printer network path> to print the labels...

This command is working fine from command prompt....
But I'm having problems in executing the same command with RunTime.getRunTime.exec() method...

Error:
java.io.IOException: Cannot run program "COPY": CreateProcess error=2, The system cannot find the file specified

I'm still finding a solution to run this command using java....

Cheers !
Kunal
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
COPY is an inner command of the command shell cmd. Execute "cmd /c COPY ..." instead. This will fire a command shell that will execute (because of the /c) the COPY command.
 
Kunal Sapru
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a TON Sir...
I tried the command with /c attribute and itz working ....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic