How to change font name dynamically?

I am using the Jasper jar to create a report on my J2EE project. I can successfully generate PDF files without any problems. However, I want the font name to be dynamically changed for all my PDF files based on the settings that we configure in one place.

I became acquainted with a conditional style that is useful for this. However, I have hundreds of fonts that cannot be conditionally styled in every place. This will make the report worse.

I am looking for a suitable solution that helps me change fonts on jasper PDF files dynamically.

+4
source share
1 answer

, , - java, .

( ) jrxml, textField JasperReport

<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="reputation" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a88bd694-4f90-41fc-84d0-002b90b2d73e">
    .....
   <style name="myStyle" isDefault="true" fontName="DejaVu Sans"/>
    ....
</jasperReport>

java (jrxml), ,

JasperReport report = JasperCompileManager.compileReport("jmyReport.jrxml");
report.getDefaultStyle().setFontName("NewFontName");
JasperPrint jasperPrint = JasperFillManager.fillReport(report, paramMap,datasource);
, !, , pdf .

, textField JRStyle[] styles = report.getStyles();, JRStyle # GetName()

+3

Source: https://habr.com/ru/post/1687874/


All Articles