Basics of credential printer
This commit is contained in:
parent
5869456b6a
commit
1fb025a603
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1,3 @@
|
||||
mccs-it/data
|
||||
node_modules
|
||||
package-lock.json
|
45
mccs-it/thermal/app.js
Normal file
45
mccs-it/thermal/app.js
Normal file
@ -0,0 +1,45 @@
|
||||
const express = require('express');
|
||||
const ThermalPrinter = require('node-thermal-printer').printer;
|
||||
const Types = require('node-thermal-printer').types;
|
||||
const printer = require('printer');
|
||||
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
|
||||
// Middleware to serve static files (HTML)
|
||||
app.use(express.static('public'));
|
||||
|
||||
// Setup thermal printer
|
||||
const thermalPrinter = new ThermalPrinter({
|
||||
type: Types.STAR, // Replace with the correct printer type (e.g., STAR, EPSON)
|
||||
interface: 'printer:TSP100', // Printer name as recognized by the OS
|
||||
driver: printer, // Use node-printer driver
|
||||
});
|
||||
|
||||
// Test print function
|
||||
app.post('/test-print', async (req, res) => {
|
||||
try {
|
||||
// Initialize the printer
|
||||
const isConnected = await thermalPrinter.isPrinterConnected();
|
||||
if (!isConnected) {
|
||||
return res.status(500).json({ message: 'Printer not connected' });
|
||||
}
|
||||
|
||||
// Print a test line
|
||||
thermalPrinter.println('This is a test print');
|
||||
thermalPrinter.cut();
|
||||
|
||||
// Execute the print job
|
||||
await thermalPrinter.execute();
|
||||
|
||||
res.json({ message: 'Print Success' });
|
||||
} catch (error) {
|
||||
console.error('Print Error:', error);
|
||||
res.status(500).json({ message: 'Print Error', error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Start the server
|
||||
app.listen(port, () => {
|
||||
console.log(`Server running at http://localhost:${port}`);
|
||||
});
|
20
mccs-it/thermal/package.json
Normal file
20
mccs-it/thermal/package.json
Normal file
@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "thermal",
|
||||
"version": "1.0.0",
|
||||
"description": "Web portal to print to a TSP100 thermal printer.",
|
||||
"main": "app.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.vfsh.dev/voidf1sh/custom-scripts"
|
||||
},
|
||||
"author": "Skylar Grant",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"express": "^4.19.2",
|
||||
"node-thermal-printer": "^4.4.3",
|
||||
"printer": "^0.4.0"
|
||||
}
|
||||
}
|
21
mccs-it/thermal/public/index.html
Normal file
21
mccs-it/thermal/public/index.html
Normal file
@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Test Print</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Thermal Printer Test</h1>
|
||||
<button id="testPrintBtn">Test Print</button>
|
||||
|
||||
<script>
|
||||
document.getElementById('testPrintBtn').addEventListener('click', () => {
|
||||
fetch('/test-print', { method: 'POST' })
|
||||
.then(response => response.json())
|
||||
.then(data => alert(data.message))
|
||||
.catch(error => alert('Error: ' + error));
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user