Printing one or more files with feature control and progress callbacks

Activity log  ::  

Asynchronous printing of one or more PDF format files, along with monitoring the progress of each job in script is available with the  BatchPrintPDFEx API . With batch printing, files are downloaded and printed in the background, allowing users to continue with other tasks on the displayed page.

Multiple files may be queued for printing and as with  BatchPrintPDFEx API different options/features used for each print. For example, a different printer may be selected for each print, or different page ranges printed to different printers/trays.

Since the printing is asynchronous then the  IsSpooling API or the  WaitForSpoolingComplete API can be used to start and end a suitable UI to show the user that printing is in progress. WaitForSpoolingComplete() is used in this sample.

Progress monitoring is va a callback function that may used for example to alert the user to a failure in the print.

Use with ScriptX.Services

BatchPrintPDFEx() is an API provided by ScriptX.Add-on. An emulation of this API is implemented in  MeadCo ScriptX.Services print client modules . These are used throughtout these samples to allow "single source". An alterative is to use the  ScriptX.Services Print API 'directly'.

This is a simple example of printing two different pages ranges from the same document to the chosen printer with BatchPrintPDFEx which results in two separate prints. A 'real life' example might use different trays for each print.

function log(s) {
    $("#logoutput").append(s + "
"); } function monitorPrint(status, statusData, myData) { // log("Job progress, status: " + status + ", data: [" + statusData + "], myData: " + myData); switch (status) { case 1: log("Job: " + myData + " has been queued"); break; case 2: log("Job: " + myData + " has started"); break; case 3: log("Job: " + myData + " has started downloading url: " + statusData); break; case 4: log("Job: " + myData + " has downloaded: " + statusData); break; case 5: log("Job: " + myData + " is printing"); break; case 6: log("Job: " + myData + " has completed"); break; case 7: log("Job: " + myData + " has been paused"); break; case 8: log("Job: " + myData + " is printing a PDF document: " + statusData); break; case -1: log("Job: " + myData + " has encountered an error: [" + statusData + "]"); break; case -2: log("Job: " + myData + " is being abandoned"); break; default: log("Job: " + myData + " unknown status: " + status); break; } } // setupPrinting // // Initialise print setup used by all jobs. // function setupPrinting() { var printer = MeadCo.ScriptX.Printing; printer.printer = $("#fld-pdfprinter").val(); printer.orientation = $('input[type=radio][name=fld-pdforientation]:checked').val(); printer.paperSize = $("#fld-pdfpapersize").val(); printer.paperSource2 = "" + $("#fld-pdfpapersource").val(); printer.copies = 1; } function PrintPDFFiles() { setupPrinting(); MeadCo.ScriptX.Printing.SetPrintScale(MeadCo.PDFOptionsUI.ShrinkToFitChecked ? -1 : 100); console.log("printing to: " + MeadCo.ScriptX.Printing.printer); var printing = MeadCo.ScriptX.Printing; printing.SetPageRange(false, 1, 1); printing.BatchPrintPDFEx("/Content/PDF/Fourpages.pdf",monitorPrint,"Job1"); printing.SetPageRange(false, 3, 100); // large number for print to end of document printing.BatchPrintPDFEx("/Content/PDF/Fourpages.pdf",monitorPrint,"Job2"); // UI until both prints are spooled app.PrintSpooling.Show(); }
<body>
<button id="idPrint" onclick="PrintPDFFiles()">Print reports</button>
</body>