using standalone app designer how to print figure using pushbutton ,thanks .

 Accepted Answer

That is mean no hope with matlab R2021a Any way thanks a lot

1 Comment

Directly, apparently.
You could save the axis to a .pdf file with exportgraphics and then should be able to dump that file to a printer -- although that might also entail having to use an intermediary application.
Hadn't ever actually tried and the doc doesn't mention can't use print on uifigure and I had forgotten that even though did know it.

Sign in to comment.

More Answers (1)

dpb
dpb on 22 Sep 2025
Edited: dpb on 22 Sep 2025
Include print in the callback function of your button. You will have to inform your users that the printer will have to first be selected and configured by the OS user dialog method as printdlg won't work with AppDesigner and uiprintdlg wasn't introduced until R2025a so it won't be in R2021a.
ERRATUM
Can't use print on uifigure and I had forgotten that even though did know it, sorry.
You could save the axis to a .pdf file with exportgraphics and then should be able to dump that file to a printer -- although that might also entail having to use an intermediary application.

17 Comments

That mean no hope to print directly from use figure with pushbutton in matlab R2021a Thanks a lot anyway

Directly, yes. Seems Mathworks left a big hole unfilled when introduced the uifigure.
On reflection, I think there is, perhaps, a subterfuge way around it although I've not tested it.
Add a panel to your layout programmatically and a app property variable to hold a graphics handle.
Define a function to create the normal axes in the panel something like
properties
Axes gobjects(1); % app property for axes handle
end
function makeRegularAxes(app)
app.Axes = axes(app.Panel); % 'Panel' is the container component
end
Either do the plotting to this object directly using its handle or copyobj the other into it. Normal axes functions including print just may work there.

Thanks I am for now using print screen to get my figure , but by using push button it will be fine for end user Any way I accept your answer and many thanks for you.

FYI and any others who stumble across --
I took the APPDESIGNER sample app of mortgage calculator and added a "Print" push button in its LH panel and a callback for it, then set a breakpoint in the callback.
At the command line, the following worked successfully...
hPR=app.RightPanel; % shorter panel handle
hUAx=app.PrincipalInterestUIAxes; % ditto for less typing
hUAx.Units='normalized'; % default is pixel, but normal axes is normalized
posn=hUAx.InnerPosition; % position of uiaxes
hUAX.Visible='off';
hAx=axes(hPR,'position',posn,'color','none'); % "regular" axes on top of uiaxes
and things seemed as normal. Didn't have the time to really try to make a printing routine out of copying the existing figure, but looks as though it should be possible.

Thanks a lot I will try it I accept your answer.

I'd guess you would want to create another panel in which to place the normal axes rather than overlay the normal user interface as I did just for concept testing. It can then be made invisible after debugging for the real use.
I suspect there will also be some issues in that the copied figure won't identically reproduce the uiaxes one owing to internal differences, but it would be the closest one could come with an integrated solution with earlier releases.

Does not work, For end user stand alone user, I advise home to use print screen button. Thank you any way meeting you in future projects.

I want through pushbutton the end user use his printer to print the figure without any back ground on matlab. That is all

I don't understand what you mean by "without any back ground on matlab", sorry. Can you explain more fully? Do you mean background on the printed figure thinking your user must know details inside MATLAB?
Can you show the code you tried that didn't work and what was the error?
I don't know that I will have time to try to delve into it more deeply, but might be able to add some pointers if the problems you ran into aren't truly insurmountable.
If the other axes can be created and the figure copied over (or maybe even redrawn in that axes), then it would seem should be able to do it. But, I'll admit I haven't actually tried more than the prior experiment so well may run into an issue.
One other alternative is to revert to saving the pdf file and then, assuming the end users have Adobe Acrobat, can dispatch "quick print" via the command line something like
printfilename='figure1.pdf';
exportgraphics(app.UIAxes,printfilename,'ContentType','vector')
cmd=sprintf('"C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe" /s /h /p %s &',printfilename);
[s,c]=system(cmd);
I tested the above technique locally and it works behind the scenes to the user other than there apparently is no way to force Acrobat to close after the print job is done; there is a minimized Acrobat process left running.
There are some freeware command line utilities to print a pdf file but I haven't tested any of them recently. That route would, of course, entail distributing the chosen app as well.
The cleanest solution would be to upgrade to R2025b that does include the support https://www.mathworks.com/help/matlab/release-notes.html#mw_06d385ae-40e3-4862-84d7-0eb9ae9e77bd

It is standalone program run on many commercial computers with no knowledge of matlab persons using runtimes on computers So we need to use available printers at users site to print predicted graph I will attach the front end of project which is getting paitent number at my country Thank you too much for your attention.

"... run on many commercial computers "
Are you supporting other platforms besides Windows?
OK, I yield...there is no subterfuge that will let one use the print function in an AppBuilder app; even though one can create the regular axes in a second window, MATLAB won't/can't create a regular figure object as a child of a uifigure and print only works to print a figure from a figure handle.
The only route I can see programmatically is the one outlined before of exporting to a file and then printing the file. This could all be coded with sufficient effort or by use of secondary applications to do the work, but without being able to specify your clients must have a postscript-enabled printer, it's painful.

Thank you I think we get the end of our discussion .

Agreed. Good luck...but one last thought/idea...
If you were to decide to pursue the printfile route, look at https://www.sumatrapdfreader.org/free-pdf-reader. While it is a reader/viewer, it has a command-line operation that would let you print programmatically like showed earlier with Adobe Reader. And, if you were really ambitious, you can download the source code and then could selectively compile the pieces needed only to do the printing stuff into a mex function wrapper so wouldn't have to distribute another executable. Your users wouldn't even be able to tell a file to be printed was created behind the scenes... <g>

Sign in to comment.

Categories

Find more on Printing and Saving in Help Center and File Exchange

Products

Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!