Print a single remote HTML document

In the 'classic' usage of ScriptX to provide an enhanced printing experience of HTML documents the printing UI is included in the page to be printed.

A work-flow may include a process on the server preparing reports to be printed. The user at their PC may then select one of a number of the pre-prepared reports for printing. Or, a server action may return an HTML document with data obtained from a database populating various content in the document. The user may select a document to be prepared and printed without needing to see or preview the document.

These are both cases for printing of a 'remote' document - in other words download and print the document without displaying it in the browser.

When the PrintHTML() method is used, headers, footers, papersize etc etc, i.e. all the usual formatting (including enhanced formatting) and presentation properties are used to print the downloaded document.

A chosen document can then be printed:

function printDocument(url) {
const p = MeadCo.ScriptX.printing;

p.header = "Finance report&b&p of P&b";
p.footer = "&b&D&b";

// BackgroundPrintURL wraps PrintHTML/PrintHTMLEx()
MeadCo.ScriptX.BackgroundPrintURL(url,false);
}

The printHtml() method implements its own queue and caches printing parameters (including printer to use and so on) for each print job - documents are downloaded and once the download is complete, the document is printed.

There are important differences between the behaviour of ScriptX.Add-on and ScriptX.Services.

Illustration

The report cookie for this browser's session with the server is: [4eb217dd-0b33-42cb-b083-35d7cc4bc086, created at: 21/11/2024 13:45:23].

If the print process shares this browser's session then the above cookie will be printed on the report when "Print document ..." is used.

This will be true when you are using ScriptX.Add-on with its default behaviour () and you haven't used Enable OwnQueue. For ScriptX.Add-on, once you have printed, the print type - in-process or out-of-process, will stay the same, use Refresh to switch usage

For other cases, i.e. when OwnQueue is used or ScriptX.Services with default behaviour, the report with be printed with no-cookie value showing that the session data from this browser's session is not available.

ScriptX.Add-on

In its default usage, users must wait for the entire queue to download and print before navigating away from the page. Calling the OwnQueue() method moves the printHtml queue to its own independent process and users are free to get on with their work.

However, there is a price to pay for this flexibility when dealing with dynamic server side systems that rely upon maintenance of session information and in particular those that rely upon the use of cookies to maintain that information.

In its default usage, the printHtml() queue shares session information transferred to the browser by the server with the Internet Explorer browser session. For example, session cookies are shared and the server will believe that requests made by the queue are in the same session as previous requests from the browser and so, for example, log-on information etc is 'preserved'.

When OwnQueue has been called, a new independent process is created and no session information (cookies) from the parent browser are transferred. Requests made by the queue to the server will therefore appear to be from a new browser session and any log-on information that is persisted by cookies will have been 'lost'. A typical result of this is that rather than the expected report being produced, a logon page or site default page is printed (the requested report page will have determined that the session is not logged on and will perform a redirect to the default/logon page).

ScriptX.Services

With ScriptX.Services all printing is in its own queue operating independently of the browser (it may be on a physically separate machine).

Requests made by ScriptX.Services for the document therefore appear to be from a new source and there will be no log-on information or any information that is persisted to cookies that might be available to the originating browser. A typical result of this is that rather than the expected report being produced, a logon page or site default page is printed (the requested report page will have determined that the session is not logged on and will perform a redirect to the default/logon page).

With ScriptX.Services for Windows PC 2.12 and later a cookie and value can be passed to the print process and will be passed along with the request for the document being printed.

If the  MeadCoScriptXJS Library is used, then the function MeadCo.ScriptX.SetContentAuthorisationCookie() can be used.

This is used on this page so the report cookie [4eb217dd-0b33-42cb-b083-35d7cc4bc086, created at: 21/11/2024 13:45:23] will be printed on the report when "Print document ..." is used.

Activity log  ::