This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

How to print barcode labels using barcode4j?

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Currently I’m using Barcode4J open source library for barcode generation. This library has some functions through which I was able to create jpeg image of the barcode, but for printing the barcode I need a .prn file to send to the thermal printer. I know the command to do this and we can use that in our java application. But I couldn’t find any function to create a .prn file using barcode4j library.
 
Sheriff
Posts: 21802
104
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not Swing related. Moving to Other Open Source Projects.
 
Kunal Sapru
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Found the solution !
 
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you share this with us? Would be useful for others
 
Kunal Sapru
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Barcode4J is very useful in generating barcode and creating images in various formats.....

Now for printing the barcode labels I was trying to print jpeg images to the thermal printer...
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 was working fine from command prompt....
But I was 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


Then Rob Prime helped me out and suggested the following command....
cmd /c COPY /b <prn-file-path> <printer-network-path>

I tried it and everything is now working

Cheers !
Kunal
 
Martijn Verburg
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great stuff! Thanks for sharing
 
mooooooo ..... tiny ad ....
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!