settings (GET)
{server}/api/v1/printer/settings/{deviceName}/{units}
Description
Returns device settings for a print device that HTML/PDF/RAW content will be printed to (paper size, source etc.).
Where a value of 0 corresponds to 'Default' (eg. for collate or duplex), the setting will be taken from the Internet Explorer settings on the machine providing ScriptX.Services.
Applies to:
- ScriptX.Services for Windows PC v2.19 and later.
Request parameters
deviceName (string, required)
units (integer, optional): 0 = Default, 1 = Inches, 2 = Mm
- deviceName (string, optional)
-
Name of the printer/device available to the ScriptX.Services device (Windows PC/Windows Server), or 'default' for the service default printer.
- units (integer, optional)
- Option that specifies the measurement units to be used for margin settings, header and footer heights etc. Value can be 0 (Default), 1 (inches) or 2 (mm).
Response model
DeviceSettings {
printerName (string, optional),
paperSizeName (string, optional),
paperSourceName (string, optional),
collate (integer, optional): 0 = Default, 1 = True, 2 = False,
copies (integer, optional),
duplex (integer, optional): 0 = Default, 1 = Simplex, 2 = Vertical, 3 = Horizontal,
paperPageSize (Size, optional),
unprintableMargins (Margins, optional),
status (integer, optional),
port (string, optional),
attributes (integer, optional),
serverName (string, optional),
shareName (string, optional),
location (string, optional),
isLocal (boolean, optional),
isNetwork (boolean, optional),
isShared (boolean, optional),
isDefault (boolean, optional),
bins (Array[string], optional),
forms (Array[string], optional)
}
Size {
width (number, optional),
height (number, optional)
}
Margins {
left (string, optional),
top (string, optional),
bottom (string, optional),
right (string, optional)
}
DeviceSettings:
- printerName (string, optional)
- Name of the printer/device on the server. If 'default' was used for the deviceName parameter this will be the default server printer.
- paperSizeName (string, optional)
- Current paper size setting for the device.
- paperSourceName (string, optional)
- Current paper source setting (or bin) for the device (eg. 'Upper tray').
- collate (integer, optional)
- Current collation setting for the device. Value can be 0 (Default), 1 (True) or 2 (False).
- copies (integer, optional)
- Current device setting for number of copies to be printed.
- duplex (integer, optional)
- Current duplex setting for the device. Value can be 0 (Default), 1 (Simplex ie. not Duplex), 2 (Vertical duplex) or 3 (Horizontal duplex).
- paperPageSize (Size, optional)
- Current paper page size for the device as described by the Size class.
- unprintableMargins (Margins, optional)
- Current device setting for unprintable margins as described by the Margins class.
- status (integer, optional)
- Current status of the device. Value can be any reasonable combination of these values.
- port (string, optional)
- A string that identifies the port(s) used to transmit data to the printer. If a printer is connected to more than one port, the names of each port will be separated by commas (for example, "LPT1:,LPT2:,LPT3:").
- attributes (integer, optional)
- The current attributes of the printer. Value can be any reasonable combination of these values.
- serverName (string, optional)
- A string giving the name of the server computer controlling the printer. If the string is empty then the printer is controlled locally.
- shareName (string, optional)
- A string identifying the share point of the printer. This value is only present if PRINTER_ATTRIBUTE_SHARED is set in attributes.
- location (string, optional)
- A string describing the physical location of the printer.
- isLocal (boolean, optional)
- Whether the printer is a local printer (true) or not (false). isLocal tests whether PRINTER_ATTRIBUTE_LOCAL is set in attributes.
- isNetwork (boolean, optional)
- Whether the printer is a network printer (true) or not (false). isNetwork tests whether PRINTER_ATTRIBUTE_NETWORK is set in attributes.
- isShared (string, optional)
- Whether the printer is a shared printer (true) or not (false). isShared tests whether PRINTER_ATTRIBUTE_SHARED is set in attributes.
- isDefault (boolean, optional)
- Whether the printer is the default printer of the server computer (true) or not (false).
- bins (Array[string], optional)
- Lists the available paper sources for a printer. The names returned are suitable for use with the paperSource property.
- forms (Array[string], optional)
- Lists the available paper sizes (forms) for a printer. The names returned are suitable for use with the paperSize property.
Size:
- width (number, optional)
- The width of the paper specified by paperSizeName. Units are as specified in the units request parameter.
- height (number, optional)
- The height of the paper specified by paperSizeName. Units are as specified in the units request parameter.
Margins:
- left (string, optional)
- Left page margin.
- top (string, optional)
- Top page margin.
- bottom (string, optional)
- Bottom page margin.
- right (string, optional)
- Right page margin.
Example usage
Request
<h5>Response <span id="response-status"></span></h5>
<textarea id="response" readonly="readonly" rows="3" class="codefont"></textarea>
<h5>Response headers</h5>
<textarea id="headers" readonly="readonly" rows="3" class="codefont"></textarea>
document.addEventListener("DOMContentLoaded", function() {
document.getElementById('btn_runcode').addEventListener('click', function() { callServer(); });
});
function callServer() {
document.getElementById('response-status').textContent = "(waiting)";
const apiUrl = "/api/v1/printer/settings/default/2";
const headers = new Headers({
"Authorization": "Basic " + btoa("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + ":"),
"Content-Type": "application/json"
});
fetch(apiUrl, { method: "GET", headers: headers })
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok: ' + response.statusText);
}
document.getElementById('response-status').textContent =
'(status: ' + response.status + ' ' + response.statusText + ')';
return response.json().then(data => {
// show JSON response in textarea element
document.getElementById('response').value = JSON.stringify(data, null, " ");
// do something with the device info
var leftUnprintableMargin = data.unprintableMargins.left + (data.page.units === 1 ? ' inches' : ' mm';
var isDefaultPrinter = data.isDefault;
var currentPaperSize = data.paperSizeName + '(w:' + data.paperPageSize.width + 'mm h:' + data.paperPageSize.height + 'mm)';
// the units request parameter was 2 so dimensions returned will be in mm
return response.headers;
});
})
.then(headers => {
// show response headers in textarea element
let headersText = "";
for (let pair of headers.entries()) {
headersText += `${pair[0]}: ${pair[1]}\n`;
}
document.getElementById('headers').value = headersText;
})
.catch(error => {
document.getElementById('response-status').textContent = '(error: ' + error.message + ')';
document.getElementById('response').value = "Failed to fetch data.";
});
}