How to save a MATLAB graphic in a right size .pdf?

540 Ansichten (letzte 30 Tage)
weijie
weijie am 3 Aug. 2011
Kommentiert: MAzharul Islam am 14 Apr. 2022
I save a graphic as .pdf format, but matlab will produce an A4 size to put this small picture in the middle of this A4 size pdf. The problem comes when I import them into my LaTeX file, i only need the picture size, not the whole A4 pdf size. Could anyone tell how to solve this problem?

Akzeptierte Antwort

Friedrich
Friedrich am 3 Aug. 2011
Hi,
you can do it in MATLAB through:
h = figure;
plot(1:10);
set(h,'Units','Inches');
pos = get(h,'Position');
set(h,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)])
print(h,'filename','-dpdf','-r0')
  8 Kommentare
Priya Mittal
Priya Mittal am 11 Apr. 2021
Exactly what I wanted, many thanks!
MAzharul Islam
MAzharul Islam am 14 Apr. 2022
how to get it done while exporting simulink model using print. I write the following line in my command window which gives me a full page pdf instead of croped one. But in case of other formats it produces just the figure without any white space around the figure.
print('-shomedata','-dpdf','home.pdf')

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Fereidani Samani
Fereidani Samani am 19 Sep. 2018
Bearbeitet: Walter Roberson am 20 Sep. 2018
h4=figure;
set(h4,'PaperSize',[20 10]); %set the paper size to what you want
print(h4,'filename','-dpdf') % then print it

Oliver Woodford
Oliver Woodford am 3 Aug. 2011
Export_fig saves the figure at the dimensions it appears at on screen, and crops the whitespace around the figure, for a tight border.
Note that for exporting to pdf it requires that you have ghostscript installed.
  1 Kommentar
SteveC
SteveC am 29 Apr. 2018
Using print or export_fig as above crop the figure, but change the fonts used in the figure. Printing to Adobe pdf can preserve the fonts by embedding them and crops the picture to the minimum size if Friedrich's setting are mode. (System: Adobe Acrobat Pro 2017, Matlab 2012b, Win 7 x64). This is much better for my application. Is there a way to have ghostscript embed the fonts in the pdf?

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by