Add PNG support
parent
3ef7a1f1a1
commit
685c7ae6a0
13
index.js
13
index.js
|
@ -59,7 +59,7 @@ app.get('/', (req, res) => {
|
|||
- Prints IPP attributes
|
||||
- GET /printers/:name/jobs
|
||||
- Prints IPP jobs
|
||||
- POST /print?printer=:name (body: application/pdf)
|
||||
- POST /print?printer=:name (body: application/pdf or image/png)
|
||||
- Prints a PDF
|
||||
- ?printer= printer name or alias (case insensitive)
|
||||
- ?copies= (optional) number of copies (1-10 allowed)
|
||||
|
@ -132,8 +132,13 @@ app.post('/print', bodyParser.raw({ type: '*/*', limit: 10_000_000 }), (req, res
|
|||
if (!body || !body.length) {
|
||||
res.status(400).send("No data received, please send a PDF")
|
||||
return
|
||||
} else if (body.subarray(0, 4).toString() !== "%PDF") {
|
||||
res.status(415).send("Data does not look like a PDF, please send a PDF")
|
||||
}
|
||||
|
||||
const isPDF = body.subarray(0, 4).toString() === "%PDF"
|
||||
const isPNG = body.subarray(0, 8).equals(Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]))
|
||||
|
||||
if (!isPDF && !isPNG) {
|
||||
res.status(415).send("Unsupported media type, only PDF and PNG are supported")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -147,7 +152,7 @@ app.post('/print', bodyParser.raw({ type: '*/*', limit: 10_000_000 }), (req, res
|
|||
// send print job
|
||||
const msg = {
|
||||
"operation-attributes-tag": {
|
||||
"document-format": "application/pdf",
|
||||
"document-format": isPNG ? "image/png" : "application/pdf",
|
||||
},
|
||||
"job-attributes-tag": {
|
||||
"copies": copies,
|
||||
|
|
Loading…
Reference in New Issue