API Reference¶
Class PyReportJasper¶
-
class
PyReportJasper
(*args, **kwargs)¶ Class responsible for facilitating the management and export of reports
-
classmethod
config
(input_file, output_file=False, output_formats=['pdf'], parameters={}, db_connection={},locale='pt_BR', resource=None)¶ Method responsible for preparing and validating the settings and parameters
Parameters: - input_file (str) – Input file (.jrxml|.jasper|.jrprint)
- output_file (str) – Output file or directory
- output_formats (list) – List with the formats you want to export. Options:
pdf
,rtf
,docx
,odt
,xml
,xls
,xlsx
,csv
,csv_meta
,ods
,pptx
,jrprint
- parameters (dict) – Dictionary with the parameters your report expects
- db_connection (dict) – Dictionary with the necessary information to generate the report. Options:
driver
,username
,password
,host
,database
,port
,jdbc_driver
,jdbc_url
,jdbc_dir
,db_sid
,xml_xpath
,data_file
,json_query
,jsonql_query
,csv_first_row
,csv_columns
,csv_record_del
,csv_field_del
,csv_out_field_del
,csv_charset
,csv_out_charset
. - locale (str) – Set locale with two-letter ISO-639 code or a combination of ISO-639 and ISO-3166 like de_DE. For a complete list of locales see Supported Locales
- resource (str) – Directory the files with resources that the report needs for correct generation and export.
-
classmethod
compile
(write_jasper=False)¶ Compiles the report or all reports into a directory if the input file parameter is a directory
Parameters: write_jasper (bool) – Sets whether to write the .jasper
output or not.-
classmethod
process_report
()¶ Process the report and export to the formats specified in the config method
-
classmethod
list_report_params
()¶ Lists the parameters defined in the report
Returns: Returns a parameter list Return type: list(str)
-
classmethod
process
(input_file, output_file=False, format_list=['pdf'], parameters={}, db_connection={}, locale='pt_BR', resource="")¶ Warning
This method still works more in the next versions will be removed.
Deprecated since version 2.1.0: Use
PyReportJasper.process_report()
instead.
-
classmethod
Class Config¶
-
class
Config
(*args, **kwargs)¶ Class for defining the settings to generate the reports.
-
jvm_maxmem
¶ Maximum memory used by the JVM
Type: str Value: ‘512M’ -
jvm_classpath
¶ The class path is the path that the Java runtime environment searches for classes and other resource files.
Type: str -
dbType
¶ Data source type
Type: str Options: None
,csv
,xml
,json
,jsonql
,mysql
,postgres
,oracle
,generic
-
dbDriver
¶ Jdbc driver class name for use with dbType: generic
Type: str -
dbHost
¶ Database host
Type: str -
dbName
¶ Database name
Type: str -
dbPasswd
¶ Database password
Type: str -
dbPort
¶ Database port
Type: int -
dbSid
¶ Oracle sid
Type: str -
dbUrl
¶ Jdbc url without user, passwd with dbType: generic
Type: str -
dbUser
¶ Database user
Type: str -
jdbcDir
¶ Directory where jdbc driver jars are located.
Type: str -
input
¶ Input file (.jrxml|.jasper|.jrprint)
Type: str -
dataFile
¶ Input file for file based datasource
Type: str -
csvFirstRow
¶ First row contains column headers
Type: bool -
csvColumns
¶ Comma separated list of column names
Type: list(str) -
csvRecordDel
¶ CSV Record Delimiter - defaults to line.separator
Type: str -
csvFieldDel
¶ CSV Field Delimiter - defaults to “,”
Type: str -
csvCharset
¶ CSV charset - defaults to “utf-8”
Type: str -
xmlXpath
¶ XPath for XML Datasource
Type: str -
jsonQuery
¶ JSON query string for JSON Datasource
Type: str -
jsonQLQuery
¶ JSONQL query string for JSONQL Datasource
Type: str -
locale
¶ Set locale with two-letter ISO-639 code or a combination of ISO-639 and ISO-3166 like en_US.
For a complete list of locales see Supported Locales
Type: str -
output
¶ Directory or basename of outputfile(s)
Type: str -
outputFormats
¶ A list of output formats
Type: list(str) Options: pdf
,rtf
,docx
,odt
,xml
,xls
,xlsx
,csv
,csv_meta
,ods
,pptx
,jrprint
-
params
¶ Dictionary with the names of the parameters and their respective values.
Exemple:
{'NAME_PARAM_1': 'value param 1', 'NAME_PARAM_2': 'value param 2'}
Type: dict -
printerName
¶ Name of printer
Type: str -
reportName
¶ Set internal report/document name when printing
Type: str -
resource
¶ Path to report resource dir or jar file. If <resource> is not given the input directory is used.
Type: str -
writeJasper
¶ Write .jasper file to imput dir if jrxml is processed
Type: bool Value: False -
outFieldDel
¶ Export CSV (Metadata) Field Delimiter - defaults to “,”
Type: str -
outCharset
¶ Export CSV (Metadata) Charset - defaults to “utf-8”
Type: str -
askFilter
¶
Type: str
Options: a
- all (user and system definded) prarmsae
- all empty paramsu
- user paramsue
- empty user paramsp
- user params marked for promptingpe
- empty user params markted for prompting-
classmethod
has_output
()¶
Valid if there is a path or file for the output
Returns: Returns true if there is a defined path or file for output otherwise false. Return type: bool -
classmethod
is_write_jasper
()¶
Valid if it is to generate a .jasper
Returns: Returns true
if the .jasper is to be generated, otherwise it isfalse
.Return type: bool -
classmethod
has_jdbc_dir
()¶
Validates if there is a path or file for jdbc .jar
Returns: Returns true
if it exists, otherwisefalse
.Return type: bool -
classmethod
has_resource
()¶
Validates if there is a .jar or path with several .jar to add to the class path
Returns: Returns true
if it exists, otherwisefalse
.Return type: bool -
Class Report¶
-
class
Report
(config: Config, input_file)¶ Class responsible for instantiating the JVM and loading the necessary Java objects for manipulating the files to compile, generate and export the reports.
Parameters: - config (Config) – Config class instance
- input_file (str) – Input file (.jrxml|.jasper|.jrprint)
-
classmethod
compile
()¶ Compile the report
-
classmethod
compile_to_file
()¶ Emit a .jasper compiled version of the report definition .jrxml file.
-
classmethod
fill
()¶ Executes the
fill_internal()
method
-
classmethod
fill_internal
()¶ Method responsible for filling the report
-
classmethod
get_output_stream
(suffix)¶ Return a file-based output stream with the given suffix
Parameters: suffix (str) – File suffix Returns: Returns an output stream from the input file. Return type: OutputStream (java)
-
classmethod
export_pdf
()¶ Export the report in
pdf
format
-
classmethod
export_rtf
()¶ Export the report in
rtf
format
-
classmethod
export_docx
()¶ Export the report in
docx
format
-
classmethod
export_odt
()¶ Export the report in
odt
format
-
classmethod
export_xml
()¶ Export the report in
xml
format
-
classmethod
export_xls
()¶ Export the report in
xls
format
-
classmethod
export_xls_meta
()¶ Export the report in
xls
Metadata Exporter format
-
classmethod
export_xlsx
()¶ Export the report in
xlsx
format
-
classmethod
export_csv
()¶ Export the report in
csv
format
-
classmethod
export_csv_meta
()¶ Export the report in
csv
Metadata Exporter format
-
classmethod
export_ods
()¶ Export the report in
ods
format
-
classmethod
export_pptx
()¶ Export the report in
pptx
format
-
classmethod
export_jrprint
()¶ Export the report in
jrprint
format
-
classmethod
get_report_parameters
()¶ Returns a list of all report parameters
Returns: Returns a list of parameters Return type: list(str)
-
classmethod
get_main_dataset_query
()¶ For JSON, JSONQL and any other data types that need a query to be provided, an obvious default is to use the one written into the report, since that is likely what the report designer debugged/intended to be used. This provides access to the value so it can be used as needed.
Returns: Return a string of main dataset query. Return type: str
-
classmethod
add_jar_class_path
(dir_or_jar)¶ Method responsible for adding a
.jar
toclass_path
or a list of.jar
files in an informed directoryParameters: dir_or_jar (str) – A .jar
file or directory containing one or more.jar
Class Db¶
-
class
Db
¶ Class responsible for managing the report data source
-
classmethod
get_csv_datasource
(config: Config)¶ Method responsible for creating a data source from an informed csv file
Parameters: config (Config) – Config class instance Returns: Returns a data source of type csv Return type: net.sf.jasperreports.engine.data.JRCsvDataSource
(java)
-
classmethod
get_xml_datasource
(config: Config)¶ Method responsible for creating a data source from an informed xml file
Parameters: config (Config) – Config class instance Returns: Returns a data source of type xml Return type: net.sf.jasperreports.engine.data.JRXmlDataSource
(java)
-
classmethod
get_json_datasource
(config: Config)¶ Method responsible for creating a data source from an informed json file
Parameters: config (Config) – Config class instance Returns: Returns a data source of type json Return type: net.sf.jasperreports.engine.data.JsonDataSource
(java)
-
classmethod
get_jsonql_datasource
(config: Config)¶ Method responsible for creating a data source from an informed json file
Parameters: config (Config) – Config class instance Returns: Returns a data source of type jsonql Return type: net.sf.jasperreports.engine.data.JsonQLDataSource
(java)
-
classmethod
get_data_file_input_stream
(config: Config)¶ Get InputStream corresponding to the configured dataFile.
Parameters: config (Config) – Config class instance Returns: Returns a InputStream Return type: java.io.InputStream
(java)
-
classmethod
get_connection
(config: Config)¶ Method responsible for obtaining a connection to a database
Returns: Returns database connection Return type: java.sql.Connection
(java)
-
classmethod