Is it possible to select a printer's media tray?
I'm working with a printer with multiple media trays and so I'd like to select one according to the paper size. Is it possible?
Thanks!
-- pretty good lib btw ;)
You'll want to query your printer's attributes and look for media-source-supported. (run the Get-Printer-Attributes.js script in the examples folder)
Example from one of my printers:
//... bunch of other info cut out
'media-source-supported': [ 'auto', 'manual', 'tray-1', 'tray-2' ],
// ... munch of more info cut out
Then, when you print, you need to specify one of the media options it lists:
var ipp = require('./../ipp');
var PDFDocument = require('pdfkit');
var concat = require("concat-stream");
var doc = new PDFDocument({margin:0});
doc.text(".", 0, 0);
doc.pipe(concat(function (data) {
var printer = ipp.Printer("http://cp02.local.:631/ipp/printer");
var msg = {
"operation-attributes-tag": {
"requesting-user-name": "Bumblebee",
"job-name": "whatever.pdf",
"document-format": "application/pdf"
},
"job-attributes-tag":{
"media-col": {
"media-source": "tray-2"
}
}
, data: data
};
printer.execute("Print-Job", msg, function(err, res){
console.log(err);
console.log(res);
});
}));
doc.end();
Thanks so very much. Got those attributes of my printer and got tray name.
Hey, When I queried printer attributes i got below response from the printer for media-size - "media-size-supported": [ { "x-dimension": 21590, "y-dimension": 27940 }, { "x-dimension": 21590, "y-dimension": 35560 }, { "x-dimension": 18415, "y-dimension": 26670 }, { "x-dimension": 13970, "y-dimension": 21590 }, { "x-dimension": 20990, "y-dimension": 29704 }, { "x-dimension": 16193, "y-dimension": 22895 }, { "x-dimension": 11395, "y-dimension": 16193 }, { "x-dimension": 10971, "y-dimension": 21978 }, { "x-dimension": 10478, "y-dimension": 24130 }, { "x-dimension": 9843, "y-dimension": 19050 } ]
In order to print from a specific tray, I should supply the exact media size dimensions and set that tray to that paper size. Just wanted to know the units for these values. Eg: 21590 x 27940 is letter, what i can calculate is it is equal to 216 * 279 mm roughly when divided by 100.
Could anyone help me with the units for media-size attribute. It is neither mm nor inch. i am guessing it is (size in mm x 100) and is it same kind for all printers ?
See the PWG IPP workgroup page for the definitions of these things.
In this case, the units are hundredths of millimeters (1/2540th of an inch).
PWG 5100.3 (http://ftp.pwg.org/pub/pwg/candidates/cs-ippprodprint10-20010212-5100.3.pdf) is the specification that defines the "media-size" attribute; it defines the "x-dimension" and "y-dimension" member attributes of "media-size" to contain values measured in hundredths of a millimeter.
Thank you both ! As per PWG 5100.3 - A requested media size dimension matches a supported media dimension if it is within an implementation-defined tolerance.
I need to define these dimensions dynamically as i send the prints and i cannot query all the printers which can be used in future. In order to build a generic approach, I am calculating the media size as per the paper size to be used for printing in application and then using it while sending prints. As i understand , if these dimensions match any of the dimensions supported by the printer, it would go to the right tray.(provided someone has set the tray to match that media-size eg letter) And if it is not supported by the printer(not present in media-size-supported), it would try to match the closest dimensions set for the printer ? One more question in this regard is the media-size tolerance , providing media-size dimensions as 21600 x 27900 instead of 21590 x 27940 also works fine, so i dont have to explicitly store these values and (size in mm * 100) would just work fine ?
Your help is very much appreciated as I am new to this area!
@SoniaBalodi12 Providing 21600x27900 may or may not work - some printers have very tight tolerances and will reject those dimensions.
If you only care about the media size (and not the type or source), just use the "media" attribute which is a simple string - na_letter_8.5x11in for US Letter, iso_a4_210x297mm for A4, etc. - and will accomplish the same thing without the need for the complexity of media-col.
@michaelrsweet - what do you mean by printer will reject those dimensions ? It will not print it at all ? Can you help me find these dimensions value (eg : 20990 X 29704 is for A4) , similarly for A1 , A2 etc ?
@SoniaBalodi12 The printer will a) accept the request, choosing the closest size, b) accept the request but ignore your unsupported media size, or c) reject the print job request because the size is not supported. (This is covered in the IPP standards - we are working on a developer-centric book so you don't need to read them all... :)
The accepted (standardized) A4 dimensions are 210x297mm (exactly). The core media sizes are documented in the PWG Media Standardized Names with dimensions and names you can use.
Thank you @michaelrsweet ! It was of great help . I am assuming media is also a MUST support by the printer just like media-size.
@williamkapke This is a follow on query related to the original question. I have a PDF document that has 2 pages with different sizes in it, I'd like the printer to use a specific input tray for page 1 and a different input tray for page 2 to cater for that. It's important that it's submitted a single job so that "print around" type functionality doesn't mess up the order of the output.
Is that possible? I can't seem to find anyone that has achieved this with extensive searching but I may not be understanding what it is I'm trying to search for!
I suspect you may achieve that if you assembly a file with a few PJL command plus the original PDF file content. Then you send it to printer as one job.
Something more or less like this:
- Page 1:
<0x1b>E
<0x1b>%-12345X@PJL
@PJL DEFAULT LCUSTOMPAPERUNITS = MILLIMETERS
@PJL DEFAULT LCUSTOMPAPERWIDTH = {{paperWidth}}
@PJL DEFAULT LCUSTOMPAPERHEIGHT = {{paperHeight}}
@PJL DEFAULT ORIENTATION = {{paperOrientation}}
@PJL SET MEDIASOURCE = {{mediaSource}}
@PJL ENTER LANGUAGE = PDF
[PDF content of page 1.]
<0x1b>%-12345X
- Page 2:
<0x1b>E
<0x1b>%-12345X@PJL
@PJL DEFAULT LCUSTOMPAPERUNITS = MILLIMETERS
@PJL DEFAULT LCUSTOMPAPERWIDTH = {{paperWidth}}
@PJL DEFAULT LCUSTOMPAPERHEIGHT = {{paperHeight}}
@PJL DEFAULT ORIENTATION = {{paperOrientation}}
@PJL SET MEDIASOURCE = {{mediaSource}}
@PJL ENTER LANGUAGE = PDF
[PDF content of page 2.]
<0x1b>%-12345X
I've done something similar but "per document" not "per page", which means my file has the PJL header, then the full PDF content with many pages, and finally the PJL footer. So I take this one file and send it to printer.
Check whether you printer support PJL commands (I guess it does). You can command your printer to do many things with PJL, including change printer settings, etc. You can find a PJL guide over the internet fairly easy.
Well, I hope it helps you!
PS: Keep in mind you must replace {{paperWidth}} with actual value for the property. Same is true for all properties.
Printing different page sizes can be done with IPP using the "overrides" attribute defined in 2003 in PWG 5100.6 (https://ftp.pwg.org/pub/pwg/candidates/cs-ipppageoverride10-20031031-5100.6.pdf).