MATLAB: How to force output of large figure to not be “scaled”, or how to properly print a pdf whose dimensions won’t fit on the [small] screen

exportexport_figfigureMATLABpaperpositionpdfprint

Hello,
I am trying to create a figure that will eventually be "print"ed to pdf at a standard paper size. However, if I tried to create this figure when my screen resolution + screen dpi is insufficient to hold the full figure, I receive the following error upon invoking "print":
Warning: UI controls may not print or export properly because the output has been scaled. Setting the figure's
PaperPositionMode property to 'auto' may help.
And indeed the uicontrols do not output correctly on the resulting pdf. Following the advice and setting PaperPositionMode to 'auto' does not fix the problem, although it does change the way in which the output is incorrect.
It seems I would want to prevent matlab from automatically "scaling the output", but I cannot find how to do this. I understand that what I want will prevent me from viewing the full figure correctly on my screen, but I don't care because I ultimately want the printed pdf to be correct.
Alternatively, maybe I am misusing the "PaperPosition" and "PaperSize" properties of the figure?
Here is a minimal example to reproduce the warning, though it does not give an appreciation of what goes wrong with the ui control placement on the pdf (in my application I carefully place many uicontrols). In this example, I want a 20"x20" pdf, but it cannot be held in full on my screen, which is a 1920×1080 display with reported ScreenPixelsPerInch=96 to give 20"x11.25". In my real application, I want a 8.5"x11" (portrait), and I want it to work even if the screen is small (e.g., laptop with 720 pixels tall and typical screen dpi).
PaperSize = [21,21]; % in inches, too large to fit on screen;
hFig = figure('Units','inches',...
'Position',[0,0,PaperSize],...
'PaperPosition',[0,0,PaperSize],...
'PaperSize',PaperSize,...
'PaperPositionMode','manual');
% need a uicontrol to trigger warning
uicontrol(hFig,'Style','pushbutton','String','uicontrol element')
print('tmp.pdf','-dpdf','-r600');
Thanks in advance for any help.
Matlab version is 9.1.0.441655 (R2016b)

Best Answer

I got a work-around.
The issue seems to be that figures are automagically resized when they don't fit on the screen, and this messes up any kind of placement of uicontrols, axes, etc. on the figure.
The workaround is to determine a safe length scaling factor based on screen resolution reported by
ScreenSize = get(0,'ScreenSize');
SPPI = get(0,'ScreenPixelsPerInch');
SH = floor((ScreenSize(4)-200)/SPPI);
SMult = SH/(PaperSize(2));
And scale all lengths and positions of uicontrols in the figure by this amount.
The next step is to rely on the behavior of
print -fillpage
which asserts a 0.25" margin but otherwise fills the page, and so define our figure on screen as
printMargin = 0.25; % immovable 0.25" margin with print -fillpage
FigureSize = (PaperSize-2*printMargin) * SMult;
This seems to work reasonably well...so far...