File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Print simple jpeg image using java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Print simple jpeg image using java" Watch "Print simple jpeg image using java" New topic
Author

Print simple jpeg image using java

Kunal Sapru
Greenhorn

Joined: Jul 08, 2010
Posts: 9
My requirement is to print a simple barcode JPEG image using java (or javascript). My default printer is barcode thermal printer.


SCJP 5, SCWCD 5
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
What have you done so far? And please read this.
Kunal Sapru
Greenhorn

Joined: Jul 08, 2010
Posts: 9
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

Joined: Jul 08, 2010
Posts: 9
I've found the solution !
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
. . . and what was the solution?
Kunal Sapru
Greenhorn

Joined: Jul 08, 2010
Posts: 9
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

Joined: Oct 27, 2005
Posts: 19543
    
  16

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Kunal Sapru
Greenhorn

Joined: Jul 08, 2010
Posts: 9
Thanks a TON Sir...
I tried the command with /c attribute and itz working ....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Print simple jpeg image using java
 
Similar Threads
Need Help in barcode display
generate barcode image
How to print barcode labels using barcode4j?
Printing API Question
Java Advanced Imaging (JAI) Question