• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

printer not calling through this program..

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.awt.Graphics;
import java.awt.PageAttributes;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.print.attribute.Attribute;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.Copies;
import javax.print.attribute.standard.MediaSize;
import javax.print.attribute.standard.MediaSizeName;

public class PrintImage {
static public void main(String args[]) throws Exception {



PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet() ;
pras.add(new Copies(1));

PrintService pss[] = PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.GIF, pras);
if (pss.length == 0)
throw new RuntimeException("No printer services available.");
PrintService ps = pss[0];
System.out.println("Printing to " + ps);
DocPrintJob job = ps.createPrintJob();
String s = "<STX>L<CR>"; // Print content of buffer, 1 label

// String s="oooooooo";




// Print content of buffer, 1 label

// String s="oooooooo";
byte[] by = s.getBytes();


Doc doc = new SimpleDoc(by, DocFlavor.BYTE_ARRAY.AUTOSENSE, null);

job.print(doc, pras);


/*String code="130000002000000BAR CODE N : UPC5<CR>";
BufferedImage img=new BufferedImage(100,100,BufferedImage.TYPE_INT_RGB);
Graphics g=img.getGraphics();
// g.setColor(Color.BLACK);
g.drawString(code,15,15);
ByteArrayOutputStream outstream=new ByteArrayOutputStream();
//ImageIO.write( img, "jpg", outstream);
byte[] buf=outstream.toByteArray();
String value=new String(buf);
System.out.println("Found printer: " + sPrinterName);
DocPrintJob job = psZebra.createPrintJob();
// Prepare string to send to the printer
String s = "<STX>L<CR>"; // Print content of buffer, 1 label

// String s="oooooooo";
byte[] by = s.getBytes();
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet() ;

MediaSizeName m = MediaSizeName.PERSONAL_ENVELOPE;
pras.add(m);
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
System.out.println(flavor.getMimeType());

//MIME type = "application/octet-stream";
//print data representation class name = "[B" (byte array).

System.out.println("Before callling ************");
Doc doc = new SimpleDoc(by, flavor, null);

System.out.println("Ready to print");

System.out.println(doc.getPrintData()+"---------");

job.print(doc, pras);

*/







}
}



we are using.. argox printer
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sureshreddy, please TellTheDetails and UseCodeTags. It will be easier for us to help you.
 
sureshreddy govindu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, i am using argox os-2140 barcode printer . i don't no how to pass barcode commands through java program. tell me how to access the printer . i am using above program is print the barcode. but it is not work. it's needed. below program is working cannon printer . but it's not working with argox os-2140 barcode printer .
thanks a lot for reply.



 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I guess the barcode printer uses special drivers. If the manufacturers didn't provide a Java API, you will have to use native code to access the barcode printer driver.

There seems to be a download here for a command library. Maybe it comes with a readme or a manual. Take a look:
http://www.argox.com/content.php?sno=0000033&P_ID=82
 
sureshreddy govindu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks to reply,

how to use this commands through java program. please send me small example using printer commands . already i read this commands but how to use through java program.
we are using argox os-2140 printer(usb port) .
 
sureshreddy govindu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

send me one small program for java how to send barcode string to barcode printer .
 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need Java Native Interface (JNI) to access the functions in the DLLs provided by the manufacturer. The readme will tell you what functions exists and how they work.

Google Java Native Interface or JNI to find a tutorial on how you can do this.
 
sureshreddy govindu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi thanks to reply., How to use JNA library to communicate with barcode printer, if possible send me an example.

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Platform;

/** Simple example of JNA interface mapping and usage. */
public class HelloWorld1 {

// This is the standard, stable way of mapping, which supports extensive
// customization and mapping of Java to native types.
public interface CLibrary extends Library {
CLibrary INSTANCE = (CLibrary)
Native.loadLibrary((Platform.isWindows() ? "msvcrt" : "c"),
CLibrary.class);

void printf(String format, Object... args);
}

public static void main(String[] args) {
CLibrary.INSTANCE.printf("Hello, World\n");
for (int i=0;i < args.length;i++) {
CLibrary.INSTANCE.printf("Argument %d: %s\n", i, args[i]);

}
}
}
 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you read a tutorial on JNI/JNA? Have you figured out how to call functions in DLLs through JNI/JNA? Have you read the Readme that came with the command library?

Do all of these, then try to write some code for yourself. If you run into problems, post your code and explain where you are getting stuck and maybe someone can help you out. Don't forget to UseCodeTags or you will find it hard to receive help.
 
sureshreddy govindu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi thanks to reply,



i am calling dll with java for using native api. below exception occur


Exception in thread "main" java.lang.UnsatisfiedLinkError: Form1.A_GetUSBBufferLen()I
at Form1.A_GetUSBBufferLen(Native Method)
at Form1.main(Form1.java:73)

using following code.

 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your private static native int A_GetUSBBufferLen() method is not implemented in any of the DLLs you're loading.
 
sureshreddy govindu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, thanks to reply


i have three dll file i.e related to those method.(which methods i used), i am accessing those method from java class(above). how to access that dll file through java file. give me one example how to access the method of dll with java (os)
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Who created these DLLs? Does any of them contain the JNI implementation of the native methods in your class? Because you can't just load any DLL and call the functions from it - you need either JNI or JNA as a wrapper. The difference is that with JNI you write the code in C or C++ (mostly) that forms a bridge between the Java code and the DLLs, and with JNA you write similar code but in Java. JNA takes care of the translation from Java code to JNI code.
 
sureshreddy govindu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks to reply,

those dll's supplyed by argox os-2140 barcode printer company. these dll's used for implementing the program for barcode generation.
first --> register dll's with windows os(system 32 folder).
after i used these dll's through program.



 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, like Rob said, you first have to create a wrapper around the DLLs supplied by the vendor. Java by itself does not know how to call functions in a DLL.

Create a JNI or JNA wrapper for the DLL you received. Then your Java code can either delegate to the JNI native code, or call the JNA methods. JNA might be easier, so find a JNA tutorial that explains how you can call methods from a DLL.
 
sureshreddy govindu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks to reply,

it was resolved, i got it with JNA . Thanks a lot ,

now i am facing another problem , deployed the application in the server , after deploying the application when access the application from client machine , the application see the printer on the server machine.., i want to access the application from client machine the application search the barcode printer from client machine only., (present it's seems server machine),

i used the code for accesing the usb printer is below

CLibrary.INSTANCE2.A_GetUSBBufferLen();

int nUSBDataLen;
byte[] pbuf;



nUSBDataLen=CLibrary.INSTANCE2.A_GetUSBBufferLen();
// nUSBDataLen = A_GetUSBBufferLen()+1;
pbuf = new byte[nUSBDataLen];
CLibrary.INSTANCE2.A_EnumUSB(pbuf);
CLibrary.INSTANCE2.A_CreateUSBPort(1);

 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't do this. You need an application on the client's machine that uses the printer, and then sends the data to your server. It would be a huge security risk if server applications could run hardware on clients by themselves.
reply
    Bookmark Topic Watch Topic
  • New Topic