使用HG2-Update和'painters'渲染器将图形导出为.pdf格式的矢量图形不能正常工作
我正在使用仍未公开的 HG2-Update 创建我的MATLAB图,因为它们看起来好多了.
I'm using the still undocumented HG2-Update to create my MATLAB plots, because they just look that much nicer.
(来源:Yair Altman)
(Source: Yair Altman)
实际上,使用当前版本 Release 2013b 效果很好,并且没有太多问题.除了希望将图形导出为矢量图形(渲染器:'-painters'
),尤其是将其导出为 pdf .
Actually, using the current version Release 2013b it works quite nicely and there are not much issues. Except one wants to export the figures as vector graphics (renderer: '-painters'
), especially as pdf.
我使用以下命令:
saveas(gcf,'test.pdf','pdf')
或
print(gcf,'test.pdf','-dpdf')
There are rendering issues, the print does not contain the whole figure and some parts are cropped or non-default fonts are not recognized.
但是我真的很想留在 HG2 上,但我仍然想使用矢量图形.有什么解决方案或解决方法吗?
But I'd really like to stay with HG2 and I'd still like to use vector graphics. Is there any solution or workaround?
使用尚未正式发布的导出矢量图形 HG2-Update 是一个大问题. .pdf -导出仍然完全搞砸了. .svg -export可以正常工作,但边界框的设置不正确.
Exporting vector graphics using the yet not official HG2-Update is quite an issue. The .pdf-export is still totally screwed up. What is working fine is the .svg-export, apart from that the boundary box is not set properly.
长的解决方法是:
使用'-dsvg'
(print
-命令)或'svg'
(saveas
-命令)将图解保存为矢量图形,在开放源应用程序
The long workaround would be:
Save the plot with '-dsvg'
(print
-command) or 'svg'
(saveas
-command) as vector graphic, open the file in the open source application Inkscape and save again as .pdf with the Export area is drawing checkmark set.
非常复杂,所以我找到了一种直接从Matlab通过命令行进行操作的方法(仍然需要Inkscape!):
Quite complicated, so I found a way to do it via command-line directly from Matlab (Inkscape still required!):
filename = 'test';
inkscapepath = '"C:\Program Files (x86)\Inkscape\inkscape.exe"';
%// save as .svg
saveas(gcf,filename,'svg')
%// open and save with "export-area-drawing" set via command line
system( [inkscapepath ' ' filename ...
'.svg --export-area-drawing --export-pdf=' filename '.pdf'])
这需要一些时间,但目前尚无任何已知问题.
It takes some time, but works without any known issues for now.
之后再删除svg文件:
Additionally delete the svg-File afterwards:
delete([filename '.svg'])