Main Content

Create Page Layout Sections

You can add sections to a report using themlreportgen.report.Sectionclass. This predefined class automatically adds a formatted section into your report. The default formatting is portrait orientation with a default margins and a page number in the footer. You can override the layout and contents of the section. It is much easier and more efficient to use this class rather than using DOM objects to create a section. For information and examples, seemlreportgen.report.Section

You can also use DOM objects to create sections. You can divide a Word or PDF document into sections, each with its own page layout. Page layout includes page margins, page orientation, and headers and footers.

Define Page Layouts in a Word Template

Every Word template has at least one page layout section. You can use Word to create as many additional sections as you need. For example, in the main template for a report, you can create sections for your report’s title page, table of contents, and chapters. See the Word documentation for information on how to create page layout sections in a Word template.

Define Page Layouts in a PDF Template

You define page layouts in a PDF template using aelement. You can use theelement in the main template (root.html), and in document part templates.

You can use these attributes with theelement.

style

page-margin: top left bottom right header footer gutter; page-size: height width orientation

first-page-number Number of first page in the layout
page-number-format norNfor numeric,a,A,i,I
section-break Where to start section for this layout:Odd Page,Even Page, orNext Page

For example, this element defines a layout with:

  • Top, bottom, left, and right margins of 1 inch

  • Header and footer heights of 0.5 inches

  • Gutter size (space for binding pages) of 0

  • 8.5-inch by 11-inch page size in portrait orientation

"page-margin: 1in 1in 1in 1in 0.5in 0.5in 0in;page-size: 8.5in 11in portrait" />

Thiselement includes a page footer. The page footerDefaultPageFootermust be defined in a document part template.

"page-margin: 1in 1in 1in 1in 0.5in 0.5in 0in;page-size: 8.5in 11in portrait">"default"template-name="DefaultPageFooter"/> 

You can create page layouts in document parts. For example, this code defines a document part template namedChapterthat includes a page layout. The layout includes a page header and a page footer and specifies the format for the page number using theelement. In this case, also define part templates for the page header and page footer elements. SeeUse Page Headers and Footers in a Template.

"Chapter"> "page-margin: 1in 1in 1in 1in 0.5in 0.5in 0in;page-size: 8.5in 11in portrait">"default"template-name="MyPageHeader"/> "default"template-name="MyPageFooter"/> "1"/>  <!-- Define content for your layout here--fixed text and holes as needed -->

To use the layout, insert the document part into your report using your program. This code assumes that there is one hole in the document partChapter. The document part uses the page layout definition you provided in theChapterdocument part template.

importmlreportgen.dom.*d = Document('myDocPartEx','pdf','mytemplate'); open(d);% Assign the Chapter document part template to the variable dpdp = DocumentPart(d,'Chapter');% Move to each hole in this document part and append contentmoveToNextHole(dp); append(dp,'My text to fill hole');% Append this document part to the documentappend(d,dp); close(d); rptview(d.OutputPath);

Watermarks in PDF Page Layouts

You can place a watermark in a PDF page layout. A watermark is an image that appears in the background of a page, such as the wordDraftorConfidential. It runs behind the text on each page you apply it to. You can use any of these file types for the image:.bmp,.jpg,.pdf,.png,.svg, and.tiff.

Usein aelement. Specify the watermark as an image file stored in the template package. To store the image in the template package, unzip the template package, copy the image into the folder, and then zip the template again. For example:

  1. Unzip the template.

    unzipTemplate('MyTemplate.pdftx');
  2. Copy the watermark image into the folderMyTemplate. To keep your images organized, copy the image into theimagesfolder.

  3. Add thewatermarkelement to a page layout in your template. For example, add the watermark to the default layout inroot.html.

    "page-margin: 1in 1in 1in 1in 0.5in 0.5in 0in;page-size: 8.5in 11in portrait" >"./images/myfile.png"width="6in"/> 
  4. Zip the template.

    zipTemplate('MyTemplate.pdftx','MyTemplate');
  5. Delete the folderMyTemplate.

  6. Create a report that uses this template using the DOM API, or create a form-based report in Report Explorer whosePDF Page Layoutcomponent uses this layout.

L导航模板页面ayouts

A document or document part’sCurrentPageLayoutproperty points to a page layout object that specifies the current section’s page layout based on the document or document part’s template. Each time you move to a new section (by moving to a hole at the beginning of the section), the DOM updates theCurrentPageLayoutproperty to point to the page layout object that specifies the section’s page layout properties. You can change a section’s page layout by modifying the properties of the layout object or replacing the layout object with a new object.

For example, you can change the section’s orientation or add page headers or footers. Make these changes before you add any content to the new section. When replacing the current layout object, use anmlreportgen.dom.DOCXPageLayoutobject for Word documents andmlreportgen.dom.PDFPageLayoutfor PDF documents.

Override Template Page Layouts in Your Report Program

你可以改变模板布局改过的ies programmatically. For example, the page orientation of the DOM default Word template is portrait. This example changes the orientation to landscape to accommodate wide tables. The code swaps the height and width of the page to the new page orientation.

importmlreportgen.dom.*rpt = Document('test','docx'); open(rpt); sect = rpt.CurrentPageLayout; pageSize = sect.PageSize; pageSize.Orientation ='landscape'; saveHeight = pageSize.Height; pageSize.Height = pageSize.Width; pageSize.Width = saveHeight; table = append(rpt,magic(22)); table.Border ='solid'; table.ColSep ='solid'; table.RowSep ='solid'; close(rpt); rptview(rpt.OutputPath);

Create Layouts Programmatically

You can append aDOCXPageLayoutobject (for Word documents) or aPDFPageLayoutobject (for PDF documents) to start a new page layout section programmatically. For DOCX reports, theappendmethod can specify a paragraph to end the previous section.

append(rptObj,paraObj,LayoutObj)

If you do not specify a paragraph in yourappendmethod, the DOM API inserts an empty paragraph before starting the new section. This example uses the end paragraph syntax to avoid inserting an empty paragraph at the end of the previous section.

importmlreportgen.dom.*rpt = Document('test','docx'); append(rpt,Heading(1,'Magic Square Report','Heading 1')); sect = DOCXPageLayout; sect.PageSize.Orientation ='landscape'; sect.PageSize.Height ='8.5in'; sect.PageSize.Width ='11in'; append(rpt,Paragraph('The next page shows a magic square.'),sect); table = append(rpt,magic(22)); table.Border ='solid'; table.ColSep ='solid'; table.RowSep ='solid'; close(rpt); rptview(rpt.OutputPath);

See Also

Classes

Related Topics