Printing report fails with wrong font

0

Hi everybody,

I hope some of you really can help me. I'm developing a java based business apllication where I have to view and print delivery reports for customers. My customer owns a dot-matrix printer (Oki M1120 eco).
The problem now is that erverytime I wanna print a report, the printer just writes any unreadable font (letter spacing to small, letters too bold, and so on), which is not acceptable for me and my customer.

I'm using version 6.1.0

Here is the report I am creating and compiling at compile-time and fill it at run-time.

<?xml version="1.0" encoding="UTF-8"?> <!-- Created with Jaspersoft Studio version 6.1.0.final using JasperReports Library version 6.1.0 --> <!-- 2015-09-02T13:33:06 --> <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="Lieferschein" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="03de705d-bb10-4f24-bf03-542bbb39f0aa"> <property name="ireport.zoom" value="2.0"/> <property name="ireport.x" value="0"/> <property name="ireport.y" value="56"/> <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/> <style name="CustomLieferscheinStyle" markup="styled" isBlankWhenNull="true" fontName="Calibri" isBold="false"> <paragraph lineSpacing="Single" leftIndent="0" spacingBefore="0"/> </style> <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false"> <defaultValueExpression><![CDATA[""]]></defaultValueExpression> </parameter> <queryString language="hql"> <![CDATA[]]> </queryString> <field name="kunde" class="de.mbichlmeier.model.Kunde"> <fieldDescription><![CDATA[kunde]]></fieldDescription> </field> <field name="fahrer" class="de.mbichlmeier.model.Fahrer"> <fieldDescription><![CDATA[fahrer]]></fieldDescription> </field> <field name="lieferschein" class="de.mbichlmeier.model.Lieferschein"> <fieldDescription><![CDATA[lieferschein]]></fieldDescription> </field> <field name="positionenWaren0" class="java.util.Collection"> <fieldDescription><![CDATA[positionenWaren0]]></fieldDescription> </field> <field name="positionenWaren1" class="java.util.Collection"> <fieldDescription><![CDATA[positionenWaren1]]></fieldDescription> </field> <field name="positionenWaren2" class="java.util.Collection"> <fieldDescription><![CDATA[positionenWaren2]]></fieldDescription> </field> <field name="positionenWaren3" class="java.util.Collection"> <fieldDescription><![CDATA[positionenWaren3]]></fieldDescription> </field> <field name="positionenWaren4" class="java.util.Collection"> <fieldDescription><![CDATA[positionenWaren4]]></fieldDescription> </field> <field name="positionenWaren5" class="java.util.Collection"> <fieldDescription><![CDATA[positionenWaren5]]></fieldDescription> </field> <field name="positionenWaren6" class="java.util.Collection"> <fieldDescription><![CDATA[positionenWaren6]]></fieldDescription> </field> <field name="positionenWaren7" class="java.util.Collection"> <fieldDescription><![CDATA[positionenWaren7]]></fieldDescription> </field> <background> <band splitType="Stretch"/> </background> <title> <band height="116" splitType="Stretch"> <staticText> <reportElement style="CustomLieferscheinStyle" x="167" y="0" width="217" height="29" uuid="2b01379d-940e-45d1-8ca5-ed38d864faae"/> <textElement textAlignment="Center"> <font size="20" isBold="true"/> </textElement> <text><![CDATA[Lieferschein]]></text> </staticText> <staticText> <reportElement style="CustomLieferscheinStyle" x="20" y="43" width="147" height="14" uuid="8d533bff-63dd-4354-ac3c-dbe35fd649c0"/> <text><![CDATA[Tel: 96 50]]></text> </staticText> <staticText> <reportElement style="CustomLieferscheinStyle" x="20" y="15" width="147" height="14" uuid="577fc150-a6bb-43b0-aa40-1b315a225e83"/> <text><![CDATA[Einkaufs- und ]]></text> </staticText> <staticText> <reportElement style="CustomLieferscheinStyle" x="20" y="1" width="100" height="14" uuid="748a8769-3274-4ade-9271-d9c3250c6d79"/> <text><![CDATA[Soch]]></text> </staticText> <staticText> <reportElement style="CustomLieferscheinStyle" x="20" y="57" width="146" height="14" uuid="fc51805f-00ab-406e-a562-fc630dfd2aa3"/> <text><![CDATA[Fax: 08 89]]></text> </staticText> <staticText> <reportElement style="CustomLieferscheinStyle" x="370" y="40" width="71" height="20" uuid="0f52b943-ec81-4ea1-9cfc-13b5c931f5df"/> <textElement> <font isBold="true"/> </textElement> <text><![CDATA[Lieferdatum]]></text> </staticText> <textField> <reportElement style="CustomLieferscheinStyle" x="20" y="99" width="264" height="16" uuid="a3806a3a-bf70-49bc-85d0-8dc73566305f"/> <textElement> <font size="10"/> </textElement> <textFieldExpression><![CDATA[$F{kunde}.getPlz()+", "+$F{kunde}.getStadt()]]></textFieldExpression> </textField> <textField pattern="EEEEE, den dd.MM.YYYY"> <reportElement style="CustomLieferscheinStyle" x="370" y="60" width="179" height="20" uuid="16a7292c-abe8-4dcf-80ee-fb449b99d230"/> <textElement> <font isBold="true"/> </textElement> <textFieldExpression><![CDATA[(new SimpleDateFormat("EEEEE").format($F{lieferschein}.getDateAsDate()))+", den "+(new SimpleDateFormat("dd.MM.YYYY").format($F{lieferschein}.getDateAsDate()))]]></textFieldExpression> </textField> <textField> <reportElement style="CustomLieferscheinStyle" x="20" y="80" width="264" height="19" uuid="b41196d6-8b62-4f52-b67b-1d79d64b824f"/> <textElement> <font size="12" isBold="true"/> </textElement> <textFieldExpression><![CDATA[$F{kunde}.getStraße()]]></textFieldExpression> </textField> </band> </title> <detail> <band height="171" splitType="Stretch"> <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.FreeLayout"/> <subreport> <reportElement positionType="Float" x="288" y="14" width="269" height="16" uuid="2e3c09f9-d89d-49ba-9999-4830bd289fe7"/> <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{positionenWaren2})]]></dataSourceExpression> <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "LieferscheinSubArtikel.jasper"]]></subreportExpression> </subreport> <subreport> <reportElement positionType="Float" x="288" y="49" width="269" height="16" uuid="320873ec-a233-4e36-89ef-1ec5df464249"/> <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{positionenWaren1})]]></dataSourceExpression> <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "LieferscheinSubArtikel.jasper"]]></subreportExpression> </subreport> <subreport> <reportElement positionType="Float" x="288" y="82" width="269" height="16" uuid="37cdef72-a5e9-4017-be01-e1708bf69091"/> <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{positionenWaren0})]]></dataSourceExpression> <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "LieferscheinSubArtikel.jasper"]]></subreportExpression> </subreport> <subreport> <reportElement positionType="Float" x="0" y="14" width="283" height="16" uuid="d7ff0de7-1cdc-417a-aeab-5ff19faf4c77"/> <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{positionenWaren3})]]></dataSourceExpression> <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "LieferscheinSubArtikel.jasper"]]></subreportExpression> </subreport> <subreport> <reportElement positionType="Float" x="0" y="49" width="283" height="16" uuid="e9036fb1-a9c5-406d-bf4e-427c5a6d4c26"> <property name="local_mesure_unity" value="pixel"/> <property name="com.jaspersoft.studio.unit.y" value="px"/> </reportElement> <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{positionenWaren4})]]></dataSourceExpression> <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "LieferscheinSubArtikel.jasper"]]></subreportExpression> </subreport> <subreport> <reportElement positionType="Float" x="0" y="82" width="285" height="16" uuid="fbaa5785-edbe-4cd6-92b6-6ae865d7cdaa"> <property name="com.jaspersoft.studio.unit.height" value="pixel"/> </reportElement> <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{positionenWaren5})]]></dataSourceExpression> <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "LieferscheinSubArtikel.jasper"]]></subreportExpression> </subreport> <subreport> <reportElement positionType="Float" x="0" y="118" width="285" height="16" uuid="fb49b3f5-fc7c-492b-8018-cf5dfe26c4ac"/> <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{positionenWaren6})]]></dataSourceExpression> <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "LieferscheinSubArtikel.jasper"]]></subreportExpression> </subreport> <subreport> <reportElement positionType="Float" x="1" y="148" width="283" height="16" uuid="ad97aaec-332c-4331-9c4f-4eca507d547e"/> <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{positionenWaren7})]]></dataSourceExpression> <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "LieferscheinSubArtikel.jasper"]]></subreportExpression> </subreport> </band> </detail> </jasperReport>

