How to print a figure as a PDF, that has the same size of my figure (or, how to resize the PDF according to my figure dimensions)?

조회 수: 5 (최근 30일)
How to print a figure as a PDF, that has the same size of my figure (or, how to resize the PDF according to my figure dimensions)?
In other words, how can I get rid of the upper and lower white margins in the following printed PDF?
% create a figure with "subtightplot"
subplot = @(m,n,p) subtightplot (m, n, p, [0.001 0], [0.01 0.01], [0.01 0.01]);
fig = figure('position',[700 100 700 1200],'Color',[1 1 1])
hold on
for i = 1 : 6
subplot(2,3,i);
end
hold off
% print the figure as PDF
fig.Units = 'centimeters'; % set figure units to cm
fig.PaperUnits = 'centimeters'; % set pdf printing paper units to cm
fig.PaperSize = fig.Position(3:4); % assign to the pdf printing paper the size of the figure
path = ( '/Users/Donald/.../' ); % where to print my figure
print (fig(:), '-dpdf','-loose','-opengl','-r600', [path, 'fig'] )
This is the resulting PDF, where you can clearly see the upper and lower white margins that I would like to get rid of:
  댓글 수: 3
Sim
Sim 2023년 3월 7일
편집: Sim 2023년 3월 7일
Thanks a lot! Yes, that solution works! Sorry for asking something similar to my old post - Maybe I can delete this question (if Matlab moderators/staff thinks it is better)

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

채택된 답변

Sim
Sim 2023년 3월 7일
편집: Sim 2023년 3월 7일
Solved, thanks to the @Luca Ferro's comment (Yes, similar to my old post - and sorry for asking something similar, I did not realise I could use the same solution, my fault)...Many thanks @Luca Ferro!!
Just the exportgraphics function solves my issue:
% Solution:
% create a figure with "subtightplot"
subplot = @(m,n,p) subtightplot (m, n, p, [0.001 0], [0.01 0.01], [0.01 0.01]);
fig = figure('position',[700 100 700 1200],'Color',[1 1 1])
hold on
for i = 1 : 6
subplot(2,3,i);
end
hold off
% print the figure as PDF
path = ( '/Users/Donald/.../' ); % where to print my figure
exportgraphics(fig, fullfile(path, 'fig.pdf'),'ContentType','vector') % this solves my issue
And this is the resulting PDF, without the upper and lower white margins:
At this point, I do not know if the following commands that I have used (by following the method/solution proposed by Sergi Tarroc on 17 Jun 2021) are really necessary, maybe no, or at least I do not see differences:
fig.Units = 'centimeters'; % set figure units to cm
fig.PaperUnits = 'centimeters'; % set pdf printing paper units to cm
fig.PaperSize = fig.Position(3:4); % assign to the pdf printing paper the size of the figure

추가 답변 (0개)

카테고리

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