Anonymous
Термопечать Electronjs, не печатает
Сообщение
Anonymous » 20 дек 2025, 21:45
Вот простая программа, которую я создал на Electron.js. Предполагается регистрировать товары и распечатывать их штрих-коды. Но после настройки node-thermal-printer и всего остального нажатие кнопки «Печать» фактически ничего не распечатывает в реальной жизни, а просто сообщает, что штрих-код успешно напечатан.
Код: Выделить всё
async connectPrinter(printerName) {
try {
console.log('Connecting to printer:', printerName);
const printers = await this.detectPrinters();
const exists = printers.some(p => p.name === printerName);
if (!exists) {
return {
success: false,
message: 'Printer not found',
error: `Printer "${printerName}" not found in system`
};
}
// Initialize thermal printer using node-thermal-printer
this.printer = new ThermalPrinter({
type: PrinterTypes.EPSON,
interface: printerName,
characterSet: CharacterSet.PC852_LATIN2,
lineCharacter: '═',
width: 42,
removeSpecialCharacters: false
});
// Test connection with a simple command
await this._testPrinterConnection();
this.connectedPrinterName = printerName;
console.log('✓ Successfully connected to:', printerName);
return {
success: true,
message: `Connected to: ${printerName}`,
printer: printerName
};
} catch (error) {
console.error('Printer connection error:', error);
this.printer = null;
return {
success: false,
message: 'Connection failed',
error: error.message
};
}
}
Если вы хотите более подробно изучить код, вот Github проекта.
Подробнее здесь:
https://stackoverflow.com/questions/798 ... t-printing
1766256358
Anonymous
Вот простая программа, которую я создал на Electron.js. Предполагается регистрировать товары и распечатывать их штрих-коды. Но после настройки node-thermal-printer и всего остального нажатие кнопки «Печать» фактически ничего не распечатывает в реальной жизни, а просто сообщает, что штрих-код успешно напечатан. [code]async connectPrinter(printerName) { try { console.log('Connecting to printer:', printerName); const printers = await this.detectPrinters(); const exists = printers.some(p => p.name === printerName); if (!exists) { return { success: false, message: 'Printer not found', error: `Printer "${printerName}" not found in system` }; } // Initialize thermal printer using node-thermal-printer this.printer = new ThermalPrinter({ type: PrinterTypes.EPSON, interface: printerName, characterSet: CharacterSet.PC852_LATIN2, lineCharacter: '═', width: 42, removeSpecialCharacters: false }); // Test connection with a simple command await this._testPrinterConnection(); this.connectedPrinterName = printerName; console.log('✓ Successfully connected to:', printerName); return { success: true, message: `Connected to: ${printerName}`, printer: printerName }; } catch (error) { console.error('Printer connection error:', error); this.printer = null; return { success: false, message: 'Connection failed', error: error.message }; } } [/code] Если вы хотите более подробно изучить код, вот Github проекта. Подробнее здесь: [url]https://stackoverflow.com/questions/79851910/electronjs-thermal-printing-is-not-printing[/url]