• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Print simple jpeg image using java

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79943
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've found the solution !
 
Campbell Ritchie
Marshal
Posts: 79943
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
. . . and what was the solution?
 
Kunal Sapru
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a TON Sir...
I tried the command with /c attribute and itz working ....
 
I like you because you always keep good, crunchy cereal in your pantry. This tiny ad agrees:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic