Main Content

中心图在页面上的快照

此示例显示了如何将图形快照集中在pdf和Microsoft®单词报告的景观页面上。

该示例创建了具有景观布局的报告API报告,创建MATLAB数字,然后使用centerFigurelocal function to create and add the snapshots of these figures at the center of the page.

创建报告

导入DOM并报告API软件包,因此您不必使用长期,完全合格的类名称。

进口mlreportgen.dom。*进口mlReportgen.Report。*

创建PDF报告。要创建Microsoft®单词报告,请更改“ PDF”“ docx”

rpt =报告("myreport",,,,“ PDF”);打开(RPT);

Update Report Page Layout

创建页面布局对象。

如果strcmpi(rpt.Type,“ PDF”)pagelayoutobj = pdfpagelayout;别的pagelayoutobj = docxpagelayout;结尾

Specify the page orientation, height, and width.

pageLayoutObj.PageSize.Orientation ="landscape";pagelayoutobj.pagesize.height =“ 8.5英寸”;pagelayoutobj.pagesize.width =“ 11英寸”;

Specify the page margins.

pagelayoutobj.pagemargins.top ="0.5in";pageLayoutObj.PageMargins.Bottom ="0.5in";pageLayoutObj.PageMargins.Left ="0.5in";pagelayoutobj.pagemargins.right ="0.5in";pageLayoutObj.PageMargins.Header =“0.3”;pagelayoutobj.pagemargins.footer =“0.3”;

将页面布局对象添加到报告中。

add(rpt,pageLayoutObj);

创建并添加数字

用线性图创建一个图形。

f = fige();情节(1:1:10,2:2:20);网格on;

致电centerFigure本地功能以在页面中心添加图形快照。然后,删除图对象。

Centerfigure(F,RPT);

删除(f);

同样,在页面中心添加膜表面图快照。

centerFigure(surf(membrane),rpt);

delete(gcf);

Generate the Report

关闭并查看报告。

关闭(RPT);RPTView(RPT);

centerFigureLocal Function

此功能创建指定图的快照,并在指定报告中的页面中心添加。该功能使用报告API数字reporter to take the figure snapshot and an invisible DOMTable到do the layout.

functionCenterfigure(图,RPT)

导入DOM API,报告API和报告生成器实用程序软件包,因此您不必使用长期,完全合格的类名称。

进口mlreportgen.dom。*进口mlReportgen.Report。*进口mlreportgen.utils.*

Get the report's current page layout to determine the current page size and the page margins. The page layout information is used to calculate the page body size in order to size the layout table created in a subsequent step.

pagelayout = getReportlayout(rpt);pagesize = pagelayout.pagesize;pagemargins = pagelayout.pagemargins;

Calculate the page body width. The page body width denotes the page width available for the content and is determined by subtracting the left and right margin size from the page width. For DOCX output, gutter size also needs to be subtracted.

bodywidth =单位。...units.toInches(pageMargins.Left) -...units.toInches(pageMargins.Right);如果strcmpi(rpt.Type,“ docx”)Bodywidth = Bodywidth-...toinches(pagemargins.gutter);结尾bodywidth = sprintf(“%0.2fin”,Bodywidth);

Calculate the page body height. The page body height denotes the page height available for the content and is determined by subtracting the top and bottom margin size from the page height. For PDF output, the header and footer sizes also need to be subtracted because the body extends from the bottom of the header to the top of the footer.

bodyHeight = units.toInches(pageSize.Height) -...toinches(pagemargins.top) -...toinches(pagemargins.bottom);如果strcmpi(rpt.Type,“ PDF”)bodyheight = bodyheight-...toinches(pagemargins.header) -...toinches(pagemargins.footer);结尾bodyHeight = sprintf (“%0.2fin”,,,,bodyHeight);

创建一个数字指定图的对象。然后,创建一个图片对象包裹在图快照图像文件上。缩放图像以适合后续步骤中创建的布局表的条目。

无花果=图(图);figimg = image(getSnapshotimage(图,rpt));figimg.Style = [figimg.Style {scaletofit}];

Wrap the image in a paragraph because PDF requires that an image reside in a paragraph. Update the paragraph style to make sure that there is no white space around the image.

para = Paragraph(figImg); para.Style = [para.Style {OuterMargin("0in",,,,"0in",,,,"0in",,,,"0in")}];

Add the paragraph that contains the figure snapshot in a 1-by-1 invisible layout table (lo_table)。当未针对表及其表条目定义边界时,表格不可见。

lo_table = table({para});

跨表格到可用的页面主体宽度。

lo_table.Width = bodyWidth;

跨越可用的页面主体高度的唯一桌子条目。另外,指定垂直和水平对齐格式,以确保图像在表条目内垂直和水平的居中。

lo_table.tableentriesstyle = [lo_table.tableentriesstyle...{...高度(身体方),...HAlign("center"),...VAlign(“中间”...}];

将布局表添加到报告中。

添加(rpt,lo_table);结尾

也可以看看

||||||

Related Topics