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

41 vues (au cours des 30 derniers jours)
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 1920x1080 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)

Réponse acceptée

J. Alex Lee
J. Alex Lee le 28 Oct 2016
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...

Plus de réponses (1)

Marc Jakobi
Marc Jakobi le 24 Oct 2016
I haven't exported to PDF, but I used to have similar problems when exporting figures to emf. I have a short script that fixes it for me 99% of the time. Maybe it'll fix your PDF export.
Here's the contents:
unis = get(gcf,'units');
ppos = get(gcf,'paperposition');
set(gcf,'units',get(gcf,'paperunits'));
pos = get(gcf,'position');
ppos(3:4) = pos(3:4);
% pos(1:2) = [1 1];
set(gcf,'paperposition',ppos);
set(gcf,'units',unis);
  6 commentaires
Marc Jakobi
Marc Jakobi le 26 Oct 2016
What is the 'PaperType' property of your figure? Setting that according to the paper type of the PDF document may help (e. g. 'A4' or 'A3')
J. Alex Lee
J. Alex Lee le 28 Oct 2016
Thanks for the continued help. I had been using "US Letter" for PaperType, and ensured that my PaperSize and PaperPosition correspond to the correct dimensions (8.5x11 inches).
I ended up not figuring out export_fig (though it seemed promising for a while).
However, I settled on a workaround as I describe below. I'd be happy to see if there are cleaner ways to do it!
Thanks!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by