Closed evillaq closed 3 years ago
Hi @evillaq Say more about your needs and your environment OS, ide, java version ...
I'm using Netbeans 11, OpenJDK 11 and JavaFx 11 and need a way to send raw text to a pos printer although your solution is way better. The problem is I don't know how to implement your API or if it is posible considering my current setup.
Hi @evillaq , Yes, it is possible. Netbeans have all tools that you need..
The escpos-coffee is maven and runs well on gradle (generally used on android projects) Netbeans have wide possibilities to create projects: maven, gradle, ant ..
maven and gradle is easy, just put the dependencies and run..
ant project is more complex.. how to put maven lib to netbeans ant project? have others, but one solution is: create one directory lib on your machine go to maven central and search by the lib https://search.maven.org/ search by com.github.anastaciocintra, and download the artifact escpos-coffee 4.0.1 download the jar option and download to the lib directory created
If you have other maven dependencies you can download too. For example, you can download flying sauer lib go to maven central and search by the lib https://search.maven.org/ search by org.xhtmlrenderer download flying-sauer-core last version
after download, on your ant fx project, on the libraries (left toolbar) right-click on libraries / add JAR/folder and add the libs downloaded on maven central...
I'm ataching here one complete project with hello escpos on javafx project I hope that it works. see you
I had to port my code to a new Java 8 project because apparently the Java Print Service API is not available from Java 11 or it seems that way. Is there any way to use your API in a Java 11 project? Thanks.
I tested just now, and for me it is working well, escpos-coffee lib is running:
SO: Windows 10 home edition Printer TM-T20 epson on usb Netbeans 12.1 ( donwloaded yesterday - last version)
Jdk | Compatibility |
---|---|
oracle JDK 8 | OK |
OpenJDK 8 | OK |
Oracle JDK 11 | OK |
OpenJDK 11 | OK |
Oracle JDK 8 + JavaFx + netbeans ant | Ok |
Oracle JDK 11 + JavaFx + netbeans ant | Ok |
The lib is compiled on java 8 for for compatibility reasons, but you can re-compile in java 11 with same result.
Then, IMHO you should maintain java 11 and do not downgrade to java 8.
I'm sorry, I'm not explaining myself well. My knowledge of the programming language is still limited and I can't find the way to access the Java Printing Service API via javax.print package when using Java 11.
Hi @evillaq So.. if your trouble is with PrintService on Java11 , follow the answer. I made one project just now using java 11 with PrintService with no errors... Yes, java 11 have javax.print package see java11 doc on this link
maybe is only a detail adjustment on your environment.
If you want, feel free to share your peace of code with error and we try to help you.
Hi @evillaq, I have one question: Do you have your own implementation of PrintService and need to make it works on java 11? Or do you need to make PrintService implementation of escpos-coffee lib works?
I'd started a project in JavaFX (JavaFX 11 and OpenJDK 11 using NetBeans 11) and needed to send raw data to a POS printer. The package javafx.print allow me to print nodes (but its not a pragmatic approach) and allegedly I can use javax.print to print but I can't access the package. I don't know the reason. Do I need to reinstall my entire setup?
Ok, I get your idea. You need simply send raw data to the printer and you aren't talk about escpos-commands but raw and free data. Am I understand right?
Ok you can send data like a Stream to the printer ...
import javax.print.PrintService;
import java.io.IOException;
public class JavaEleven {
public static void main(String[] args) throws IOException {
PrintService printService = PrinterOutputStream.getPrintServiceByName(args[0]);
PrinterOutputStream outputStream = new PrinterOutputStream(printService);
outputStream.write("Hello Raw data\n\n\n\n".getBytes());
outputStream.close();
}
}
simple like that... the class is on https://github.com/anastaciocintra/escpos-coffee/blob/master/src/main/java/com/github/anastaciocintra/output/PrinterOutputStream.java
and you can use for free...
obs, the code above is compiled and running on java 11 without errors...
Hi @evillaq managed to compile your code in java11?
Sorry for the delay... I needed to add this "requires java.desktop;" to the "module-info.java" file in order to access the javax package. Thanks for the help.
Steps to Reproduce
Evidences