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:\myfigure.ps');
Thanks

1 件のコメント

Janani
Janani 2026 年 3 月 5 日
append

サインインしてコメントする。

 採用された回答

KSSV
KSSV 2016 年 11 月 12 日

17 投票

saveas(gcf,'myfigure.pdf')
Or
set(gcf,'Units','inches');
screenposition = get(gcf,'Position');
set(gcf,...
'PaperPosition',[0 0 screenposition(3:4)],...
'PaperSize',[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 件のコメント

za
za 2017 年 6 月 2 日
Is there a way to save it as pdf with fill page?
Ghost
Ghost 2019 年 3 月 1 日
編集済み: Ghost 2019 年 3 月 1 日
fig=gcf; % your figure
fig.PaperPositionMode='auto';
print('Name_of_file','-dpdf','-fillpage')
Cyril Justin
Cyril Justin 2019 年 11 月 20 日
How do you save multiple figures on the same pdf?
Marco Torres
Marco Torres 2020 年 7 月 19 日
To save several matlab figures on the same pdf, you can use the report generator toolbox.
Michael Judge
Michael Judge 2021 年 4 月 9 日
@KSSV, Thank you so much for this. It's going to save me and my group so much time.
Saunok Chakrabarty
Saunok Chakrabarty 2022 年 1 月 20 日
Could you explain how you're using screenposition here?

サインインしてコメントする。

その他の回答 (3 件)

Sujay Kadam
Sujay Kadam 2021 年 7 月 1 日
編集済み: Eric Sargent 2023 年 12 月 20 日

9 投票

Update: Starting in R2021b, 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);
end
(Original Answer prior to R2021b)
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';
chosen_figure=gcf;
set(chosen_figure,'PaperUnits','inches');
set(chosen_figure,'PaperPositionMode','auto');
set(chosen_figure,'PaperSize',[str2num(figure_property.Width) str2num(figure_property.Height)]); % Canvas Size
set(chosen_figure,'Units','inches');
hgexport(gcf,'filename.pdf',figure_property); %Set desired file name
Warning: Style sheets will not be supported in a future release.

6 件のコメント

Parth Patel
Parth Patel 2021 年 12 月 11 日
This is the most perfect solution one can find for this problem. Thank you so much :)
Sujay Kadam
Sujay Kadam 2021 年 12 月 12 日
You're welcome! I'm glad you found this helpful.
Md Modassir Firdaus
Md Modassir Firdaus 2022 年 9 月 19 日
Hi Sujay,
How can I change the only font size of legend ? It seems that the font size of every thing is same
Sujay Kadam
Sujay Kadam 2022 年 9 月 19 日
Hi Firdaus,
Kindly change in the following line '12' to 'auto'...
figure_property.FontSizeMin= '12';
Katty
Katty 2023 年 7 月 25 日
Hi! Is it possible to generate this same pdf but in a horizontal format?
Sujay Kadam
Sujay Kadam 2023 年 7 月 25 日
Hi,
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 日

4 投票

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);
end

1 件のコメント

Ramprakash Ananthapadmanaban
Ramprakash Ananthapadmanaban 2023 年 8 月 29 日
'exportgraphics' function works well and even in subplots. Thanks

サインインしてコメントする。

Ish Jain
Ish Jain 2019 年 9 月 9 日

0 投票

saveas(gcf,'filename.pdf')
!pdfcrop filename.pdf filename.pdf'
pdfcrop is useful if you are saving pdf for latex and you are using Linux.

1 件のコメント

ASMA FAROOQ
ASMA FAROOQ 2023 年 9 月 20 日
print -dpdf epsFig

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeTables についてさらに検索

タグ

質問済み:

2016 年 11 月 12 日

コメント済み:

2026 年 3 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by