iReport and Jasperreport fonts for a PDF report

纵然是瞬间 提交于 2020-02-07 07:09:32

问题


I made a report with iReport using some default fonts (monospace, sans-serif). This report is a bit complex and many static elements have their position calculated to fit the label's width. Just for example: Where "test of a long string..." is a field content, and the boxes are static elements. As you can see I need a precise char sizes as.

The iReport preview well works, but when I made a report with JasperReport library fonts size are really different from the iReport preview and, moreover, the monospace font doesn't exist at all.

How to exactly create a PDF report like ireport preview?

This is the JRXML head (full file is >2000 rows):

<?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="107m" pageWidth="595" pageHeight="842" columnWidth="537" leftMargin="29" rightMargin="29" topMargin="20" bottomMargin="20" uuid="821aebb9-c4bd-4720-ae38-ae0f7e515398">
    <property name="ireport.zoom" value="1.4641000000000364"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="48"/>
    <property name="ireport.background.image" value="C:\v2(1).png"/>
    <property name="ireport.background.image.properties" value="true,true,0.25,1,-202,-7,184,612,865"/>
    <detail>
        <band height="801" splitType="Stretch">
            <staticText>
                <reportElement x="0" y="0" width="536" height="18" uuid="07f24965-4a55-49f1-bbaa-c7550bc6b37f"/>
                <textElement textAlignment="Center">
                    <font size="11"/>
                </textElement>
                <text><![CDATA[TITLE]]></text>
            </staticText>
            <staticText>
                <reportElement x="0" y="14" width="536" height="18" uuid="06b42267-0de9-4467-96cb-aa477c3f07c1"/>
                <textElement textAlignment="Center">
                    <font size="9" isBold="true"/>
                </textElement>
                <text><![CDATA[SUBTITLE]]></text>
            </staticText>

回答1:


To get the same font in pdf export previous to Jasper 6.0 you used

code like this

<font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/>

since Jasper 6.0 this is deprecated and you should use font-extension

This is a good guide for how to include font extensions in iReport.

EDIT: Where can I find the font on my pc?, on Windows normally in C:\Windows\Fonts



来源:https://stackoverflow.com/questions/33550735/ireport-and-jasperreport-fonts-for-a-pdf-report

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!