How to save figure in pdf without margins?
조회 수: 122 (최근 30일)
이전 댓글 표시
Let us suppose I have a figure with definite pixel size:
set(gcf,'unit','pixel','position',[0 0 figure_width figure_height])
I would like to save it as a pdf. I know the aspect ratio, but how to set the size? I don't want unnecessary margins. I want to use something like this
set(gcf,'PaperPositionMode','auto','papersize',[a*figure_width a*figure_height]);
%print(gcf,'Fig','-dpdf','-r0')
But how to choose the value of 'a' ?
댓글 수: 0
답변 (1개)
Jan
2018년 7월 22일
The value of a depends on the wanted size of the PDF. You can choose it freely to what you need. To remove the border use:
print(gcf, 'Fig.pdf', '-dpdf', '-fillpage')
댓글 수: 3
Jan
2019년 12월 9일
Did you try the -loose flag in the print command?
'-loose' — Use a loose bounding box. EPS and PS files only.
André de Castro
2019년 12월 19일
Using -loose did improve the results. It worked for PDF, EPS and PS files. I also had to:
- not use -fillpage;
- set the Position property before printing, as below.
width = 3.5;
height = 2.2;
figure_handle.Units = 'inches';
figure_position = figure_handle.Position;
figure_handle.Position = [figure_position(1),figure_position(2), width, height];
It seems strange that I had to set the figure Position though, as I had already set PaperUnits and PaperSize appropriately.
Combining -loose and the above code with the solution suggested here, in the Expand Axes to Fill Figure section, gave even better results, cropping as close as possible to the drawn area. Said solution was not effective when I had tried it before because I was using -fillpage.
참고 항목
카테고리
Help Center 및 File Exchange에서 Printing and Saving에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!