B4J Library jJasperReports Library

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
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:


Please let me know if I misunderstood you.

Thanks
 

Juan Marrero

Active Member
Licensed User
Longtime User
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.
 

aeric

Expert
Licensed User
Longtime User
Hi,
I can't find the sample .jrxml or .jasper file for example project.
 

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.
 

aeric

Expert
Licensed User
Longtime User
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.
Thanks for clarifying. I will give it a try.
 

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
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. 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
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.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…