Print a single PDF document

To synchronously print a single PDF format file, use the  PrintPDF() API. The url of the PDF document to be printed is specified, the printer to use etc can be chosen by the user by utilising prompted printing.

Synchronous printing blocks the browser UI so its use is discouraged. We recommend using one of the BatchPrint APIs instead.

Note when using ScriptX.Services printing is not synchronous at the browser due to the asynchronous nature of the calls to the server that does the printing. In this case WaitForSpoolingComplete() will work and enable a 'busy' UI to be implemented. However it will not work as expected with ScriptX.Add-on.

The use of the ScriptX Client libraries that emulate the Add-on API means the same code can be written for all browsers.

The PDF library must be included:

<script src="~/Scripts/jquery-3.1.1.js"></script>
<script src="/scripts/MeadCo.ScriptX/meadco-core.js"></script>
<script src="/scripts/MeadCo.ScriptX/meadco-scriptxprint.js"></script>
<script src="/scripts/MeadCo.ScriptX/meadco-scriptxprintpdf.js"></script>
<script src="/scripts/MeadCo.ScriptX/meadco-scriptxfactory.js"></script>
<script src="/scripts/MeadCo.ScriptX/meadco-scriptxprintlicensing.js"></script>
<script src="/scripts/MeadCo.ScriptX/meadco-secmgr.js"></script>
<script src="/scripts/meadco-scriptx-1.7.0.js" type="text/javascript"></script>

Then the same code works:

$(window).on("load", function () {
    MeadCo.Licensing.IsLicensedAsync()
        .then(function(l) {
            MeadCo.ScriptX.InitAsync()
                .then(function() {
                    $("#btn-print").click(function(e) {
                        // print the pdf, no prompt, shrinktofit
                        MeadCo.ScriptX.Printing.PrintPDF({ url: "example.pdf"},false,true);
                    });
                })
                .catch(function(e) {
                    app.Messages.ErrorBox("Unable to intialise ScriptX: " + e);
                });
        })
        .catch(function(e) {
            app.Messages.ErrorBox("Unable to use the ScriptX license: " + e);
        });
});