'What do I have to do in order to print Blob data types (PDF) retrieved from a webserver in Node?
I don't understand how to handle Blob-Files. I have an Electron application where I retrieve a pdf from a webserver. I want to silently print the pdf retrieved from the webserver using the printer name stored in printer. I tried different solutions including different node modules but it does not work and I am not quite getting what to do.
I would appreciate your help!
axios.get("getPdf", {responseType: "blob",headers: {'Accept': 'application/pdf'}).then(res => {
let printer = printer_settings["printFormatX"];
// I am not quite sure what to do now
// I used different modules like 'pdf-to-printer' but it is not working like expected
// I am generally unsure what to do with the retrieved pdf in order to print it
})
Solution 1:[1]
I solved it this way:
I create a temporary file, then write the response data to it in order to then print it with the module pdf-to-printer
axios.get("getPdf", {responseType: "arraybuffer",headers: {'Accept': 'application/pdf'}).then(res => {
let printer = printer_settings["printFormatX"];
let tmpFile = __dirname + "/tmp_pdf.pdf"
fs.writeFileSync(tmpFile, res.data, {encoding: "binary"});
print(tmpFile, res.data, {printer: printer});
})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Invader |
