Apply Default Styles And Behaviour

As of 4.3, Reportico provides the reportico_defaults.php file to allow to set attributes, styles, formatting options, and other functions which will be applied to every report. This can be set up to apply to all reports, or all reports in a single project.

This file allows you to set useful default behaviour including :-

Setting default styles to different areas of the report such as setting default colors, borders, margins, paddings etc. These can be applied to the report body, and most of the elements within the report such as group headers/trailers, detail block and individual cells. At the moment most styling options can be applied to both PDF and HTML format.

Adding Page Headers/Page Footers to every page (PDF Only). You can add styled coloured bordered text and image areas to allow you format the page title, page count, other custom text as well as adding images to your report pages.

The Reportico folder contains reportico_defaults.php which is a stub for entering such functions. By placing this in a project folder it will be used for all reports in that folder instead of the global one.

A note on fonts

It is possible to set the font to use but given that the PDF and HTML mechanisms use a different source for fonts it is necessary to specify different style sets for the two formats.

Apply Styles

In the reportico_defaults.php file you need to add a section for each element you want to style by default.

To add a style you need to create an array of style elements specified as key value pairs which are much like CSS.

Then you use the apply_styleset function to indicate which area of the reports should be styled and also specify whether the style should be applied to HTML output, PDF output or both as follows :-

  $reportico->apply_styleset($section, $styles, $cell, $outputformat);

where :-

  • section is one of ALLCELLS ROW CELL PAGE BODY COLUMNHEADERS GROUPHEADER GROUPHEADERLABEL GROUPHEADERVALUE GROUPTRAILER
  • styles is the array of styles
  • cell is set to a columnname to apply the styles to (for CELL section only) otherwise set to false
  • outputformat is the output format type to apply the style to .. set to PDF, HTML or leave blank to apply to both

For example to apply a background color and set a border to the whole report body in PDF format :-

            $styles = array(
                "background-color" => "#cccccc",
                "border-width" => "1px 1px 1px 1px",
                "border-style" => "solid",
                "border-color" => "#000000",
                "margin" => 
                );
            $reportico->apply_styleset("BODY", $styles, false, "PDF");

Note: because of the differences between HTML and PDF generation, in some cases styles applied in PDF may not behave the same as in HTML. For this reason it may be necessary to apply differet sets of styles for PDF and HTML. This will involve some experimentation.

Page Headers and Footers

Use the create_page_header and create_page_footer to add text and image elements to the top and bottom of each page.

      $reportico->create_page_header($name, $line, "TEXT{STYLE styleinfo}" );
      $reportico->set_page_header_attribute($name, "ShowInHTML", "no" );
      $reportico->set_page_header_attribute($name, "ShowInPDF", "yes" );
      $reportico->set_page_header_attribute($name, "Justify", "right|left|center" );

Where :- name is a unique name to give to header line is a line number from the top of the report page to display the header. This can be from 1 onwards. However you can use the margin styling option to more accurately control the space to leave before printing the header.

The TEXT element can be freeform text or you can use the following notation to include other elements {REPORT_TITLE} - shows the title of the current report. {PAGE} - Shows the current page number {columnname} - Shows the value of a the report row data column to be next printed

For STYLE use CSS syntax:- {STYLE border-width: 1 1 1 1; border-color: #000000; border-style: solid;padding:10px 14px 0px 6px; width: 90%}

Example to add a right justified report title in a blue 4 pixel border with a red background to the top of the page 2cm from th top :-

           $reportico->create_page_header("H1", 1, "{REPORT_TITLE}{STYLE border-width: 4px 4px 4px 4px; border-color: #0000ff; border-style: solid; margin: 2cm 0 0 0;" );
            $reportico->set_page_header_attribute("H1", "ShowInHTML", "no" );
            $reportico->set_page_header_attribute("H1", "ShowInPDF", "yes" );
            $reportico->set_page_header_attribute("H1", "Justify", "right" );

For page footers do exactly the same using the create_page_footer and set_page_footer_attribute functions but the line number is relative to the bottom.

  • report_default_styles_and_behaviour.txt
  • Last modified: 2018/05/04 21:40
  • (external edit)