The report is using a custom style (CustomLieferscheinSytle) to change the fonts because of quicker testing.

The java code where I fill and open the viewer is the following:

try { final Collection<LieferscheinPrintBean> collection = new ArrayList<LieferscheinPrintBean>(); collection.add(new LieferscheinPrintBean(bean)); final JRDataSource jrDataSource = new JRBeanCollectionDataSource(collection); final HashMap<String, Object> parameters = new HashMap<String, Object>(); final InputStream in = ReportController.class.getResourceAsStream(Utils.getLieferscheinreportrelativepath()); jp = JasperFillManager.fillReport(in, parameters, jrDataSource); in.close(); final JRViewer viewer = new JRViewer(jp); final ReportView r = new ReportView(viewer); JasperPrintManager.printReport(jp, true); // currently only for test reasons } catch (final Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(new JFrame(), "Fehler beim erstellen des LieferscheinsReport " + ex.getMessage(), "Warnung", JOptionPane.WARNING_MESSAGE); }

The goal is that the user can view the report and print it out of the JRViewer. But exactly here seems to be the problem. The font which is set in the report (I've tried Arial, Calibri, Courier, and many more) is not transmitted to the printer in the correct way. When I'm printing the font test page everythings works fine. Only when I wanna print the created report.

Please help me , I'm stucking here for so long ;)

Best regards,

Michi

museYke's picture
Joined: Sep 2 2015 - 4:28am
Last seen: 3 years 11 months ago

2 Answers:

1

Try printing out from Jaspersoft Studio to your printer to check if it works OK. If it does, there's a problem with your program.

hozawa's picture
47047
Joined: Apr 24 2010 - 4:31pm
Last seen: 2 months 2 weeks ago
0

Thanks for your quick response, but the problem still exists.
I've created a completely new report only with one static text in "Calibri Light". There seems to be no direct printing option inside the Jaspersoft Studio where you can print the report as is. So I've also tried to export it as PDF and print it from the created PDF with the result that the letters seems to be more alike the font I've choosen but there are now missing pixels inside the single letters, so you could mean the printer got an faulty PDF.

EDIT: I export the jprint inside my program to a pdf file and open it afterwards with the default installed pdf viewer.I also packaged the used fonts (Calibri) into my package and embedded it into the created PDF. There is curiously still the Helvetica font inside as well as my embedded Calibri font. Is there a possibility to force the PDF exporter not to use Helvetica? Maybe that is the problem?

The goal is a PDF with an embedded CIDFont+F1 (that's what adobe reader tells me in the document information of the working pdf example). The example pdf is printed correctly.

museYke's picture
Joined: Sep 2 2015 - 4:28am
Last seen: 3 years 11 months ago
Feedback
randomness