B4J Library jJasperReports Library

Hi. I want to share this jJasperReports library with the community.
It needs several libraries to work. I provided a link: download
---More libraries needed (missing from the first link): download
You also need to download databases jdbc drivers: sql jdts, mysql and oracle
New Link (All jar files are included in this link): Download
All jars need to be placed in Additional Libraries folder.
In the B4J project you need to add a jar file: #AdditionalJar: itext-2.1.7.js1
Library files and a small example is provided.
Please feel free to test the library.
Note: for some reason when using SubReports, the compiled (.jasper) files need to be in the same level as the app jar file. XML Reports (.jrxml) can be in any other folder different from the app jar file. (e.g. if report.jrxml is in File.DirApp & "/reports" then all compiled (.jasper) subreports need to be in File.DirApp. In the example provided .jrxml and .jasper are in the same level as jaspertest.jar.

v1.00 - Release
v1.10 - SQLite support added. MySQL useSSL variable added.
v1.12 - Changed the way the JasperViewer works. Now you can set the form to full screen, use the default size and location or set a specific size and location.
v1.13 - Added method PrintDirectlyToPrinter.
v1.20 - Access support added via uCanAccess jdbc driver. Note: When creating reports in Jaspersoft Studio you need to add all jar files that ucanaccess needs. The metadata won't work but you can create a query and it will work.
v1.22 - Added functions to export report to XLS and XLSX. Note: need 2 more jar files: download. Copy them into Additional Libraries folder.
v1.24 - Added function Print3 to be able to show reports without a Data Source.

------------------------------------------

NEW VERSION 2.00
Special thanks to Num3 for testing this library and helping me getting it done.

Instructions:
1. Libraries needed: Donwload
2. Place all jars in Additional Libraries folder
3. Specify in B4J project with #AdditionalJar: the database that is going to be used. (e.g. #AdditionalJar: mysql-connector-java-5.1.49-bin)
a. If using ucanaccess-5.1.0 database please add these in addition to #AdditionalJar: ucanaccess-5.0.1:
- #AdditionalJar: commons-lang3-3.8.1
- #AdditionalJar: commons-logging-1.2
- #AdditionalJar: hsqldb-2.5.0
- #AdditionalJar: jackcess-3.0.1

v2.00 - Same functionality as v1.24 but based on jasperreports-6.17.0. Previous v1.24 was based on jasperreports-6.7.1.
 

Attachments

  • mainform.png
    mainform.png
    8.1 KB · Views: 1,536
  • jrxml_exported_to_pdf.png
    jrxml_exported_to_pdf.png
    53.9 KB · Views: 1,520
  • jrxml_subreports.png
    jrxml_subreports.png
    53.6 KB · Views: 1,621
  • jrxml_single_report.png
    jrxml_single_report.png
    16.7 KB · Views: 1,542
  • jJasperReports.zip
    10.2 KB · Views: 849
  • sqlite_report.png
    sqlite_report.png
    35.1 KB · Views: 1,362
  • jaspertest.zip
    2.8 KB · Views: 897
  • jJasperReports - 1.24.zip
    17.4 KB · Views: 570
  • jJasperReports - 2.00.zip
    17.6 KB · Views: 450
Last edited:

cjpryor

Active Member
Licensed User
Okay, here we go!!!!

First - Sample report that is using "DejaVu Sans" (this gets compiled into a .jasper file that is called to display the data)

XML:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.17.0.final using JasperReports Library version 6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd  -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Collections" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ced95029-b569-4027-895c-af2843a4e088">
    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
    <property name="com.jaspersoft.studio.data.sql.SQLQueryDesigner.sash.w1" value="163"/>
    <property name="com.jaspersoft.studio.data.sql.SQLQueryDesigner.sash.w2" value="832"/>
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="nmcswDB"/>
    <style name="Title" fontName="DejaVu Sans" fontSize="50" isBold="true"/>
    <style name="SubTitle" forecolor="#736343" fontName="DejaVu Sans" fontSize="18"/>
    <style name="Column header" forecolor="#666666" fontName="DejaVu Sans" fontSize="12" isBold="true"/>
    <style name="Detail" fontName="DejaVu Sans" fontSize="12"/>
    <style name="Row" mode="Transparent">
        <conditionalStyle>
            <conditionExpression><![CDATA[$V{REPORT_COUNT}%2 == 0]]></conditionExpression>
            <style backcolor="#E6DAC3"/>
        </conditionalStyle>
    </style>
    <queryString language="SQL">
        <![CDATA[SELECT   
COLLECTIONTEMPLATES . COLLECTIONID,   
COLLECTIONTEMPLATES . COLLECTIONNAME,   
COLLECTIONTEMPLATES . COLLECTIONDESCRIPTION
FROM     
COLLECTIONTEMPLATES]]>
    </queryString>
    <field name="COLLECTIONNAME" class="java.lang.Object">
        <property name="com.jaspersoft.studio.field.name" value="COLLECTIONNAME"/>
        <property name="com.jaspersoft.studio.field.label" value="COLLECTIONNAME"/>
        <property name="com.jaspersoft.studio.field.tree.path" value="COLLECTIONTEMPLATES"/>
    </field>
    <field name="COLLECTIONDESCRIPTION" class="java.lang.Object">
        <property name="com.jaspersoft.studio.field.name" value="COLLECTIONDESCRIPTION"/>
        <property name="com.jaspersoft.studio.field.label" value="COLLECTIONDESCRIPTION"/>
        <property name="com.jaspersoft.studio.field.tree.path" value="COLLECTIONTEMPLATES"/>
    </field>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch">
            <staticText>
                <reportElement style="Title" x="97" y="0" width="370" height="62" uuid="1a652692-054a-40f3-ade5-68d8da36626d"/>
                <textElement verticalAlignment="Middle"/>
                <text><![CDATA[Collections]]></text>
            </staticText>
        </band>
    </title>
    <pageHeader>
        <band splitType="Stretch"/>
    </pageHeader>
    <columnHeader>
        <band height="16" splitType="Stretch">
            <line>
                <reportElement positionType="FixRelativeToBottom" x="0" y="15" width="555" height="1" uuid="1a61a836-d137-48b1-ad67-6ff64600bf93"/>
                <graphicElement>
                    <pen lineWidth="0.5" lineColor="#999999"/>
                </graphicElement>
            </line>
            <staticText>
                <reportElement style="Column header" x="0" y="0" width="277" height="15" forecolor="#736343" uuid="001eaf52-d57a-4687-adf6-82cf6e665427">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="4938894f-47bf-4592-b4a8-8d1caa5cd8e4"/>
                </reportElement>
                <text><![CDATA[COLLECTIONNAME]]></text>
            </staticText>
            <staticText>
                <reportElement style="Column header" x="277" y="0" width="277" height="15" forecolor="#736343" uuid="94c53a2b-29d2-4617-b5ca-18fcd5bb2c03">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="61fca909-3a81-4ee1-b688-072607e4fee9"/>
                </reportElement>
                <text><![CDATA[COLLECTIONDESCRIPTION]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="15" splitType="Stretch">
            <frame>
                <reportElement style="Row" mode="Opaque" x="0" y="0" width="555" height="15" uuid="a98495d8-3c8d-4fa0-81f5-30c3efc2f766"/>
                <textField textAdjust="StretchHeight">
                    <reportElement style="Detail" x="0" y="0" width="277" height="15" uuid="efe9522c-0049-4c53-ad42-6f94e33005a0">
                        <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="4938894f-47bf-4592-b4a8-8d1caa5cd8e4"/>
                    </reportElement>
                    <textFieldExpression><![CDATA[$F{COLLECTIONNAME}]]></textFieldExpression>
                </textField>
                <textField textAdjust="StretchHeight">
                    <reportElement style="Detail" x="277" y="0" width="277" height="15" uuid="868845a7-7c21-405a-93f5-ad2921e29708">
                        <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="61fca909-3a81-4ee1-b688-072607e4fee9"/>
                    </reportElement>
                    <textFieldExpression><![CDATA[$F{COLLECTIONDESCRIPTION}]]></textFieldExpression>
                </textField>
            </frame>
        </band>
    </detail>
    <columnFooter>
        <band height="45" splitType="Stretch">
            <line>
                <reportElement positionType="FixRelativeToBottom" x="0" y="3" width="555" height="1" uuid="fa45a887-615a-4d84-a2d7-8a2219671b3c"/>
                <graphicElement>
                    <pen lineWidth="0.5" lineColor="#999999"/>
                </graphicElement>
            </line>
        </band>
    </columnFooter>
    <pageFooter>
        <band height="25" splitType="Stretch">
            <frame>
                <reportElement mode="Opaque" x="-21" y="1" width="597" height="24" forecolor="#D0B48E" backcolor="#F2EBDF" uuid="183682bc-d976-4756-83e0-6625a3f98ed1"/>
                <textField evaluationTime="Report">
                    <reportElement style="Column header" x="533" y="0" width="40" height="20" forecolor="#736343" uuid="0193f9b3-1559-491a-8580-b6988863b6a1"/>
                    <textElement verticalAlignment="Middle">
                        <font size="10" isBold="false"/>
                    </textElement>
                    <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement style="Column header" x="453" y="0" width="80" height="20" forecolor="#736343" uuid="d00b105e-494b-418b-8ac9-8b1b4824f4f0"/>
                    <textElement textAlignment="Right" verticalAlignment="Middle">
                        <font size="10" isBold="false"/>
                    </textElement>
                    <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
                </textField>
                <textField pattern="EEEEE dd MMMMM yyyy">
                    <reportElement style="Column header" x="22" y="1" width="197" height="20" forecolor="#736343" uuid="0616f3fe-0354-456f-8911-ec30ec51a5ae"/>
                    <textElement verticalAlignment="Middle">
                        <font size="10" isBold="false"/>
                    </textElement>
                    <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
                </textField>
            </frame>
        </band>
    </pageFooter>
    <summary>
        <band splitType="Stretch"/>
    </summary>
</jasperReport>

Second - B4X code that calls it:

B4X:
Private Sub Button_Open_Report_Click
    
    Dim jasper As JasperReports
    Dim report As JasperReport
    Dim print As JasperPrint
    Dim conn As JasperConnection
    
    Try
        
        Dim reportName As String = reportFileNamesList.Get(selectedReportIndex)
        
        'DEBUG force error
        'Dim reportName As String = reportFileNamesList.Get("xyz")
        
        jasper.InitializeParameters
        jasper.AddParameter("collectionId", selectedCollectionId)
        jasper.AddParameter("itemId", selectedItemId)
        
        jasper.AddParameter("SUBREPORT_DIR", File.DirData("nmcollector/Reports") & MainPage.pathSeparator )
        
        'report = jasper.CompileXML(File.Combine(File.DirData("nmcollector/Reports"),"Collections.jasper"))
        'report = jasper.CompileXML(File.Combine(File.DirData("nmcollector/Reports"),reportName))
        report = jasper.LoadJRReport(File.Combine(File.DirData("nmcollector/Reports"),reportName))
        
        conn = jasper.getConnectionSQLite(File.Combine(File.DirData("nmcollector"),"nmcswDB.sqlite"))
        print = jasper.Print(report, jasper.parameters, conn)
        jasper.JasperViewer(print, False)
        
    Catch
        
        Log("Open Report, error = [" & LastException & "]")
        'Wait For (xui.MsgboxAsync(LastException, "Error")) Msgbox_Result (Result As Int)
                
        Dim sf As Object = xui.Msgbox2Async(LastException, "Error", "okay", "", "", Null)
        Wait For (sf) Msgbox_Result (Result As Int)
        
    End Try
    
End Sub

Third - the error I see in Release mode - works just find in Debug mode.

Open Report, error = [(JRFontNotFoundException) net.sf.jasperreports.engine.util.JRFontNotFoundException: Font "DejaVu Sans" is not available to the JVM. See the Javadoc for more details.]
 

Juan Marrero

Active Member
Licensed User
Longtime User
okay, I am stuck in my other approach and submitted a request for help in another thread so I will refactor my B4J application to use your jJasperReort library now - just have to find it in my code repository.

:)

Thanks
Was that approach DynamicJasper?
 

cjpryor

Active Member
Licensed User
No, I just wrote a simple java program that takes arguments from B4X and displays the report. You can find a description, including where I got stuck, in this post:


BTW, I started with IntelliJ but then switched to Eclipse since I already knew how to build a "fat" jar in Eclipse. I just started looking at how to build a B4X library so I am going to go down that path next. Perhaps it will provide hints about how to properly build my jar file for my simple Java program.
 

Juan Marrero

Active Member
Licensed User
Longtime User
Okay, here we go!!!!

First - Sample report that is using "DejaVu Sans" (this gets compiled into a .jasper file that is called to display the data)

XML:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.17.0.final using JasperReports Library version 6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd  -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Collections" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ced95029-b569-4027-895c-af2843a4e088">
    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
    <property name="com.jaspersoft.studio.data.sql.SQLQueryDesigner.sash.w1" value="163"/>
    <property name="com.jaspersoft.studio.data.sql.SQLQueryDesigner.sash.w2" value="832"/>
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="nmcswDB"/>
    <style name="Title" fontName="DejaVu Sans" fontSize="50" isBold="true"/>
    <style name="SubTitle" forecolor="#736343" fontName="DejaVu Sans" fontSize="18"/>
    <style name="Column header" forecolor="#666666" fontName="DejaVu Sans" fontSize="12" isBold="true"/>
    <style name="Detail" fontName="DejaVu Sans" fontSize="12"/>
    <style name="Row" mode="Transparent">
        <conditionalStyle>
            <conditionExpression><![CDATA[$V{REPORT_COUNT}%2 == 0]]></conditionExpression>
            <style backcolor="#E6DAC3"/>
        </conditionalStyle>
    </style>
    <queryString language="SQL">
        <![CDATA[SELECT  
COLLECTIONTEMPLATES . COLLECTIONID,  
COLLECTIONTEMPLATES . COLLECTIONNAME,  
COLLECTIONTEMPLATES . COLLECTIONDESCRIPTION
FROM    
COLLECTIONTEMPLATES]]>
    </queryString>
    <field name="COLLECTIONNAME" class="java.lang.Object">
        <property name="com.jaspersoft.studio.field.name" value="COLLECTIONNAME"/>
        <property name="com.jaspersoft.studio.field.label" value="COLLECTIONNAME"/>
        <property name="com.jaspersoft.studio.field.tree.path" value="COLLECTIONTEMPLATES"/>
    </field>
    <field name="COLLECTIONDESCRIPTION" class="java.lang.Object">
        <property name="com.jaspersoft.studio.field.name" value="COLLECTIONDESCRIPTION"/>
        <property name="com.jaspersoft.studio.field.label" value="COLLECTIONDESCRIPTION"/>
        <property name="com.jaspersoft.studio.field.tree.path" value="COLLECTIONTEMPLATES"/>
    </field>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch">
            <staticText>
                <reportElement style="Title" x="97" y="0" width="370" height="62" uuid="1a652692-054a-40f3-ade5-68d8da36626d"/>
                <textElement verticalAlignment="Middle"/>
                <text><![CDATA[Collections]]></text>
            </staticText>
        </band>
    </title>
    <pageHeader>
        <band splitType="Stretch"/>
    </pageHeader>
    <columnHeader>
        <band height="16" splitType="Stretch">
            <line>
                <reportElement positionType="FixRelativeToBottom" x="0" y="15" width="555" height="1" uuid="1a61a836-d137-48b1-ad67-6ff64600bf93"/>
                <graphicElement>
                    <pen lineWidth="0.5" lineColor="#999999"/>
                </graphicElement>
            </line>
            <staticText>
                <reportElement style="Column header" x="0" y="0" width="277" height="15" forecolor="#736343" uuid="001eaf52-d57a-4687-adf6-82cf6e665427">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="4938894f-47bf-4592-b4a8-8d1caa5cd8e4"/>
                </reportElement>
                <text><![CDATA[COLLECTIONNAME]]></text>
            </staticText>
            <staticText>
                <reportElement style="Column header" x="277" y="0" width="277" height="15" forecolor="#736343" uuid="94c53a2b-29d2-4617-b5ca-18fcd5bb2c03">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="61fca909-3a81-4ee1-b688-072607e4fee9"/>
                </reportElement>
                <text><![CDATA[COLLECTIONDESCRIPTION]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="15" splitType="Stretch">
            <frame>
                <reportElement style="Row" mode="Opaque" x="0" y="0" width="555" height="15" uuid="a98495d8-3c8d-4fa0-81f5-30c3efc2f766"/>
                <textField textAdjust="StretchHeight">
                    <reportElement style="Detail" x="0" y="0" width="277" height="15" uuid="efe9522c-0049-4c53-ad42-6f94e33005a0">
                        <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="4938894f-47bf-4592-b4a8-8d1caa5cd8e4"/>
                    </reportElement>
                    <textFieldExpression><![CDATA[$F{COLLECTIONNAME}]]></textFieldExpression>
                </textField>
                <textField textAdjust="StretchHeight">
                    <reportElement style="Detail" x="277" y="0" width="277" height="15" uuid="868845a7-7c21-405a-93f5-ad2921e29708">
                        <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="61fca909-3a81-4ee1-b688-072607e4fee9"/>
                    </reportElement>
                    <textFieldExpression><![CDATA[$F{COLLECTIONDESCRIPTION}]]></textFieldExpression>
                </textField>
            </frame>
        </band>
    </detail>
    <columnFooter>
        <band height="45" splitType="Stretch">
            <line>
                <reportElement positionType="FixRelativeToBottom" x="0" y="3" width="555" height="1" uuid="fa45a887-615a-4d84-a2d7-8a2219671b3c"/>
                <graphicElement>
                    <pen lineWidth="0.5" lineColor="#999999"/>
                </graphicElement>
            </line>
        </band>
    </columnFooter>
    <pageFooter>
        <band height="25" splitType="Stretch">
            <frame>
                <reportElement mode="Opaque" x="-21" y="1" width="597" height="24" forecolor="#D0B48E" backcolor="#F2EBDF" uuid="183682bc-d976-4756-83e0-6625a3f98ed1"/>
                <textField evaluationTime="Report">
                    <reportElement style="Column header" x="533" y="0" width="40" height="20" forecolor="#736343" uuid="0193f9b3-1559-491a-8580-b6988863b6a1"/>
                    <textElement verticalAlignment="Middle">
                        <font size="10" isBold="false"/>
                    </textElement>
                    <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement style="Column header" x="453" y="0" width="80" height="20" forecolor="#736343" uuid="d00b105e-494b-418b-8ac9-8b1b4824f4f0"/>
                    <textElement textAlignment="Right" verticalAlignment="Middle">
                        <font size="10" isBold="false"/>
                    </textElement>
                    <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
                </textField>
                <textField pattern="EEEEE dd MMMMM yyyy">
                    <reportElement style="Column header" x="22" y="1" width="197" height="20" forecolor="#736343" uuid="0616f3fe-0354-456f-8911-ec30ec51a5ae"/>
                    <textElement verticalAlignment="Middle">
                        <font size="10" isBold="false"/>
                    </textElement>
                    <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
                </textField>
            </frame>
        </band>
    </pageFooter>
    <summary>
        <band splitType="Stretch"/>
    </summary>
</jasperReport>

Second - B4X code that calls it:

B4X:
Private Sub Button_Open_Report_Click
   
    Dim jasper As JasperReports
    Dim report As JasperReport
    Dim print As JasperPrint
    Dim conn As JasperConnection
   
    Try
       
        Dim reportName As String = reportFileNamesList.Get(selectedReportIndex)
       
        'DEBUG force error
        'Dim reportName As String = reportFileNamesList.Get("xyz")
       
        jasper.InitializeParameters
        jasper.AddParameter("collectionId", selectedCollectionId)
        jasper.AddParameter("itemId", selectedItemId)
       
        jasper.AddParameter("SUBREPORT_DIR", File.DirData("nmcollector/Reports") & MainPage.pathSeparator )
       
        'report = jasper.CompileXML(File.Combine(File.DirData("nmcollector/Reports"),"Collections.jasper"))
        'report = jasper.CompileXML(File.Combine(File.DirData("nmcollector/Reports"),reportName))
        report = jasper.LoadJRReport(File.Combine(File.DirData("nmcollector/Reports"),reportName))
       
        conn = jasper.getConnectionSQLite(File.Combine(File.DirData("nmcollector"),"nmcswDB.sqlite"))
        print = jasper.Print(report, jasper.parameters, conn)
        jasper.JasperViewer(print, False)
       
    Catch
       
        Log("Open Report, error = [" & LastException & "]")
        'Wait For (xui.MsgboxAsync(LastException, "Error")) Msgbox_Result (Result As Int)
               
        Dim sf As Object = xui.Msgbox2Async(LastException, "Error", "okay", "", "", Null)
        Wait For (sf) Msgbox_Result (Result As Int)
       
    End Try
   
End Sub

Third - the error I see in Release mode - works just find in Debug mode.

Open Report, error = [(JRFontNotFoundException) net.sf.jasperreports.engine.util.JRFontNotFoundException: Font "DejaVu Sans" is not available to the JVM. See the Javadoc for more details.]
Is this only on Linux? I tested a report on Windows with DejaVu Sans on one of the text fields and font installed on the Op. System and it's working.
 

cjpryor

Active Member
Licensed User
Thanks for trying. If I understand you correctly you say it works in Windows if you install the font. Is that correct?

This particular problem is common across all operating systems. The test is to NOT have the font installed on the Operating System. The idea is to be able to deploy to any system without having to install fonts on that system. Please see http://jasperreports.sourceforge.net/sample.reference/fonts/ (referenced earlier). Here is an excerpt:

About Fonts Extension

Formerly used font definitions relied on font files available on the machine. In this case, when defining how a piece of text should look like, one had to take care about the following possible issues:
  • The needed font library might not be available to the JVM at runtime because the font file is not installed on the system.
  • When a font library is not available, the local JVM will replace it with some default fonts, and this could lead to various side effects, such as totally different text appearance or truncated pieces of text.
It's obviously that running a report in this kind of approach becomes completely dependent on the local environment, and one have to ensure that required font files are installed on the machine where the report is run. If they aren't, they should be installed first. And that's what should be done on every machine running the report. Quite a little bit embarrassing, isn't it.
Therefore, this is not the best way to control fonts in JasperReports. A much better one is due to the extension points support, available in JasperReports. Font files can be provided as library extensions. In a very simple manner, making a font extension consists in putting various True Type Font files in a JAR file together with a properties file describing the content of the JAR, and an XML file defining relationships between fonts and locales.

Please let me know if I misunderstood you.

Thanks
 

Juan Marrero

Active Member
Licensed User
Longtime User
Thanks for trying. If I understand you correctly you say it works in Windows if you install the font. Is that correct?

This particular problem is common across all operating systems. The test is to NOT have the font installed on the Operating System. The idea is to be able to deploy to any system without having to install fonts on that system. Please see http://jasperreports.sourceforge.net/sample.reference/fonts/ (referenced earlier). Here is an excerpt:



Please let me know if I misunderstood you.

Thanks
You are correct. Fonts are installed in Windows. Also I checked a Linux Mint Laptop I have at work and fonts are also installed natively (was going to install them and terminal says they are already in latest version).
I'm very old school, I always install fonts. I have never use Fonts Extensions. Can give it a try later.
 

cjpryor

Active Member
Licensed User
So I have experienced unexpected text formats in my reports on different systems even when the fonts are installed. I have adjusted field widths to compensate for unexpected differences but really like the idea of not having to ask my customers to do extra steps to get the program to run as expected on their computers.
 

Juan Marrero

Active Member
Licensed User
Longtime User
Hi,
I can't find the sample .jrxml or .jasper file for example project.
You need to create reports in Jaspersoft Studio or iReport first. Then use them in your examples. My examples are connected to my databases so they won't work on your side.
 

amorosik

Expert
Licensed User
Before sending the request I have already tried to download both version 1 and version 2
But there is no trace of the indicated file
 

amorosik

Expert
Licensed User
I'm trying to follow the directions at psot #1
I just uploaded the jaspertest example
But I can't find the reports indicated in the code, I mean the file RepName.jrxml, SubRepName1.jrxml and others
Do you have to download them from somewhere else?
Where to find a complete and working example to use the jJasperReport library?
 

Juan Marrero

Active Member
Licensed User
Longtime User
I'm trying to follow the directions at psot #1
I just uploaded the jaspertest example
But I can't find the reports indicated in the code, I mean the file RepName.jrxml, SubRepName1.jrxml and others
Do you have to download them from somewhere else?
Where to find a complete and working example to use the jJasperReport library?
Those reports where made using my own databases. You need to create you reports using Jaspersoft Studio or another software using your database of choice.
 
Hi,
I'm using the jasper library, in debug and release mode it works correctly, but if I try to run the report from the .jar it gives me this error:

"(IOException) java.io.IOException: CreateProcess error=2, Cannot find the specified file"

Can anyone help me? I can't find a solution.
Thanks!
 

Juan Marrero

Active Member
Licensed User
Longtime User
Hi,
I'm using the jasper library, in debug and release mode it works correctly, but if I try to run the report from the .jar it gives me this error:

"(IOException) java.io.IOException: CreateProcess error=2, Cannot find the specified file"

Can anyone help me? I can't find a solution.
Thanks!
Hi. Is this when trying to load a report? A subreport? An image in the report?
 
Hi. Is this when trying to load a report? A subreport? An image in the report?
Hi Juan, thank you for your reply.

This is the code:

B4X:
            Dim SelectedData As String=selectedDate & " 00:00:00.000"
            Dim jasper As JasperReports
            Dim report As JasperReport
            Dim print As JasperPrint
            Dim conn As JasperConnection
            Dim design As JasperDesign
            Dim query As JasperDesignQuery
    
            jasper.InitializeParameters
            jasper.InitializeJRDesignQuery
            jasper.SetText("select ROUND(Quantita,0)as qta,*,(select RagioneSociale from clienti as c2 where c2.CodiceCliente=d.CodiceDestinazione) as bar from Documenti as d  inner join Articoli as a on a.Codice=d.CodiceArticolo inner join Clienti as c on d.CodiceCliente=c.CodiceCliente where d.CodiceCliente='"& SelectedRapp &"' and data='"& SelectedData &"' order by d.Ordine")
            
            jasper.GetResourceAsStream(File.Combine(File.DirApp, "cartellinobar.jrxml"))
            jasper.LoadJRXml(jasper.in)
            query = jasper.query
            jasper.SetJRDesingQuery(query)
            design = jasper.design
            report=jasper.CompileXML2(design)
    
            conn = jasper.getConnectionSQLServer("xxx.xxx.xxx.xxx", "xxx", "sqlexpress", "xxx", "sa", "xxxxxxx")

            print = jasper.Print(report, jasper.parameters, conn)
    
            jasper.PrintDirectlyToPrinter(print, selPrinter, jasper.msn_NA_LETTER)
            Log("Stampato: " & SelectedRapp)

and the command that generates the error is:

"report=jasper.CompileXML2(design)"

but only from the .jar, in debug and in release mode it works perfectly.

Thanks in advance for any help you can give me.

Christian
 

Juan Marrero

Active Member
Licensed User
Longtime User
Hi Juan, thank you for your reply.

This is the code:

B4X:
            Dim SelectedData As String=selectedDate & " 00:00:00.000"
            Dim jasper As JasperReports
            Dim report As JasperReport
            Dim print As JasperPrint
            Dim conn As JasperConnection
            Dim design As JasperDesign
            Dim query As JasperDesignQuery
  
            jasper.InitializeParameters
            jasper.InitializeJRDesignQuery
            jasper.SetText("select ROUND(Quantita,0)as qta,*,(select RagioneSociale from clienti as c2 where c2.CodiceCliente=d.CodiceDestinazione) as bar from Documenti as d  inner join Articoli as a on a.Codice=d.CodiceArticolo inner join Clienti as c on d.CodiceCliente=c.CodiceCliente where d.CodiceCliente='"& SelectedRapp &"' and data='"& SelectedData &"' order by d.Ordine")
          
            jasper.GetResourceAsStream(File.Combine(File.DirApp, "cartellinobar.jrxml"))
            jasper.LoadJRXml(jasper.in)
            query = jasper.query
            jasper.SetJRDesingQuery(query)
            design = jasper.design
            report=jasper.CompileXML2(design)
  
            conn = jasper.getConnectionSQLServer("xxx.xxx.xxx.xxx", "xxx", "sqlexpress", "xxx", "sa", "xxxxxxx")

            print = jasper.Print(report, jasper.parameters, conn)
  
            jasper.PrintDirectlyToPrinter(print, selPrinter, jasper.msn_NA_LETTER)
            Log("Stampato: " & SelectedRapp)

and the command that generates the error is:

"report=jasper.CompileXML2(design)"

but only from the .jar, in debug and in release mode it works perfectly.

Thanks in advance for any help you can give me.

Christian
Can you get the value of File.DirApp and check if that is the correct folder the jrxml should be? At first I got issues with report or subreport or image location in production mode. If I remember well subreport and images has to be at the same level as main report.
 
Top