Thanks to the information I found in this post it took me little time to legally use a close to the proprietary Arial font in our application. If you plan to distribute or license your application you will need to buy Arial font or find a different project with a more commercial friendly license (like BSD) as the license for Liberation fonts is GPL. must then
- Download and extract the Red Hat Open Source GPL licensed Liberation Fonts
- From iReport Preferences on a Mac or Options for the rest of the mortals navigate through "iReport | Fonts | Install Font", then import "LiberationSans-Regular.ttf" from the exploded directory created as part of the above step. Click next and pick the bold, Italic and BoldItalic versions for LiberationSans. LiberationSans is the closest font to Arial. The rest of the Liberation Fonts are closer to Times New Roman and Courier New fonts
- Pick a good family name that will later use in your style fontName property, for example "LiberationSans". Check the "Embed this font in the PDF document"
- Include your font in a hello world jrxml like I show below and run it from iReport. Play with the properties and you should see bold and italic rendered as well (I am in this example striking through and underlining as well).
<?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="hello" language="groovy" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20"> <property name="ireport.zoom" value="1.0"/> <property name="ireport.x" value="0"/> <property name="ireport.y" value="0"/> <style name="Default" isDefault="true" fontName="LiberationSans" fontSize="20" isBold="true" isItalic="true" isUnderline="true" isStrikeThrough="true"/> <background> <band splitType="Stretch"/> </background> <title> <band height="79" splitType="Stretch"> <staticText> <reportElement x="12" y="10" width="531" height="57"/> <textElement/> <text><![CDATA[Hello JasperReports!!!]]></text> </staticText> </band> </title> <pageHeader> <band height="35" splitType="Stretch"/> </pageHeader> <columnHeader> <band height="61" splitType="Stretch"/> </columnHeader> <detail> <band height="125" splitType="Stretch"/> </detail> <columnFooter> <band height="45" splitType="Stretch"/> </columnFooter> <pageFooter> <band height="54" splitType="Stretch"/> </pageFooter> <summary> <band height="42" splitType="Stretch"/> </summary> </jasperReport>
- Now you should see from iReport your font correctly embedding in the resulting PDF
- From iReport navigate to the Fonts settings as I explained before and then pick "LiberationSans" and export it as liberation-sans.jar
- Include the jar in your application classpath
- Now your app is serving close to Arial font styled content
No comments:
Post a Comment