MATLAB图形PDF周围的紧密边界框 [英] Tight bounding box around PDF of MATLAB figure
本文介绍了MATLAB图形PDF周围的紧密边界框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在MATLAB中创建简单图形并将其另存为PDF时,生成的PDF文件将带有一个豪华的边框.
When creating a simple figure in MATLAB and saving it as PDF, the resulting PDF file will have a luxurious bounding box.
plot(1,1,'x')
print(gcf, '-dpdf', 'test.pdf');
(从输出比例看,它们似乎总是放在A页上.)
(From the ratio of the output it seems they always put in on an A page.)
是否有一种简单的方法来获得围绕PDF的紧密边界框?
Is there a simple way to get a tight bounding box around the PDF?
推荐答案
您可以按如下所示设置边框的格式
You can format the bounding box as follows
figure(1)
hold on;
plot(1,1,'x')
ps = get(gcf, 'Position');
ratio = (ps(4)-ps(2)) / (ps(3)-ps(1))
paperWidth = 10;
paperHeight = paperWidth*ratio;
set(gcf, 'paperunits', 'centimeters');
set(gcf, 'papersize', [paperWidth paperHeight]);
set(gcf, 'PaperPosition', [0 0 paperWidth paperHeight]);
print(gcf, '-dpdf', 'test2.pdf');
对于较小的边框,您可以调整paperposition
属性,例如
For smaller borders, you can adjust the paperposition
property, e.g.
set(gcf, 'PaperPosition', [-0.5 -0.5 paperWidth+0.5 paperHeight+0.5]);
这篇关于MATLAB图形PDF周围的紧密边界框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文