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 users 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 will be available in a number of configurations, including on premise versions as required when confidential information is being printed.
This sample provides an introduction to adding the use of the ScriptX.Services.HTML to your own pages:
We'll do things in a slightly different order.
This page has a 'Download to PDF' button. The 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.
To show that we arent cheating and using a pre-prepared file for download this sample includes some form fields so you can customise the print. Also note that the date and time on the PDF 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="~/Scripts/jquery-3.1.1.js"></script> <script src="/scripts/MeadCo.ScriptX/core.js"></script> <script src="/scripts/MeadCo.ScriptX/scriptxprint.js"></script> <script src="/scripts/MeadCo.ScriptX/scriptxprinthtml.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 identifier is always required as, typically, the ScriptX.Services server will be available at a different url to the server from which the document requesting the print originated and will therefore be subject to cross origin restrictions on scripting. The server will allow calls from origins with a valid identifier.
The subscription at the server 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 to a PDF document. The ScriptX.Services modules will take care of the response from the server will be a file and will download the file when it is ready.
Complete the form and then print. Your form values will be included on the print though the value of password will not print.