2

I am developing a plugin for QGIS which one of its functionalities is to create different reports in .pdf taking the data from a PostGIS database.

The software I am using to create the reports is: iReport 5.6.0.

The package used to generate the reports is JasperReports 6.3.1 library through JasperStarter v3.1 command-line tool.

The problem comes when I try to use the library pyreportjasper from my plugin code like this:

import pyjasper import os def compileJasper(self): input_file = 'report.jasper' output = os.path.dirname(os.path.abspath(__file__)) + '\output' jasperpy = pyjasper.jasperpy jasper = jasperpy.JasperPy() jasper.process( input_file, output, format_list=["pdf", "rtf"])

The error I get:

File "C:\PROGRA~1\QGIS2~1.18\apps\Python27\lib\site-packages\pyjasper\jasperpy.py", line 144, in process
            return self.execute()
          File "C:\PROGRA~1\QGIS2~1.18\apps\Python27\lib\site-packages\pyjasper\jasperpy.py", line 183, in execute
            output = subprocess.check_call(self.command, shell=True)
          File "C:\PROGRA~1\QGIS2~1.18\apps\Python27\lib\subprocess.py", line 542, in check_call
            raise CalledProcessError(retcode, cmd)
        CalledProcessError: Command 'jasperstarter --locale pt_BR process "[INPUT_PATH]\report.jasper" -o "[OUTPUT_ROUTE]\output" -f pdf rtf' returned non-zero exit status 1

it seems that this library uses subprocess.run() and this function is implemented in Python 3.5. As far as I know, QGIS uses Python 2.7.

I’ve tried to use the console with: jasperstarter --locale pt_BR process "[INPUT_PATH]\report.jasper" -o "[OUTPUT_PATH]\output" -f pdf rtf and it generates the report successfully

Does any one know how to deal with this issue?

If not, does anyone know another software alternative to create reports from a QGIS plugin?

2

I have finally used

class MyPDFGenerator():
    def __init__(self):

        self.driver = "C:/JasperStarter/bin/jasperstarter.exe --locale es_ES process"
        self.name= " [input_path]/report2.jrxml"
        self.out= " -o [output_path] -f pdf"
        self.bd = " -t postgres -u postgres -H [host]-n [name]-p [pass]--jdbc-dir C:\driver"
        self.parametter= " -P codmuni=8"

    def makePDF(self):        
        cmd= self.driver + self.name+ self.out+ self.bd + self.parametter
        os.system(cmd)

in C:\driver I have postgresql-42.1.1.jar file

More documentation in JasperStarter

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.