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.

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 means the same code can be written for all browsers.

The PDF library must be included:

<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.10.1.js" type="text/javascript"></script>

Then the same code works:

$(window).on("load", function () {
    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 initialise ScriptX: " + e);
        });