Я пытаюсь печатать с помощью команд ESC/P, используя принтер этикеток Brother P750W. Я использую P-touch Editor 5.4, принтер работает хорошо, но когда я пытаюсь создать собственные этикетки из кода Java, принтер не работает, похоже, что он подключен к принтеру, но ничего не происходит. Что я могу попробовать сейчас?
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 org.zyx.common.cli.Command;
import org.zyx.common.cli.CommandException;
public class CommandVialLabelPrintBrotherTest implements Command {
@Override
public void execute() throws CommandException {
try {
// Your ESC/P command to print a label with barcode
PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null);
PrintService brotherPrinter = null;
for (PrintService printer : printServices) {
System.out.println("Printer: " + printer.getName());
}
// Find Brother PT-P750W
for (PrintService printer : printServices) {
System.out.println("Printer: " + printer.getName());
if (printer.getName().equalsIgnoreCase("Brother PT-P750W (Copy 1)")
|| printer.getName().equalsIgnoreCase("Brother PT-P750W")) {
brotherPrinter = printer;
}
}
if (brotherPrinter == null) {
System.out.println("Brother PT-P750W not found!");
return;
}
// Open a stream to send raw data to the printer
DocPrintJob job = brotherPrinter.createPrintJob();
String escCommands = "\u001B@" + // ESC @ - Initialize printer
"\u001Bi r 12" + // ESC i r 12 - Set label width to 12mm (0.47")
"\u001Bi L" + // ESC i L - Start label layout
"\u001Bi S 24" + // ESC i S 24 - Set text size to 24 points
"Hello Printer" + // The text to print
"\u001Bi d 1" + // ESC i d 1 - Print the label
"\u001Bi Z"; // ESC i Z - Cut the label (optional)
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
Doc doc = new SimpleDoc(escCommands.getBytes(), flavor, null);
// Print the document
job.print(doc, null);
System.out.println("Raw ESC/P data sent to printer!");
} catch (PrintException e) {
e.printStackTrace();
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... -java-docp
Принтер этикеток Brother P750W не работает, получая команды esc/p из Java DocPrintJob ⇐ JAVA
Программисты JAVA общаются здесь
1729778262
Anonymous
Я пытаюсь печатать с помощью команд ESC/P, используя принтер этикеток Brother P750W. Я использую P-touch Editor 5.4, принтер работает хорошо, но когда я пытаюсь создать собственные этикетки из кода Java, принтер не работает, похоже, что он подключен к принтеру, но ничего не происходит. Что я могу попробовать сейчас?
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 org.zyx.common.cli.Command;
import org.zyx.common.cli.CommandException;
public class CommandVialLabelPrintBrotherTest implements Command {
@Override
public void execute() throws CommandException {
try {
// Your ESC/P command to print a label with barcode
PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null);
PrintService brotherPrinter = null;
for (PrintService printer : printServices) {
System.out.println("Printer: " + printer.getName());
}
// Find Brother PT-P750W
for (PrintService printer : printServices) {
System.out.println("Printer: " + printer.getName());
if (printer.getName().equalsIgnoreCase("Brother PT-P750W (Copy 1)")
|| printer.getName().equalsIgnoreCase("Brother PT-P750W")) {
brotherPrinter = printer;
}
}
if (brotherPrinter == null) {
System.out.println("Brother PT-P750W not found!");
return;
}
// Open a stream to send raw data to the printer
DocPrintJob job = brotherPrinter.createPrintJob();
String escCommands = "\u001B@" + // ESC @ - Initialize printer
"\u001Bi r 12" + // ESC i r 12 - Set label width to 12mm (0.47")
"\u001Bi L" + // ESC i L - Start label layout
"\u001Bi S 24" + // ESC i S 24 - Set text size to 24 points
"Hello Printer" + // The text to print
"\u001Bi d 1" + // ESC i d 1 - Print the label
"\u001Bi Z"; // ESC i Z - Cut the label (optional)
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
Doc doc = new SimpleDoc(escCommands.getBytes(), flavor, null);
// Print the document
job.print(doc, null);
System.out.println("Raw ESC/P data sent to printer!");
} catch (PrintException e) {
e.printStackTrace();
}
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79122278/brother-p750w-label-printer-doesnt-work-receiving-esc-p-commands-from-java-docp[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия