Well, this is a pretty dirty trick, and there is definitely no guarantee that it will work for all versions. This works for me on Matlab 2013a / win 7.
To return Matlab to a print job or not, you need to insert a small hack into the print.m function.
print.m
Find the function print.m . It should be in the Matlab installation folders near ..\toolbox\matlab\graphics\print.m .
After posting, make a backup! (this trick is insignificant and should not break anything, but we never know).
open the file print.m and find the line LocalPrint(pj); , it should be near or at the end of the main function (~ line 240 for me).
Replace the line with:
.
pj = LocalPrint(pj); %// Add output to the call to LocalPrint if (nargout == 1) varargout{1} = pj ; %// transfer this output to the output of the `print` function end
Made for hacking. Now every time you call print , you can get a return argument full of information.
Applicable to your case:
First, note that on Windows machines, the printdlg function printdlg equivalent to calling the print function with the argument '-v' .
So printdlg(figHandle) exactly matches print('-v',figHandle) . ( '-v' means verbose ). We will use this.
The output of the print function will be a structure (let it be called pj ) with many fields. The field you want to check to see if the print command was actually executed is pj.Return .
pj.return == 0 => job cancelled pj.return == 1 => job sent to printer
So, in your case, after setting up on print.m , it might look like this:
pj = print('-v',figHandles(1)); %// Shows the print dialog for the first figure if pj.Return %//if the first figure was actually printed (and not cancelled) for currFig = 2:length(figHandles) print(figHandles(currFig)); %// Does not show the print dialog and uses the latest printer selection end end
Note. The pj structure contains much more information for reuse, including print job parameters, currently selected printers, etc.
source share