Printing blob columns in background from Servoy interface

We can print images stored in blob(Media) columns in different ways. One of the interesting way to accomplish this task is by using executeProgramInBackground method. Using this method we can execute actions at the command line. This works on both Mac and WindowsXp Operating Systems.

First we need to create a temporary file from the media field, then we will call the commandline utility to do the printing job.
Code Snippet:

var theDocument = media_field; // holding a .jpg, .tiff, etc. var theFileType = file_type // the file extension

var theTempFile = plugins.file.createTempFile('print', theFileType);

//create the temporary file
plugins.file.writeFile(theTempFile, theDocument);

//get all the printer names attached to your system
var printers = application.getPrinters();

//select any one printer from the list of printers connected to your system
var theSelectedPrinter = printers[0];

if(utils.stringMiddle(application.getOSName(), 1, 7) == “Windows”) { //for windows Operating System application.executeProgramInBackground(‘RunDll32.exe’, ‘shimgvw.dll,ImageView_PrintTo’, ‘/pt’, theTempFile, theSelectedPrinter, ”, ”); } else { //for MAC Operating System if(print_orientation == “Landscape”) { application.executeProgramInBackground(‘lp’, ‘-o landscape’, theTempFile); } else { application.executeProgramInBackground(‘lp’, theTempFile); }

}

Note : This works in both Smart Client and Web client.

150 150 Burnignorance | Where Minds Meet And Sparks Fly!