How can I programmatically print a GUI with a button

13 vues (au cours des 30 derniers jours)
MathWorks Support Team
MathWorks Support Team le 15 Jan 2019
I have created a GUI with GUIDE, and I would like to let app users print an image of the app with a button. How can I do this?

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 10 Nov 2025
Modifié(e) : MathWorks Support Team le 10 Nov 2025
There are 2 approaches.
First, the easiest way is with the 'print' function. Call 'print' in the button callback, and it will get the current figure (which is the GUI) and print it.
For more fine-grained control over the printed image, use the following approach:
f = getframe(gcf); % Get an image of the app in pixel color values
toShow = figure('Visible','off'); % Create a new invisible figure
warning('off','images:initSize:adjustingMag') % Turn off a specific imshow warning that sometimes may appear
imshow(f.cdata); % Display the pixel data.
warning('on','images:initSize:adjustingMag') % Turn the warning back on
set(toShow,'PaperOrientation','landscape',...
'PaperUnits','normalized','PaperPosition',[0,0,1,1]); % Set some size preferences for printing
printdlg(toShow); % Open print menu
close(toShow) % Close the invisible figure
This will capture a picture of the GUI using pixel values, and print an associated figure of the GUI.
To change how the GUI appears on the paper (like the size, location, etc), you can modify some of the properties in the 'set' command. More information is below in the "Printing and Exporting" section:

Plus de réponses (0)

Catégories

En savoir plus sur Printing and Saving dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by