formatting - How to do form block letter printing? -


i want print in block letters in jasper print. e.g. have bank format , want name come in boxes. how 1 that?

name: [f][i][r][s][t][ ][n][a][m][e] 
  • option1 - print cell cell ${first_name}.charat(x) - unsustainable

  • option2 - add spaces between characters changes based on font size

  • option3 - add padding spaces end of text. stretch text full width available , characters distributed equally - how 1 this?

this normal achieved using monospaced font.

if achieve other fonts or spacing large can use subreport (that called every time need fixed space)

example

main report (i'm using parameter test)

call subreport datasource contains each letter, i'm using $p{testtext}.split("") , since char[] not allowed in jrbeanarraydatasource.

note: split give empty first string in java7 not in java8

<?xml version="1.0" encoding="utf-8"?> <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="mainfixedspace" pagewidth="595" pageheight="842" whennodatatype="allsectionsnodetail" columnwidth="555" leftmargin="20" rightmargin="20" topmargin="20" bottommargin="20" uuid="d2bcb5ab-c751-4f39-8753-561b8a6ac629">     <parameter name="testtext" class="java.lang.string">         <defaultvalueexpression><![cdata["hello world"]]></defaultvalueexpression>     </parameter>     <parameter name="subreport_dir" class="java.lang.string" isforprompting="false">         <defaultvalueexpression><![cdata["c:\\jdd\\projects\\stacktrace\\jasper\\"]]></defaultvalueexpression>     </parameter>     <title>         <band height="25" splittype="stretch">             <subreport>                 <reportelement x="0" y="0" width="555" height="25" uuid="76f53ca9-da1f-46c8-bb3b-aca0dc43d2d3"/>                 <datasourceexpression><![cdata[new net.sf.jasperreports.engine.data.jrbeanarraydatasource($p{testtext}.split(""))]]></datasourceexpression>                 <subreportexpression><![cdata[$p{subreport_dir} + "mainfixedspace_subreport.jasper"]]></subreportexpression>             </subreport>         </band>     </title> </jasperreport> 

subreport

setup the fixed space column count in case 20 columns on each row (you need adapted case) , set printorder="horizontal" _this field let access letter.

<?xml version="1.0" encoding="utf-8"?> <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="mainfixedspace_subreport" columncount="20" printorder="horizontal" pagewidth="555" pageheight="802" columnwidth="27" leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0" uuid="77ba37de-32e1-4ec6-8496-58d716d0340d">     <field name="_this" class="java.lang.string"/>     <detail>         <band height="25" splittype="stretch">             <textfield>                 <reportelement x="0" y="0" width="27" height="25" uuid="ffb27000-41ba-419f-8836-b24dbb0dbb25"/>                 <textelement textalignment="center" verticalalignment="middle"/>                 <textfieldexpression><![cdata[$f{_this}]]></textfieldexpression>             </textfield>         </band>     </detail> </jasperreport> 

output

result


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -