Here is an example code using the high level PHP API where everything concerning the report (including the data source) is described in the report XML:
<?php
$o = new OpenCReport();
if (!$o->parse_xml(o, "report.xml")) {
printf("XML parse error\n");
exit(1);
}
$o->set_output_format(o, OpenCReport::OUTPUT_PDF);
$o->execute();
$->spool();
This code will load report.xml,
set the output format to PDF, runs the report and dumps
the result on stdout, which ends up
in your browser if the PHP code is run behind a webserver.
Most of the class methods are direct wrappers of the corresponding C API functions.
The class constructor creates an
OpenCReport object.
public final OpenCReport::__construct();
These methods load the report description
either from the specified XML file or
from the XML content provided in the string.
They return
true for success,
false for failure.
public final OpenCReport::parse_xml(string $filename): bool; public final OpenCReport::parse_xml_from_buffer(string $buffer): bool;
Default is public const OpenCReport::OUTPUT_PDF.
public const OpenCReport::OUTPUT_PDF; public const OpenCReport::OUTPUT_HTML; public const OpenCReport::OUTPUT_TXT; public const OpenCReport::OUTPUT_CSV; public const OpenCReport::OUTPUT_XML; public const OpenCReport::OUTPUT_JSON; public final OpenCReport::set_output_format(int $format): void;
Note that these constants are not to be overridden
in subclasses. With PHP 8.1 and newer, the
final flag is added so overriding
these constants will throw an exception.
This method returns the previously set output format, or the default if it wasn't set.
public final OpenCReport::get_output_format(): long;
This method returns the name of the output format as string.
public static final
OpenCReport::get_output_format_name(long $format):
string;
public final
OpenCReport::set_output_parameter(
string $param,
string $value): void;
Possible parameters for the HTML output driver:
document_root sets
the document root for trimming path prefix
from image paths.
meta extends
the default
<meta charset="utf-8">.
literal (see
The passed-in string value may contain
the whole <meta ...>,
in which case the inner parameters are
used only. The charset
specification is ignored. Only the rest is used.
suppress_head suppresses the default
<head> ... </head> section.
Possible values to enable suppressing the
default <head> ... </head>
are yes,
true and
on.
Anything else disables it.
Be aware, that the default section contains
importand CSS stylesheet settings that are
needed for the correct layout.
Possible parameters for the CSV output driver:
csv_filename sets the file
name for Content-Disposition
in the HTTP metadata returned by
ocrpt_get_content_type().
csv_as_text sets the MIME type
for Content-Type
in the HTTP metadata returned by
ocrpt_get_content_type().
csv_delimiter (also aliased as
csv_delimeter according to
the historical typo in RLIB) sets the CSV field
delimiter to the first character of the string.
By default it's a comma.
no_quotes will create a CSV
output with values unquoted.
Possible values to enable it are
yes,
true,
on or any positive non-zero
number. Anything else disables it.
It takes precedence over
only_quote_strings
only_quote_strings
will create a CSV output with only string
values quoted.
Possible values to enable it are
yes,
true,
on or any positive non-zero
number. Anything else disables it.
Note that some languages (e.g German, Swedish
and Hungarian) use comma as the decimal separator
instead of decimal point. For these languages,
either set csv_delimiter or
set neither no_quotes, nor
only_quote_strings
Possible parameters for the XML output driver:
xml_rlib_compat sets the
flag to create an RLIB compatible XML output.
Possible values to enable it are
yes,
true,
on or any positive non-zero
number. Anything else disables it.
When enabled, the toplevel element
will be <rlib>
and <Report>s
inside <pd>
won't be embedded in a
report element.
This method executes the report, constructs
the result in memory. It returns true
for success, false for failure.
It is a failure if the output format is unset.
public final OpenCReport::execute(): bool;
Dump the report output on the program's standard output channel.
public final OpenCReport::spool(): void;
Get the report output. The application
then can save it as a file.
This method returns the output in a
string if report execution
succeeded, otherwise it returns
false.
public final OpenCReport::get_output(): string|false;
Get the report content type. The application
then can add it as HTTP header line(s)
to the request. This method returns an
array of strings with
Content-Type:,
Content-Length: and
other header lines if report execution succeeded.
Otherwise it returns false.
public final OpenCReport::get_content_type(): array|false;
This method reports the OpenCReports library version.
public final static OpenCReport::version(): string;