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
Show older comments
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)
Accepted Answer
More Answers (1)
Marc Jakobi
on 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);
7 Comments
J. Alex Lee
on 25 Oct 2016
Marc Jakobi
on 25 Oct 2016
Hm, shame it didn't help.
print() can be buggy sometimes.
J. Alex Lee
on 26 Oct 2016
Edited: J. Alex Lee
on 26 Oct 2016
Marc Jakobi
on 26 Oct 2016
Hm, I don't know the function well enough, but I would take a closer look at his subfunctions print2eps and eps2pdf. You might be able to extract what you need from there.
Marc Jakobi
on 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
on 28 Oct 2016
Timothy
on 5 Oct 2026
While this is 10 years old it just fixed a problem for me where saving a page to PDF was 1 in 10 times a different size then expected. I have been playing with pauses and different methods for months to no avail. This wizardry worked on a test case of 100 prints back to back. Without it I would get 1/4 sized pages and pages with crazy big fonts about 30% of the time with it 100 for 100 worked as expected! Many thanks to you!
Categories
Find more on Environment and Settings in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!