pyreportjasper icon indicating copy to clipboard operation
pyreportjasper copied to clipboard

Error in generating pdf using json data

Open jaganeee opened this issue 3 years ago • 12 comments

hi, i just install the pyreportjasper using pip and installed java SE 11

i try to run the sample json code with Blank_A4.jrxml in reports folder

the code i tried is

import os
from pyreportjasper import PyReportJasper

def json_to_pdf():
   RESOURCES_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'resources')
   REPORTS_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'reports')
   input_file = os.path.join(REPORTS_DIR, 'Blank_A4.jrxml')
   output_file = os.path.join(REPORTS_DIR, 'json')
   conn = {
      'driver': 'json',
      'data_file': os.path.join(RESOURCES_DIR, 'generated.json'),
      'json_query': 'contacts.person'
   }
   pyreportjasper = PyReportJasper()
   pyreportjasper.config(
      input_file,
      output_file,
      output_formats=["pdf"],
      db_connection=conn
   )
   pyreportjasper.process_report()
   print('Result is the file below.')
   print(output_file + '.pdf')

json_to_pdf()

on running using py checl.py it shows the following .

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. Set system property 'org.apache.logging.log4j.simplelog.StatusLogger.level' to TRACE to show Log4j2 internal initialization logging. Result is the file below. G:\Sample Py\reports\json.pdf

i can get the blank pdf only. i can't able to figure out . guide me what is the problem

jaganeee avatar Mar 30 '21 05:03 jaganeee

Apparently you are using an example of blank jrxml, as the file name says.

There are two ways to generate using json.

Example 1 and the most suitable. https://replit.com/@JadsonRibeiro/json-pyreportjasper

Example 2 if your json is very large and you need to increase the maximum memory that the jvm can use to process your file https://replit.com/@JadsonRibeiro/jvmmax-mem-pyreportjasper#main.py

jadsonbr avatar Mar 30 '21 11:03 jadsonbr

i have tried the example in replit it shows the error as

Traceback (most recent call last): File "main.py", line 2, in from pyreportjasper import PyReportJasper ModuleNotFoundError: No module named 'pyreportjasper'

and also i copied all the files and i try in my own system it shows the following error

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. Set system property 'org.apache.logging.log4j.simplelog.StatusLogger.level' to TRACE to show Log4j2 internal initialization logging. WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by br.com.acesseonline.classpath.ApplicationClasspath (file:/C:/Users/laptopms/AppData/Local/Programs/Python/Python39/Lib/site-packages/pyreportjasper/libs/acesseonline-1.0.jar) to method java.net.URLClassLoader.addURL(java.net.URL) WARNING: Please consider reporting this to the maintainers of br.com.acesseonline.classpath.ApplicationClasspath WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release Traceback (most recent call last): File "G:\Sample Py\check.py", line 27, in json_to_pdf() File "G:\Sample Py\check.py", line 22, in json_to_pdf pyreportjasper.process_report() File "C:\Users\laptopms\AppData\Local\Programs\Python\Python39\lib\site-packages\pyreportjasper\pyreportjasper.py", line 182, in process_report raise error NameError: Error fill report: Erro fill internal: net.sf.jasperreports.engine.JRException: Error loading expression class: json_1617165573005_332740.

ur help is much appreciated

jaganeee avatar Mar 31 '21 04:03 jaganeee

The specified error is stating that you do not have the library.

To check run pip freeze and check if the library is in the output of the command and if it shows which version you are using?

The current version is pyreportjasper==2.1.2

jadsonbr avatar Mar 31 '21 12:03 jadsonbr

thanks for ur reply. i run the command pip freeze and it shows in my system

asgiref==3.3.1 astroid==2.4.2 colorama==0.4.4 Django==2.1.15 django-pyodbc==1.1.3 django-pyodbc-azure==2.1.0.0 isort==5.6.4 JPype1==1.2.1 lazy-object-proxy==1.4.3 mccabe==0.6.1 pyaes==1.6.1 pyasn1==0.4.8 pylint==2.6.0 pyodbc==4.0.30 pyreportjasper==2.1.2 pytz==2020.4 rsa==4.6 six==1.15.0 sql-server.pyodbc==1.0 sqlparse==0.4.1 Telethon==1.17.5 toml==0.10.1 wrapt==1.12.1

still i am getting the error

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. Set system property 'org.apache.logging.log4j.simplelog.StatusLogger.level' to TRACE to show Log4j2 internal initialization logging. WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by br.com.acesseonline.classpath.ApplicationClasspath (file:/C:/Users/laptopms/AppData/Local/Programs/Python/Python39/Lib/site-packages/pyreportjasper/libs/acesseonline-1.0.jar) to method java.net.URLClassLoader.addURL(java.net.URL) WARNING: Please consider reporting this to the maintainers of br.com.acesseonline.classpath.ApplicationClasspath WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release Traceback (most recent call last): File "G:\Sample Py\check.py", line 27, in json_to_pdf() File "G:\Sample Py\check.py", line 22, in json_to_pdf pyreportjasper.process_report() File "C:\Users\laptopms\AppData\Local\Programs\Python\Python39\lib\site-packages\pyreportjasper\pyreportjasper.py", line 182, in process_report raise error NameError: Error fill report: Erro fill internal: net.sf.jasperreports.engine.JRException: Error loading expression class: json_1617165573005_332740.

sorry i am new to this python and java. can't figure out where is the problem. ur help is appreciated

jaganeee avatar Apr 01 '21 05:04 jaganeee

If you can show the code you are trying to execute we can help you more effectively.

jadsonbr avatar Apr 01 '21 13:04 jadsonbr

thanks for ur reponse. here the details of the code and platform i am running

Windows 10 Home, Python 3.9

regarding java version it shows java version "11.0.10" 2021-01-19 LTS Java(TM) SE Runtime Environment 18.9 (build 11.0.10+8-LTS-162) Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.10+8-LTS-162, mixed mode)

on running pip freeze it shows asgiref==3.3.1 astroid==2.4.2 colorama==0.4.4 Django==2.1.15 django-pyodbc==1.1.3 django-pyodbc-azure==2.1.0.0 isort==5.6.4 JPype1==1.2.1 lazy-object-proxy==1.4.3 mccabe==0.6.1 pyaes==1.6.1 pyasn1==0.4.8 pylint==2.6.0 pyodbc==4.0.30 pyreportjasper==2.1.2 pytz==2020.4 rsa==4.6 six==1.15.0 sql-server.pyodbc==1.0 sqlparse==0.4.1 Telethon==1.17.5 toml==0.10.1 wrapt==1.12.1

i have attached the code which i run and it shows the same error that i mentioned in previous post Sample Py.zip

jaganeee avatar Apr 02 '21 03:04 jaganeee

Remove the current installation and install via git to use a compiled version for your operating system and you will no longer have the problem.

pip install git+https://github.com/acesseonline/pyreportjasper@master#egg=pyreportjasper  

jadsonbr avatar Apr 04 '21 18:04 jadsonbr

thanks a lot. its works expected. but i have some delay in getting the pdf report around 20 sec for just 100 rows of data. is it normal.

jaganeee avatar Apr 09 '21 11:04 jaganeee

Data source is in JSON, XML or database ?

jadsonbr avatar Apr 09 '21 11:04 jadsonbr

json data

jaganeee avatar Apr 10 '21 02:04 jaganeee

@jaganeee An example of this json could be made available to perform some tests?

jadsonbr avatar Aug 20 '21 16:08 jadsonbr

Issue closed for lack of interaction.

jadsonbr avatar Dec 27 '21 12:12 jadsonbr