使用紧密边界框将Matlab Simulink模型另存为PDF [英] Save Matlab Simulink Model as PDF with tight bounding box

查看:235
本文介绍了使用紧密边界框将Matlab Simulink模型另存为PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于Simulink框图(模型),我想生成一个屏幕截图",稍后在LaTeX文档中使用.我希望此屏幕截图为具有紧密边界框的PDF(矢量图形,-> pdflatex),这意味着该图周围没有不必要的空白.

我搜索了网络,搜索了stackexchange,搜索了matlab文档.但是到目前为止没有成功.一些注意事项:

I have searched the net, searched stackexchange, searched the matlab doc. But no success so far. Some notes:

  1. 对于数字,有解决此问题的方法.我有一个Simulink框图,它与众不同(请参见下文).
  2. 我知道使用其他软件(例如pdfcrop)的解决方案.
  3. PDF似乎是唯一真正产生矢量图形的驱动程序(此处为Win7上的R2013b). EPS和PS输出似乎在其中包含位图.您放大,看到了.
  1. For figures, there are solutions to this question. I have a Simulink block diagram, it's different (see below).
  2. I am aware of solutions using additional software like pdfcrop.
  3. PDF seems to be the only driver that really produces vector graphics (R2013b on Win7 here). The EPS and PS output seems to have bitmaps inside. You zoom, you see it.

我尝试过的事情:

1.

print

modelName = 'vdp';         % example system
load_system(modelName);    % load in background

% print to file as pdf and as jpeg
print(['-s',modelName],'-dpdf','pdfOutput1')
print(['-s',modelName],'-djpeg','jpegOutput1')

JPEG看起来不错,边框很紧. PDF集中在看起来像A4或usletter的页面上.不是我想要的.

The JPEG looks good, tight bounding box. The PDF is centered on a page that looks like A4 or usletter. Not what I want.

有几个用于打印框图的参数.请参见Simulink参考页 http://www.mathworks.com/help/simulink/slref/model-parameters.html .让我们提取一些:

There are several parameters for printing block diagrams. See the Simulink reference page http://www.mathworks.com/help/simulink/slref/model-parameters.html. Let's extract some:

modelName = 'vdp';         % example system
load_system(modelName);    % load in background

PaperPositionMode = get_param(modelName,'PaperPositionMode');
PaperUnits        = get_param(modelName,'PaperUnits');
PaperPosition     = get_param(modelName,'PaperPosition');
PaperSize         = get_param(modelName,'PaperSize');

根据文档,PaperPosition包含一个四元素向量[left, bottom, width, height].最后两个元素指定边界框,前两个元素指定边界框左下角与纸张左下角的距离.

According to the documentation, PaperPosition contains a four element vector [left, bottom, width, height]. The last two elements specify the bounding box, the first two specify the distance of the lower left corner of the bounding box from the lower left corner of the paper.

现在,当我打印PDF输出并使用标尺进行测量时,我发现边界框的值及其左下角的位置都完全错误(是的,我在PaperUnits中进行了测量).那真是个无赖.我本可以计算出切边的边距,以便以后在\includegraphics[clip=true,trim=...]{pdfpage}中使用.

Now when I print the PDF output and measure using a ruler, I find the values of both the bounding box and the position of its lower left corner are totally wrong (Yes, I have measured in PaperUnits). That's a real bummer. I could have calculated the margins to trim off the paper to be used later in \includegraphics[clip=true,trim=...]{pdfpage}.

当然,我最初想要的是已经被裁剪的PDF.有一个数字解决方案,它是这样的:将边界框移动到纸张的左下角,然后将纸张尺寸更改为边界框的尺寸.

Of course what I initially wanted is a PDF that is already cropped. There is a solution for figures, it goes like this: You move the bounding box to the lower left corner of the paper and than change the paper size to the size of the bounding box.

oldPaperPosition = get_param(modelName,'PaperPosition');

set_param(modelName,'PaperPositionMode','manual');
set_param(modelName,'PaperPosition',[0 0 oldPaperPosition(3:4)]);
set_param(modelName,'PaperSize',oldPaperPosition(3:4));

对于simulink模型,这有两个问题. PaperSize是模型的只读参数.更改PaperPosition对输出完全没有影响.

For simulink models, there are two problems with this. PaperSize is a read-only parameter for models. And changing the PaperPosition has no effect at all on the output.

我的想法真的用光了.

编辑----------------------------------

EDIT ----------------------------------

好的,让您保持最新状态:我已经与Matlab支持人员进行了交谈.

Allright, to keep you updated: I talked to the Matlab support about this.

  • 在R2013b中,存在一些错误,这些错误会导致PaperPositionMode的错误行为以及PaperPostion的边界框错误.
  • 没有已知的方法可以从印刷品中提取比例因子.
  • 他们建议采用这种方式:Simulink-(打印)-> SVG-(Inkscape)-> PDF.这样真的很好用. (正确的)边界框是svg节点的属性,并且导出到SVG时的比例因子始终相同.此外,Inkscape生成了已经裁剪的PDF.因此,这种方法可以解决我所有的问题,只需要Inkscape.

推荐答案

为什么不喜欢使用pdfcrop?

Why you don't like to use pdfcrop?

我的代码运行完美,一切都在Matlab中:

My code works perfectly, and everything is inside Matlab:

function prints(name)
   %%Prints Print current simulink model screen and save as eps and pdf

   print('-s', '-depsc','-tiff', name)
   print('-s', '-dpdf','-tiff', name)
   dos(['pdfcrop ' name '.pdf '  name '.pdf &']);
end

您只需要使用"dos"命令调用 pdfcrop ,就可以了!

You just have to invoke pdfcrop using "dos" command, and it's works fine!

这篇关于使用紧密边界框将Matlab Simulink模型另存为PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