Example code using the high level C API where everything concerning the report (including the data source) is described in the report XML:
#include <opencreport.h>
int main(void) {
opencreport *o = ocrpt_init();
if (!ocrpt_parse_xml(o, "report.xml")) {
printf("XML parse error\n");
ocrpt_free(o);
return 1;
}
ocrpt_set_output_format(o, OCRPT_OUTPUT_PDF);
ocrpt_execute(o);
ocrpt_spool(o);
ocrpt_free(o);
return 0;
}
The above code will load report.xml,
set the output format to PDF, runs the report and prints
its output on stdout.
This function loads the specified XML file
into the report handler. It returns
true for success,
false for failure.
bool
ocrpt_parse_xml(opencreport *o,
const char *filename);
This function parses the buffer as if it contained
XML contents and loads the details into the report handler.
It returns true for success,
false for failure.
bool
ocrpt_parse_xml_from_buffer(opencreport *o,
const char *buffer,
size_t size);
enum ocrpt_format_type {
OCRPT_OUTPUT_PDF = 1,
OCRPT_OUTPUT_HTML,
OCRPT_OUTPUT_TXT,
OCRPT_OUTPUT_CSV,
OCRPT_OUTPUT_XML,
OCRPT_OUTPUT_JSON,
OCRPT_OUTPUT_LAST
};
typedef enum ocrpt_format_type ocrpt_format_type;
void
ocrpt_set_output_format(opencreport *o,
ocrpt_format_type format);
ocrpt_format_type ocrpt_get_output_format(opencreport *o); const char * ocrpt_get_output_format_name(ocrpt_format_type format);
Set output parameters for the report.
void
ocrpt_set_output_parameter(opencreport *o,
const char *param,
const char *value);
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">.
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 are
yes, true,
on or any positive non-zero
number. 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()
to text/plain when enabled.
By default it's text/csv.
Possible values to enable it are
yes,
true,
on or any positive non-zero
number. Anything else disables it.
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 the decimal dot. For these languages,
either set csv_delimiter to
something else, or don't enable either
no_quotes or
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 function 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.
bool ocrpt_execute(opencreport *o);
Dump the report output on the program's standard output channel.
void ocrpt_spool(opencreport *o);
Get the report output. The application then can save it as a file.
const char * ocrpt_get_output(opencreport *o, size_t *length);
Get the report content type for web publishing.
The content type depends on the output type
the report was executed with.
It returns an array of
ocrpt_string * pointers
for potentially multiple HTTP header lines.
The last pointer in the array is
NULL.
const ocrpt_string ** ocrpt_get_content_type(opencreport *o);
Calling this function frees up the report handler structure and everything created for it, even the details that were created by the low level API.
void ocrpt_free(opencreport *o);
This function reports the OpenCReports library version.
const char * ocrpt_version(void);