Save a figure as pdf

조회 수: 1,602 (최근 30일)
friet . 2016년 11월 12일
댓글: ASMA FAROOQ . 2023년 9월 20일 11:22
I have figures and I am using the command below to save it as pdf. Is there any way to save it directly as pdf instead of saving as .ps and convert to .pdf.
print(figure(i), '-append', '-dpsc2', 'E:\');

채택된 답변

KSSV 2016년 11월 12일
screenposition = get(gcf,'Position');
'PaperPosition',[0 0 screenposition(3:4)],...
print -dpdf -painters epsFig
The first two lines measure the size of your figure (in inches). The next line configures the print paper size to fit the figure size. The last line uses the print command and exports a vector pdf document as the output.
  댓글 수: 6
Saunok Chakrabarty
Saunok Chakrabarty 2022년 1월 20일
Could you explain how you're using screenposition here?

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Sujay Kadam
Sujay Kadam 2021년 7월 1일
May be this has already been answered somewhere else, but I thought I would share what I usually do for generating plots in pdf format. Run the following code after generating a figure:
clear figure_property;
figure_property.units = 'inches';
figure_property.format = 'pdf';
figure_property.Preview= 'none';
figure_property.Width= '8'; % Figure width on canvas
figure_property.Height= '11'; % Figure height on canvas
figure_property.Units= 'inches';
figure_property.Color= 'rgb';
figure_property.Background= 'w';
figure_property.FixedfontSize= '12';
figure_property.ScaledfontSize= 'auto';
figure_property.FontMode= 'scaled';
figure_property.FontSizeMin= '12';
figure_property.FixedLineWidth= '1';
figure_property.ScaledLineWidth= 'auto';
figure_property.LineMode= 'none';
figure_property.LineWidthMin= '0.1';
figure_property.FontName= 'Times New Roman';% Might want to change this to something that is available
figure_property.FontWeight= 'auto';
figure_property.FontAngle= 'auto';
figure_property.FontEncoding= 'latin1';
figure_property.PSLevel= '3';
figure_property.Renderer= 'painters';
figure_property.Resolution= '600';
figure_property.LineStyleMap= 'none';
figure_property.ApplyStyle= '0';
figure_property.Bounds= 'tight';
figure_property.LockAxes= 'off';
figure_property.LockAxesTicks= 'off';
figure_property.ShowUI= 'off';
figure_property.SeparateText= 'off';
set(chosen_figure,'PaperSize',[str2num(figure_property.Width) str2num(figure_property.Height)]); % Canvas Size
hgexport(gcf,'filename.pdf',figure_property); %Set desired file name
  댓글 수: 6
Sujay Kadam
Sujay Kadam 2023년 7월 25일
You may want to change the values in the following lines:
figure_property.Width= '8'; % Figure width on canvas
figure_property.Height= '11'; % Figure height on canvas
If the width is larger than the height, the resulting plots would have a more horizontal aspect ratio.
For example,
figure_property.Width= '16'; % Figure width on canvas
figure_property.Height= '9'; % Figure height on canvas
would produce plots that would be suitable for a typical computer screen.

댓글을 달려면 로그인하십시오.

Richard Quist
Richard Quist 2021년 12월 11일
In R2021b and later you can use exportgraphics to directly create PDF files containing multiple figures:
% append each of the figures to output.pdf
for i=1:numFigs
exportgraphics(figure(i), 'output.pdf', 'Append', true);
  댓글 수: 1
Ramprakash Ananthapadmanaban
Ramprakash Ananthapadmanaban 2023년 8월 29일
'exportgraphics' function works well and even in subplots. Thanks

댓글을 달려면 로그인하십시오.

Ish Jain
Ish Jain 2019년 9월 9일
!pdfcrop filename.pdf filename.pdf'
pdfcrop is useful if you are saving pdf for latex and you are using Linux.
  댓글 수: 1
ASMA FAROOQ 2023년 9월 20일 11:22
print -dpdf epsFig

댓글을 달려면 로그인하십시오.


Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기


Community Treasure Hunt

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

Start Hunting!

Translated by