How to capture whole app.UIFigure with exportapp?
18 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I developed an app that adds fields based on user needs. When I use exportapp, it captures the max length of the screen, which I guess is the intended purpose for a screengrab. Is there a way to grab the entire UIFigure and save it as a pdf if the window is scrollable (i.e., some fields are cut off)? We need to see all of the fields in the pdf for it to be useful.
I also tried using exportgraphics() but when I try to export app.UIFigure as a pdf file, the pdf is blank.
Thank you.
0 Kommentare
Antworten (1)
Jonas
am 8 Feb. 2023
you could try to temporarly increase the figure size, export it and restore old behavior
%% create ui figure with three buttons, two of them out of sight
fig = uifigure(Position=[680 200 300 300],Scrollable="on");
uibutton(fig,Position=[100 150 100 22]);
uispinner(fig,Position=[400 150 100 22]); % too far to the right
uispinner(fig,Position=[100 10 100 22]);
fig.Position=[680 427 300 74]; % add vertical scrollability by setting small window size (just to show the concept of expanding along x and y)
% get components
allComps=fig.Children;
% get positions of components
positions=cell2mat(get(allComps,'Position'));
% get max extent of figure elements (x/y position plus x/y size)
maxX=max(sum(positions(:,[1 3]),2))*1.1;
maxY=max(sum(positions(:,[2 4]),2))*1.1;
% save old position
oldPos=fig.Position;
fig.Position(3:4)=[maxX maxY];
exportapp(fig,'expandedPDF.pdf');
% restore old position, size and scrollbars
fig.Position=oldPos; % old figure size, but tries to squeeze the buttons into the visible area
pause(1) % the figure squeezing needs some time, drawonw does not seem to do the job, pause helps here. If you leave out this line, the buttons will still be squeezed despite the next code line
% re set old positions of elements
arrayfun(@(in,row) set(in,'Position',positions(row,:)),allComps',1:numel(allComps))
pay attention to elements which are positioned at the edge of the figure, those are cut off when using exportapp. I could not fix this using code without
You can see the problem in the resulting pdf when e.g. setting
uispinner(fig,Position=[100 0 100 22]);
% instead of
uispinner(fig,Position=[100 10 100 22]);
3 Kommentare
Jonas
am 9 Feb. 2023
now i understand your issue. UIfigures cannot be bigger than screen size. How unfortunate
another more complicated option could be to take s scrollshot (I think thats the name in android)
you can scroll through your container using the scroll() command, each time taking an image/screenshot and stitching them together to a bigger image. Justl like in a panorama recording, but easier, since there is no distortion of the image
Siehe auch
Kategorien
Mehr zu Printing and Saving finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!