acesseonline / pyreportjasper

Python Reporting with JasperReports
https://pyreportjasper.readthedocs.io/en/latest/
GNU General Public License v3.0
127 stars 75 forks source link

Example font-calibri-pyreportjasper does not work for me #89

Closed humbertolopezleon closed 3 years ago

humbertolopezleon commented 3 years ago

Describe the bug Example font-calibri-pyreportjasper does not work for me. I tried it from the same page where the example is published and on my local PC and it shows the same error.

To Reproduce Steps to reproduce the behavior:

  1. Download the example
  2. Install dependencies and run

Expected behavior You must generate a PDF file using the "Calibri" font

Screenshots This photo is to show the error that is displayed when testing the example from the site where it is posted. image

Desktop: These are the characteristics of the execution environment on my PC

Jaspersoft Studio (please complete the following information):

Error trace OpenJDK 64-Bit Server VM warning: Archived non-system classes are disabled because the java.system.class.loader property is specified (value = "org.update4j.DynamicClassLoader"). To use archived non-system classes, this property must be not be set 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:/opt/virtualenvs/python3/src/pyreportjasper/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 "main.py", line 23, in contains_image() File "main.py", line 18, in contains_image pyreportjasper.process_report() File "/opt/virtualenvs/python3/src/pyreportjasper/pyreportjasper/pyreportjasper.py", line 182, in process_report raise error NameError: Error fill report: Erro fill internal: net.sf.jasperreports.engine.util.JRFontNotFoundException: Font "Calibri" is not available to the JVM. See the Javadoc for more details.

jadsonbr commented 3 years ago

In repl.it, not everything we can simulate. in the case of the font, an example of how to implement it was given.

In the discussion below you can see how to implement other font in your report.

https://github.com/acesseonline/pyreportjasper/discussions/88

humbertolopezleon commented 3 years ago

En repl.it, no todo lo que podemos simular. en el caso de la fuente, se dio un ejemplo de cómo implementarlo.

En la discusión a continuación, puede ver cómo implementar otras fuentes en su informe.

# 88

Thanks for the answer, but my problem is not when importing a font, but the import of the .jar fails. I took the font-calibri-pyreportjasper example for the similarity to the implementation in my code, as I also need to add a resource (.jar) to the class path. I have followed the instructions in the documentation but I have not succeeded. I think it has to do with the warnings when compiling the template (.jrxml).

OpenJDK 64-Bit Server VM warning: Archived non-system classes are disabled because the java.system.class.loader property is specified (value = "org.update4j.DynamicClassLoader"). To use archived non-system classes, this property must be not be set 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:/opt/virtualenvs/python3/src/pyreportjasper/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

I have searched for information on these notices but it is not clear yet what is happening. Could you guide me on this topic? Is there an example implemented on how to use the functionalities available in a library (.jar) in a template (.jrxml)?

jadsonbr commented 3 years ago

The warnings reported are from the ApplicationClasspath method of inspecting to add classes from other jar at runtime. Because it is a python library and in certain cases there is a need to import other jar at runtime, the informed operation is necessary, so the warning. These warnings do not prevent the library from running, it just tells us what is going on.

You must tell them exactly what you are trying to do in order to help them in the best possible way. To use a bank connection jar it is in one place to add another type of jar it is in another place. Be more explicit in what you are trying to do so that you can show him the way to resolve.

humbertolopezleon commented 3 years ago

I have posted an example showing the error when to use the functionalities of a java library (datazucar.util.jar) in a test template (test.jrxml).

The description of the execution environment are the same as those described at the beginning.

Could you help me to understand what I am doing wrong?

winkelband commented 3 years ago

I also was trying to use an extra font by specifying the path in the resource parameter for the classpath, but it did not work. Other resources like images specified by the resource parameter work without flaws.

But by saving the font extension under the directory site-packages/pyreportjasper/libs/ the report compiled without any problems.

I’m using pyreportjasper installed from source via git.

While I can’t help why the resource parameter isn’t working in our cases, maybe the workaround can help you, @humbertolopezleon.

tobecwb commented 3 years ago

I can confirm that using a external font don't works. Even the calibri example don't works.

To make sure, I tried on Linux and Windows Environment, and removed the Calibri font that was installed on Windows. The only source of calibri font was in JAR provided on the example.

Even If I put the font-calibri.jar on the same folder, specified the resource dir, the error Font "Calibri" is not available to the JVM. See the Javadoc for more details. was throw. The same occur with the example provided, without change anything.

The workaround provided by @winkelband resolved the issue, put the font-calibri.jar on site-packages/pyreportjasper/libs For some reason, the resource option don't works for fonts. For images and subreports is working correctly.

tobecwb commented 3 years ago

Another workaround On report.py (of pyreportjasper package), on __init__, line 28, change from:

            if self.config.jvm_classpath is None:
                jpype.startJVM("-Djava.system.class.loader=org.update4j.DynamicClassLoader",
                               "-Xmx{}".format(self.config.jvm_maxmem),
                               classpath=[
                                   os.path.join(self.LIB_PATH, "*"),
                                   os.path.join(self.JDBC_PATH, "*"),
                               ])

to

            if self.config.jvm_classpath is None:
                jpype.startJVM("-Djava.system.class.loader=org.update4j.DynamicClassLoader",
                               "-Xmx{}".format(self.config.jvm_maxmem),
                               classpath=[
                                   os.path.join(self.LIB_PATH, "*"),
                                   os.path.join(self.JDBC_PATH, "*"),
                                   os.path.join(self.config.resource, "*"),
                               ])

I believe that the RESOURCE folder was not specified as classpath on JPype

humbertolopezleon commented 3 years ago

Another workaround On report.py (of pyreportjasper package), on __init__, line 28, change from:

            if self.config.jvm_classpath is None:
                jpype.startJVM("-Djava.system.class.loader=org.update4j.DynamicClassLoader",
                               "-Xmx{}".format(self.config.jvm_maxmem),
                               classpath=[
                                   os.path.join(self.LIB_PATH, "*"),
                                   os.path.join(self.JDBC_PATH, "*"),
                               ])

to

            if self.config.jvm_classpath is None:
                jpype.startJVM("-Djava.system.class.loader=org.update4j.DynamicClassLoader",
                               "-Xmx{}".format(self.config.jvm_maxmem),
                               classpath=[
                                   os.path.join(self.LIB_PATH, "*"),
                                   os.path.join(self.JDBC_PATH, "*"),
                                   os.path.join(self.config.resource, "*"),
                               ])

I believe that the RESOURCE folder was not specified as classpath on JPype

This solution works perfect, but I had to install pyreportjasper from the master branch: pip install git+https://github.com/acesseonline/pyreportjasper.git

When I install it from the pip repos it shows me the same error mentioned in issue #92

All that remains is to include its modification in the master branch of the project. Thank you for your contribution.