Slient/Direct Printing In Servoy

I’m looking to add direct printing capability within our web application. I’ve found this previous forum post about it: How to print PDF directly in Servoy ? - Classic Servoy - Servoy Community and still seem to run into some issues. Just wondering if anyone else can provide some insight if they have added this to their application and if so how it was done. Thanks.

The way I’ve done it in the past is have a queue where the clients print job goes. This queue is usually a table of some sort. The server then has a batch processor which watches the queue and sends the job directly to the printer via command line. On Mac, thats with LPR. Windows can do it with Adobe reader command line.
Mac example here: https://servoyguy.com/code-repository/s … a-printer/

The following works for me

I use Jasper Reports to create a PDF from the report, then pass the folder and file name as the filePath

/**
 * Print PDF file in background. This Prints the pdf file in the preferred printer attached to server machine
 *
 * @param {String|plugins.file.JSFile} filePath The path to file
 * @param {String} [preferredPrinter] The Printer to be used for printing. By default uses the default printer
 * @param {Number} iCopies
 *
 * @return {Boolean} Status
 * @author pradipta
 * @since 10/15/2014
 *
 * @properties={typeid:24,uuid:"7FDD2CE9-C65F-484C-A8A9-DCA8AEB737E2"}
 */
function silentPrint(filePath, preferredPrinter, iCopies) {

	var printerJob = Packages.java.awt.print.PrinterJob.getPrinterJob();

	// Find the Preferred Printer
	if (preferredPrinter) {
		/** @type {Array<javax.print.PrintService>} */
		var _printServices = Packages.javax.print.PrintServiceLookup.lookupPrintServices(null, null)
		for (var _i = 0; _i < _printServices.length; _i++) {
			if (_printServices[_i].getName().toUpperCase() == preferredPrinter.toUpperCase()) {
				printerJob.setPrintService(_printServices[_i]);
				break;
			}
		}

		// Validate of the desired printer found
		if (_i == _printServices.length) {
			plugins.dialogs.showErrorDialog('Print', preferredPrinter + ' cannot find in installed printers')
			return false;
		}

	} else {

		// Find the Default printer;
		/** @type {javax.print.PrintService} */
		var _printService = new Packages.javax.print.PrintServiceLookup.lookupDefaultPrintService();
		if (!_printService) return false;
		printerJob.setPrintService(_printService);
	}

	// Check Printer Job
	if (!printerJob) {
		plugins.dialogs.showErrorDialog('Print Report', preferredPrinter + ' found, but unable to set the Printer Service');
		return false;
	}

	try {

		// Get Document and Print
		var file = new Packages.java.io.File(filePath);
		var printDocument = Packages.org.apache.pdfbox.pdmodel.PDDocument.load(file);
		if (!printDocument) {
			plugins.dialogs.showErrorDialog('Print Report', 'Unable to start Print Job');
			return false;
		}

		// Print Document
		printerJob.setPageable(new Packages.org.apache.pdfbox.printing.PDFPageable(printDocument));
		printerJob.setJobName("Aquarius PDF Print Job");

		if (arguments.length == 3) {
			printerJob.setCopies(iCopies);
		} else {
			printerJob.setCopies(1);
		}

		// Set the attributes
		var printAttributes = new Packages.javax.print.attribute.HashPrintRequestAttributeSet;
		var pageRange = new Packages.javax.print.attribute.standard.PageRanges(1, printDocument.getNumberOfPages());

		printAttributes.add(pageRange);

		printerJob.print();

	} catch (exception) {
		application.output(exception.message);
	} finally {
		if (printDocument) {
			printDocument.close();
		}
	}

	return true;
}