?
This commit is contained in:
parent
5f1e3b1215
commit
7cc0c363ff
@ -21,15 +21,7 @@ app.post('/print-credentials', async (req, res) => {
|
|||||||
const infoString = Thermal.generateInfo.credentials(username, studentId);
|
const infoString = Thermal.generateInfo.credentials(username, studentId);
|
||||||
|
|
||||||
// Generate the PDF, saved to disk
|
// Generate the PDF, saved to disk
|
||||||
Thermal.generatePdf(infoString).then(result => {
|
Thermal.generatePdf(infoString).catch(e => {
|
||||||
// Print the document
|
|
||||||
Thermal.print().then(result => {
|
|
||||||
res.send('PDF sent to printer successfully.');
|
|
||||||
}).catch(e => {
|
|
||||||
console.error('Failed to start printing process:', e);
|
|
||||||
res.status(500).json({ message: 'Failed to start printing process', error: e.message });
|
|
||||||
});
|
|
||||||
}).catch(e => {
|
|
||||||
console.error(e);
|
console.error(e);
|
||||||
res.status(500).json({ message: 'Error writing PDF file', error: e.message });
|
res.status(500).json({ message: 'Error writing PDF file', error: e.message });
|
||||||
});
|
});
|
||||||
@ -54,15 +46,7 @@ app.post('/print-temp-pw', async (req, res) => {
|
|||||||
const infoString = Thermal.generateInfo.tempPassword(password);
|
const infoString = Thermal.generateInfo.tempPassword(password);
|
||||||
|
|
||||||
// Generate the PDF, saved to disk
|
// Generate the PDF, saved to disk
|
||||||
Thermal.generatePdf(infoString).then(result => {
|
Thermal.generatePdf(infoString).catch(e => {
|
||||||
// Print the document
|
|
||||||
Thermal.print().then(result => {
|
|
||||||
res.send('PDF sent to printer successfully.');
|
|
||||||
}).catch(e => {
|
|
||||||
console.error('Failed to start printing process:', err);
|
|
||||||
res.status(500).json({ message: 'Failed to start printing process', error: err.message });
|
|
||||||
});
|
|
||||||
}).catch(e => {
|
|
||||||
console.error(e);
|
console.error(e);
|
||||||
res.status(500).json({ message: 'Error writing PDF file', error: err.message });
|
res.status(500).json({ message: 'Error writing PDF file', error: err.message });
|
||||||
});
|
});
|
||||||
@ -79,7 +63,19 @@ app.post('/print-mcc', async (req, res) => {
|
|||||||
const infoString = Thermal.generateInfo.maineCC();
|
const infoString = Thermal.generateInfo.maineCC();
|
||||||
|
|
||||||
// Generate the PDF, saved to disk
|
// Generate the PDF, saved to disk
|
||||||
Thermal.generatePdf(infoString).then(result => {
|
Thermal.generatePdf(infoString).catch(e => {
|
||||||
|
console.error(e);
|
||||||
|
res.status(500).json({ message: 'Error writing PDF file', error: e.message });
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Print Error:', e);
|
||||||
|
res.status(500).json({ message: 'Print Error', error: e.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Print Student MaineCC Info
|
||||||
|
app.post('/print', async (req, res) => {
|
||||||
|
try {
|
||||||
// Print the document
|
// Print the document
|
||||||
Thermal.print().then(result => {
|
Thermal.print().then(result => {
|
||||||
res.send('PDF sent to printer successfully.');
|
res.send('PDF sent to printer successfully.');
|
||||||
@ -87,10 +83,6 @@ app.post('/print-mcc', async (req, res) => {
|
|||||||
console.error('Failed to start printing process:', err);
|
console.error('Failed to start printing process:', err);
|
||||||
res.status(500).json({ message: 'Failed to start printing process', error: err.message });
|
res.status(500).json({ message: 'Failed to start printing process', error: err.message });
|
||||||
});
|
});
|
||||||
}).catch(e => {
|
|
||||||
console.error(e);
|
|
||||||
res.status(500).json({ message: 'Error writing PDF file', error: e.message });
|
|
||||||
});
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Print Error:', e);
|
console.error('Print Error:', e);
|
||||||
res.status(500).json({ message: 'Print Error', error: e.message });
|
res.status(500).json({ message: 'Print Error', error: e.message });
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
<button type="submit"
|
<button type="submit"
|
||||||
style="background-color: #1F3C70;"
|
style="background-color: #1F3C70;"
|
||||||
class="w-full text-white py-2 px-4 rounded-md hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-opacity-50">
|
class="w-full text-white py-2 px-4 rounded-md hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-opacity-50">
|
||||||
Print Credentials
|
Generate Credentials
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@ -57,7 +57,7 @@
|
|||||||
<button type="submit"
|
<button type="submit"
|
||||||
id="printTempPw"
|
id="printTempPw"
|
||||||
class="w-full bg-gray-500 text-white py-2 px-4 rounded-md hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-opacity-50 mt-2">
|
class="w-full bg-gray-500 text-white py-2 px-4 rounded-md hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-opacity-50 mt-2">
|
||||||
Print Temp Password
|
Generate Temp Password
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -67,7 +67,7 @@
|
|||||||
<button
|
<button
|
||||||
id="print-mcc"
|
id="print-mcc"
|
||||||
class="w-full bg-indigo-700 text-white py-2 px-4 rounded-md hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-opacity-50 mt-2">
|
class="w-full bg-indigo-700 text-white py-2 px-4 rounded-md hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-opacity-50 mt-2">
|
||||||
Print MaineCC Contact
|
Generate MaineCC Contact
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -84,6 +84,12 @@
|
|||||||
<div id="pdfViewer" class="border border-gray-300 p-4 rounded-md">
|
<div id="pdfViewer" class="border border-gray-300 p-4 rounded-md">
|
||||||
<!-- PDF content will be loaded here -->
|
<!-- PDF content will be loaded here -->
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
id="print"
|
||||||
|
class="w-full bg-indigo-700 text-white py-2 px-4 rounded-md hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-opacity-50 mt-2">
|
||||||
|
Print Information
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
@ -125,6 +131,23 @@
|
|||||||
fetch('/print-mcc', {
|
fetch('/print-mcc', {
|
||||||
method: 'POST'
|
method: 'POST'
|
||||||
})
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (response.ok) {
|
||||||
|
loadPDF();
|
||||||
|
return response.text(); // or .json() if your server returns JSON
|
||||||
|
} else {
|
||||||
|
throw new Error('Failed to send print request');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(message => alert(message))
|
||||||
|
.catch(error => alert('Error: ' + error));
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById('print').addEventListener('click', (event) => {
|
||||||
|
// Send a POST request with the form data to the server
|
||||||
|
fetch('/print', {
|
||||||
|
method: 'POST'
|
||||||
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
return response.text(); // or .json() if your server returns JSON
|
return response.text(); // or .json() if your server returns JSON
|
||||||
@ -157,6 +180,7 @@
|
|||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
|
loadPDF();
|
||||||
return response.text(); // or .json() if your server returns JSON
|
return response.text(); // or .json() if your server returns JSON
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Failed to send print request');
|
throw new Error('Failed to send print request');
|
||||||
@ -181,6 +205,7 @@
|
|||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
|
loadPDF();
|
||||||
return response.text(); // or .json() if your server returns JSON
|
return response.text(); // or .json() if your server returns JSON
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Failed to send print request');
|
throw new Error('Failed to send print request');
|
||||||
|
Loading…
Reference in New Issue
Block a user