tojocky / node-printer

Native node.js printer
1.53k stars 441 forks source link

How to print EMF "error: code: 1804 The specified datatype is invalid" #184

Open xioxin opened 7 years ago

xioxin commented 7 years ago
printer.getSupportedPrintFormats();
// ["RAW", "RAW [FF appended]", "RAW [FF auto]", "NT EMF 1.003", "NT EMF 1.006", "NT EMF 1.007", "NT EMF 1.008", "TEXT", "RAW", "RAW [FF appended]", "RAW [FF auto]", "NT EMF 1.003", "NT EMF 1.006", "NT EMF 1.007", "NT EMF 1.008", "TEXT", "XPS2GDI"]
printer.printDirect({
    data: fs.readFileSync('./pdf-sample-0.emf'),
    printer:printer.getDefaultPrinterName(),
    type: 'NT EMF 1.003',// ????
    success:function(jobID){console.log(jobID);},
    error:function(err){console.log(err);}
});
// TypeError: StartDocPrinterW error: code: 1804, message: 指定的数据类型无效

1804 The specified datatype is invalid. ERROR_INVALID_DATATYPE

printer.getPrinter(printer.getDefaultPrinterName())
//return:
{
    "name": "HP Color LaserJet MFP M277dw (ED37D7)",
    "portName": "USB003",
    "driverName": "HP Color LaserJet 2820 AiO PS Class Driver",
    "printProcessor": "winprint",
    "datatype": "RAW",
    "status": [],
    "statusNumber": 0,
    "attributes": [
        "DO-COMPLETE-FIRST",
        "LOCAL"
    ],
    "priority": 1,
    "defaultPriority": 0,
    "averagePPM": 0
}

How to print EMF?

brtthomp commented 7 years ago

I'm having the same issue. Anyone have any thoughts?

Xosmond commented 6 years ago

@xioxin @brtthomp Did u solve it guys?

sicklittlemonkey commented 6 years ago

I haven't used node or your library, but it looks like getSupportedPrintFormats() gets all the types supported by ALL the print processors (PP) installed. Is that right?

That doesn't mean that the PP of the printer (print job) that you're trying to print to supports it. Each printer (actually each print job) has a PP set, and that PP has a list of supported formats.

So whether 'NT EMF 1.003' is supported depends on the printer's (or print job's) PP.

Cheers, Nick.