Main Content

PDF报告中的中心形式图像

此示例显示了如何将正式图像(在pdf报告的景观页面上)中心形式图像,该图像是带有标题的图像。

这example creates a Report API PDF report that has landscape layout and uses the中心图本地功能以在页面中心添加正式图像。

创建报告

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

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

Create a PDF report.

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

更新报告页面布局

创建页面布局对象。

pageLayoutObj = PDFPageLayout;

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.3in";pagelayoutobj.pagemargins.footer ="0.3in";

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

add(rpt,pageLayoutObj);

创建和添加正式图像

创建正式图像并致电中心图本地功能以在页面中心添加这些正式图像。

formorimg1 =正式图(..."Image",哪个(“ ngc6543a.jpg”),...“标题”,,,,“猫眼星云或NGC 6543”);中心图(formalImg1,rpt); formalImg2 = FormalImage(..."Image",哪个("peppers.png"),...“标题”,,,,“胡椒”);中心图(formalImg2,rpt);

Generate the Report

关闭并查看报告。

关闭(RPT);RPTView(RPT);

中心图Local Function

This function adds the specified formal image at the center of the page in the specified PDF report. The function uses an invisible DOMTableto do the layout.

function中心图(formalImage,rpt)

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

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

要确定当前的页面大小和页面余量,请获取报告的当前页面布局。页面布局信息用于大小在后续步骤中创建的表。

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

计算页面身体宽度。页面宽度表示内容可用于内容的页面宽度。对于PDF报告,页面主体宽度是通过从页面宽度中减去左右边缘大小来确定的。

bodywidth =单位。...units.toInches(pageMargins.Left) -...单位。bodywidth = sprintf(“%0.2fin”,Bodywidth);

身体高度计算页面。页面主体确定ht denotes the page height that is available for the content. For a PDF report, the page body height is determined by subtracting the top margin, bottom margin, header, and footer size from the page height.

bodyHeight = units.toInches(pageSize.Height) -...toinches(pagemargins.top) -...toinches(pagemargins.bottom) -...toinches(pagemargins.header) -...toinches(pagemargins.footer);bodyheight = sprintf(“%0.2fin”,,,,bodyHeight);

使用getimagereporter方法的方法FormalImage记者获取图像记者和GetCaptionReporter获取标题记者的方法。

ImagerePorter = GetImagereporter(正式图,RPT);CaptionReporter = GetCaptionReporter(正式图像);

使用getimplmethods of the image and caption reporters to get the corresponding DOM implementations.

imageImpl = getImpl(imageReporter,rpt); captionImpl = getImpl(captionReporter,rpt);

DOM实现包含DOM段落其中包含图像和字幕内容。更新段落的样式,以确保段落周围没有空白,并将其集中在后续步骤中创建的表条目中。

parastyle = {...OuterMargin("0in",,,,"0in",,,,"0in",,,,"0in"),...HAlign("center"...};imagePara =克隆(ImageImpl.Children(1));ImagePara.Style = [ImagePara.Style,Parastyle];CaptionPara = clone(Captionimpl.Children(1));catchionpara.Style = [CaptionPara.Style,Parastyle];

创建一个1 x-1隐形布局表(lo_table)。当未针对表及其表条目定义边界时,表格不可见。

lo_table =表(1);行= append(lo_table,tablerow);entry = append(row,tableentry);

Add the paragraphs that contain the image and caption content to the only table entry in the invisible layout table.

附加(条目,imagePara);附加(条目,catchionpara);

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

lo_table.Width = bodyWidth;

Span the only table entry to the available page body height. Specify the vertical and horizontal alignment formats to make sure that the image and caption are centered both vertically and horizontally inside the table entry.

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

将布局表添加到报告中。

添加(rpt,lo_table);结尾

也可以看看

|||||

Related Topics