Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print Job delay when using IPP for Node JS

I'm using IPP (and CUPS) with Node JS to print labels (DYMO Labelwriter 450 Turbo's) from our child check-in system. I need to print differing quantities (var qty) of each label depending on which room the child is in (1-3). Currently I'm creating a new IPP print job for each label - but there is a few seconds' delay between printings.

Is there a way to pass quantities to IPP with each job to eliminate the delay? Or perhaps pass multiple of the same .pdf into a single job?

Vars pdf(the generated label - using a .pdf template), qty(quantity of label that need to print) and pid(Printer ID of which printer to print to) are passed to the following bit of code:

function print(qty, pid, first, last, gender, room, notes, notesr, timestamp, age, grade, code) {

    fs.readFile('label.pdf', 'utf-8', function (err, pdf) {

        pdf = pdf.toString();
        pdf = pdf.replace('<FIRST>', first).replace('<LAST>', last).replace('<GENDER>', gender).replace('<ROOM>', room).replace('<NOTES>', notes).replace('<NOTESON>', notesr).replace('<TIMESTAMP>', timestamp).replace('<AGE>', age).replace('<GRADE>', grade).replace('<CODE>', code);

        if (err)
            throw err;

        var printer = ipp.Printer('http://127.0.0.1:631/printers/DYMO_'+pid);
        var file = {
            'operation-attributes-tag':{
                'requesting-user-name': 'Test User',
                'job-name': 'My Test Job',
                'document-format': 'application/pdf'
            },
            data: new Buffer(pdf, 'binary')
        };

        for (var i = 0; i < qty; i++) {
            printer.execute('Print-Job', file, function (err, res) {
                console.log('Printed: '+res.statusCode)
            })
        }
    });
}

Update:

It looks like my problem is that CUPS waits for the printer to return to "idle" before it begins processing the next job - thus creating the delay between jobs. An option, waitprinter=false needs to be added to the DeviceURI to bypass the wait.

I've tried adding it to the DeviceURI in /etc/cups/printers.conf with no avail. I've tried adding it to the Printer object url like:

var printer = ipp.Printer('http://127.0.0.1:631/printers/DYMO_'+pid+'?waitprinter=false');

Which errors that printer cannot be found. How do I use this option with IPP?

Update #2:

Out of urgency, I created a work-around using pdfkit to generate multi-page label pdf's on the fly and sending all of the family's labels as a single print job.

like image 487
Josiah Avatar asked Nov 08 '13 19:11

Josiah


1 Answers

You tried adding it to the DeviceURI in /etc/cups/printers.conf on the CUPS host?

If you did it by simply editing that file while CUPS was running, it will not work. Normally, printers.conf is not meant for directly editing. It does state this in its first lines (screaming '# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING').

1.

The recommended way to change the printer configuration permanently is by using the lpadmin command on the CUPS server:

lpadmin -h cupsserver -P printername -E -v ipp://11.2.13.14:631/waitprinter=false

The CUPS server will then tell the CUPS clients that this printer is accessible to them via

http://cupsserver:631/printername

(Should you really need to directly edit the printers.conf, you have to stop the CUPS daemon first, make your edit, and then restart cupsd.)

2.

To change the printer configuration temporarily (for the next job only), you can pass the option with the lp command when sending the job:

lp -d printername -o waitprinter=false myjob.pdf

Translated into your problem space, this solution means:

  1. Do not try to change the printer name in your var printer = ipp.Printer ... statement.

  2. Instead rather change operation-attributes-tag and add a 'waitprinter': 'false' statement there.

like image 198
Kurt Pfeifle Avatar answered Oct 06 '22 01:10

Kurt Pfeifle