ScriptX.Services is the evolution of the ScriptX add-on for Internet Explorer to provide developers with the tools for ensuring the consistent formatting and appearance of printed output regardless of the user's device or modern browser.
Browsers have no extensibilty for printing. So, instead of the printing being performed within and by the user's browser, the content to be printed is sent to a server where it is paginated and rendered to a print device connected to the server. If that print device prints to file (e.g. 'Write to PDF' device is used) then the file can be returned to the user where they can print out the content on their local printer.
The ScriptX.Services server providing the print Web API is available in a number of configurations including an on premise version for shared services and a version for individual Windows PC.
Whichever ScriptX.Services server is used, the API is the same enabling the same client code to be used with any configuration.
By default these samples use the MeadCo Cloud Print service but can be configured to use your own for On-Premise Devices for for Windows PC ScriptX.Services server. To configure use of your own server, use Settings. Note that if you configure to use your own server then prints will be sent to the default printer.
The configured server is https://scriptxservices.meadroid.com/ currently.
This sample provides an introduction to adding the use of the ScriptX.Services for printing HTML to your own pages:
We'll do things in a slightly different order.
This page has a 'Print this page' button. When using the cloud service a download is obtained by using the ScriptX.Services server to `print` this document to a PDF and then return the `printed file` as a download. Other services will print to their default printer.
To show that we arent cheating and using a pre-prepared file for download / printing this sample includes some form fields so you can customise the print. Also note that the date and time on the PDF / print will be the time you requested the print.
The button is standard html styled with some Bootstrap css and Font Awesome:
We won't use any library to help us though obviously we could as they all resolve to being an abstraction on the underlying DOM:
At this point we have a button which when clicked writes an information line to the console.
The MeadCo ScriptX.Services modules are available for download from Github.
<script src="//firstname.lastname@example.org/dist/jquery.min.js"></script> <script src="//cdn.jsdelivr.net/npm/scriptxprint-html/dist/meadco-scriptxservices.min.js"></script>
The whole of MeadCo.ScriptX.Services.HTML is now available to the page.
The sample code above has listed out each individual file for illustration. Your environment workflow will enable packaging these files as desired.
For version 1, ScriptX.Services depends on jQuery for ajax and some DOM manipulation services so jQuery must be referenced, and as shown above it should be referenced before ScriptX.Services.
ScriptX.Services must be configured with two parameters:
A subscription/license identifier is usually required; the server will allow calls from origins with a valid identifier.
The subscription / license will also define the features available - for example basic (margins, headers, footers etc) or advanced (printer selection, print properties such as papersize etc).
Finally, we can put everything together to print the page. The ScriptX.Services modules will take care of a response from the server that a file (e.g. PDF) will be produced and will download the file when it is ready. In other cases, the print will appear on the default printer.
Complete the form and then print. Your form values will be included on the print though the value of password will not print.