Customized Stylesheets

Number Pages in a Report

This example shows how to edit a stylesheet cell to number the upper-right side of all pages in the generated report.

  1. Define a basic stylesheet cell in the Header Content cell group with a condition of right.

    1. Open a PDF stylesheet in the Report Explorer.

    2. Double-click Header Content (under Pagination and General Styles) in the Options pane in the middle.

    3. Click Position - Right in the Properties pane on the right.

  2. Set the header content to the current page number by selecting Page number from the Append template selection list.

  3. Click Append.

Add Graphics to Headers in PDF Reports

This example shows how to include an image in the center of the header of each page in a PDF report, excluding the report's title page and the first page of each chapter. You do this by editing default header content for a PDF stylesheet. This example uses the report setup file mfile-report.rpt.

You can use any bitmap or jpeg file as image content. You must know the size of the image so that you can allow enough room for it in the header. This example uses the sample_logo.bmp image, which is shown here.

    Note:   PDF reports only support bitmap (.bmp), jpeg (.jpg), and Scalable Vector Graphics (.svg) images.

To include this image file in the center of each header in the body of a PDF report:

  1. Open mfile-report.rpt by entering the following at the MATLAB® command prompt:

    setedit mfile-report 
  2. Create a custom stylesheet.

    1. Select Tools > Edit Stylesheet in the menu bar of the Report Explorer.

    2. Click New FO (PDF) in the Properties pane on the right.

    3. As the Display name, enter Logo stylesheet for PDF.

    4. As Description, enter Company logo in center of header.

    5. Save the stylesheet as logo_stylesheet.rgs in a folder on your MATLAB path.

  3. Open the cell group for editing.

    1. Scroll through the Options pane on the left to the Pagination and General Styles folder.

    2. Double-click Header Content in the Options pane.

    3. Click Body page – Center from the list of cells in the Properties pane on the right.

      The Properties pane appears as shown.

    4. Delete the text in the Value (XML) field.

    5. Select Graphic from the Append template selection list and click Append.

      The Properties pane on the right shows the XML code that tells the File Converter to include the graphic.

  4. By default, the name of the graphic is logo.bmp. Change all instances of this name to sample_logo.bmp in the Value (XML) field.

  5. Save the stylesheet.

  6. Make sure that the amount of room available in the header is large enough to accommodate the image file.

    1. In the Options pane in the middle, double-click Region Before Extent, which is in the Pagination and General Styles folder.

    2. By default the value for the height of the header is 0.4 inch. Replace this value with 1.0in.

    3. Save the stylesheet.

  7. Generate the report with the new styles.

    1. Select mfile-report.rpt in the Outline pane on the left.

    2. In the selection lists under the Report Format and Stylesheet area of the Properties pane on the right:

      • Specify Acrobat (PDF) for File format

      • Specify Logo stylesheet for PDF.

    3. Click Report on the toolbar to generate the report.

Change Font Size, Page Orientation, and Paper Type of a Generated Report

This example shows how to:

  • Generate an XML source file without converting it to a supported report format

  • Make section headers in a report larger

  • Change the report page orientation to landscape

  • Change the report paper type to A4

Create a custom stylesheet by editing an existing stylesheet to change the appearance of the wsvar-report report, which is provided with the MATLAB Report Generator™ software.

  1. Generate a source file for the report.

    1. Open the report by entering the following command in the MATLAB Command Window:

      setedit wsvar-report
    2. In the Report Format and Stylesheet area of the Properties pane, change the format to DocBook (no transform).

    3. Check the If report already exists, increment to prevent overwriting check box.

    4. Select File > Report to generate the report.

      The report-generation process creates an XML source file in the MATLAB Editor.

  2. Convert the report to PDF format.

    1. Select Tools > Convert Source File from the Report Explorer menu bar to open the File Converter.

    2. From the Source file selection list, enter wsvar-report0.xml.

    3. From the File format selection list, select Acrobat (PDF).

    4. From the Stylesheet selection list, select Unnumbered Chapters and Sections.

    5. Click Convert File.

      The MATLAB Report Generator software converts the XML source file for wsvar-report to PDF format, and then opens the PDF document.

  3. Make the report headers more prominent.

    1. In the File Converter, click Edit.

      The Report Explorer displays the Unnumbered Chapters and Sections stylesheet.

    2. In the Properties pane on the right, enter Custom Large Section Headers as the stylesheet name.

    3. Enter the description No chapter and section numbering, larger section titles.

    4. In the Outline pane on the left, select the Custom Large Section Headers stylesheet.

    5. In the Options pane in the middle, select Section Title Level 1 Properties.

    6. In the Properties pane on the right, click Add to current stylesheet.

      The Section Title Level 1 Properties data item appears in the Outline pane on the left as a child of the Custom Large Section Headers stylesheet.

    7. In the Properties pane on the right, select the Font Size attribute.

      The Properties pane on the right displays an XML expression specifying font size as a multiple of the Body Font Size attribute.

    8. Click Edit as string.

      The MATLAB Report Generator software converts the XML expression to a simple string, which appears in a pane labeled Value.

    9. Enter the value 18pt.

      The size of the font is now fixed at 18 points, rather than being a multiple of the body font size attribute.

    10. Select File > Save to save the stylesheet.

    11. Save the stylesheet as customheader.rgs, in a folder in your MATLAB path.

      The customheader.rgs stylesheet appears as an available stylesheet in the Options pane in the middle of the Report Explorer. It also appears as an option in the File Converter.

  4. Use the new stylesheet to convert the current XML source file.

    1. In the Stylesheet Editor: Main Properties pane on the right, click Send to File Converter

      The File Converter appears, with the customheader.rgs stylesheet selected.

    2. Click Convert file.

  5. Change page orientation and paper type.

    1. On the File Converter Properties pane, click Edit.

    2. In the Options pane on the left, double-click the Page Orientation data item.

    3. In the Properties pane on the right, use the selection list to change the value of the data item to Landscape.

    4. In the Options pane in the middle, double-click Paper Type in the Pagination and General Styles folder.

    5. In the Properties pane on the right, select A4 from the selection list.

    6. Save the stylesheet.

  6. Generate the report wsvar-report.xml in PDF format using customheader.rgs..

    The PDF report appears with horizontally oriented pages of slightly different dimensions.

Edit Font Size as a Derived Value in XML

This example shows how to change the font size in a report to a value derived from other values. You do this by editing the PDF report's XML source directly.

  1. Open the default print stylesheet for PDF documents.

  2. In the Options pane in the middle, select and expand the Property Sets folder.

  3. In the Options pane, double-click the Section Title Level1 Properties data item.

    The Properties pane on the right appears as follows.

  4. In the Attributes area of the Properties pane on the right, click Font Size - <xml>.

The Report Explorer looks as follows.

The font size value is a product of $body.font.master and 2.0736. To change the font size to a larger size, change the multiplication factor to 3.0736.

    Tip   You specify the value for the $body.font.master data item in the Body Font Master property. This property is in the Pagination and General Styles category in the Options pane in the middle. The default value of this data item is 10. Changing this value causes the derived values to change accordingly.

Was this topic helpful?