2002 JI Open Discussion Posted August 18, 2006 Share Posted August 18, 2006 By: Luigi Nardone - luiznar Help:Text truncation using courier in pdf 2003-06-12 03:02 Hi all, I am starting to use jasper report. Defining a text field having font type courier(pdfFontName="Courier") and text overflow enabled overf(isStretchWithOverflow="true"), not the entire text was displayed in pdf exported document. In same report, if I change only the font type (i.e. helvetica) all text is displayed. Coul you help me? Thank you By: Luigi Nardone - luiznar RE: Help:Text truncation using courier in pdf 2003-06-12 03:04 Sorry, I forgot the report definition: <?xml version="1.0" encoding="UTF-8" ?> <!-- Created with iReport - A designer for JasperReports --> <!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd"> <jasperReport name="Untitled_report_2" columnCount="1" printOrder="Vertical" orientation="Portrait" pageWidth="595" pageHeight="842" columnWidth="535" columnSpacing="0" leftMargin="30" rightMargin="30" topMargin="20" bottomMargin="20" whenNoDataType="NoPages" isTitleNewPage="false" isSummaryNewPage="false"> <queryString><![CDATA[sELECT PROJNOTE, SPACTIONS, SITUATION from PROJECTDATA where ID=5987]]></queryString> <field name="PROJNOTE" class="java.lang.String"/> <variable name="test" class="java.lang.String" resetType="None" calculation="Nothing"> <variableExpression><![CDATA["test"]]></variableExpression> <initialValueExpression><![CDATA["test"]]></initialValueExpression> </variable> <background> <band height="0"> </band> </background> <title> <band height="50"> </band> </title> <pageHeader> <band height="9"> </band> </pageHeader> <columnHeader> <band height="0"> </band> </columnHeader> <detail> <band height="29"> <textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" > <reportElement mode="Transparent" x="127" y="2" width="192" height="15" forecolor="#000000" backcolor="#FFFFFF" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <textElement textAlignment="Left" verticalAlignment="Top" lineSpacing="Single"> <font fontName="" pdfFontName="Courier" size="8" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" isStrikeThrough="false" /> </textElement> <textFieldExpression class="java.lang.String">$F{PROJNOTE}</textFieldExpression> </textField> <staticText> <reportElement mode="Transparent" x="0" y="2" width="127" height="15" forecolor="#000000" backcolor="#FFFFFF" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <textElement textAlignment="Left" verticalAlignment="Top" lineSpacing="Single"> <font fontName="" pdfFontName="Times-Bold" size="12" isBold="true" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1250" isStrikeThrough="false" /> </textElement> <text>PROJNOTE</text> </staticText> </band> </detail> <columnFooter> <band height="0"> </band> </columnFooter> <pageFooter> <band height="27"> </band> </pageFooter> <summary> <band height="0"> </band> </summary> </jasperReport> By: Teodor Danciu - teodord RE: Help:Text truncation using courier in pdf 2003-06-12 03:34 Hi, You have to set also the "fontName" attribute. It is the fontName that counts when the engine calculates the size of fields and makes the layout. If you don't specify the corresponding "fontName", the defaut font that the engine uses does not match your pdfFontName and the text does not fit. It works with Helvetica because it has the same properties as the defaut font used when "fontName" is missing. I hope this helps. Teodor By: Luigi Nardone - luiznar RE: Help:Text truncation using courier in pdf 2003-06-12 07:29 Than you teodor, now I can view all the text (I used fontName=monospace). But I found also text missing when it continues on a new page. Note that if I use size="12", no word is missing. Something wrong yet in font definition? <?xml version="1.0" encoding="UTF-8" ?> <!-- Created with iReport - A designer for JasperReports --> <!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd"> <jasperReport name="PROJECTFREEREPORT" columnCount="1" printOrder="Vertical" orientation="Portrait" pageWidth="595" pageHeight="842" columnWidth="515" columnSpacing="0" leftMargin="28" rightMargin="28" topMargin="14" bottomMargin="7" whenNoDataType="AllSectionsNoDetail" isTitleNewPage="true" isSummaryNewPage="false"> <parameter name="MaxRow" isForPrompting="true" class="java.lang.String"/> <queryString><![CDATA[sELECT PROJNOTE, SPACTIONS, SITUATION from PROJECTDATA where ID=5987]]></queryString> <field name="PROJNOTE" class="java.lang.String"/> <field name="SPACTIONS" class="java.lang.String"/> <field name="SITUATION" class="java.lang.String"/> <background> <band height="0"> </band> </background> <title> <band height="400"> </band> </title> <pageHeader> <band height="56"> </band> </pageHeader> <columnHeader> <band height="0"> </band> </columnHeader> <detail> <band height="12"> <textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" > <reportElement mode="Transparent" x="165" y="8" width="85" height="1" forecolor="#000000" backcolor="#FFFFFF" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="true"/> <textElement textAlignment="Left" verticalAlignment="Middle" lineSpacing="Single"> <font fontName="monospaced" pdfFontName="Courier" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" isStrikeThrough="false" /> </textElement> <textFieldExpression class="java.lang.String"><![CDATA["Il Cliente ha selezionato il consorzio formato da pippo,pluto,paperino che partecipa allo sviluppo dell iniziativa e all equity. Questa decisione deve essere ancora ratificata dai tre Boards di Paperopoli. L iniziativa prevede una prima fase 0 (che consiste nell assessment dei dati e nell effettuazione del prefeasibility) che sara completata prevedibilmente entro il 2023. Nell ipotesi di esito positivo di questa fase sara formato un nuovo consorzio con sei partners.Siamo stati qualificati nell ambito del consorzio con topolino e minni. Stiamo partecipando alla fase 0 per verificare la fattibilita del progetto. Se l esito sara positivo la nostra partecipazione prevede di svolgere il 200 delle attivita. Se l esito sara positivo la nostra partecipazione prevede di svolgere il 200 delle attivita. Se l esito sara positivo la nostra partecipazione prevede di svolgere il 200 delle attivita. "]]></textFieldExpression> </textField> </band> </detail> <columnFooter> <band height="0"> </band> </columnFooter> <pageFooter> <band height="0"> </band> </pageFooter> <summary> <band height="0"> </band> </summary> </jasperReport> By: Teodor Danciu - teodord RE: Help:Text truncation using courier in pdf 2003-06-15 13:25 Hi, This is a problem that comes from the fact that in PDF format the same text might wrap differently then it does in AWT/Swing. If you take a closer look you can see that on some particular line one word did not fit in PDF format and was displayed on the next row. This resulted in more lines of text to display in the same amount of vertical space and this is why we loose words at the bottom. Unfortunately there is nothing much we can do about it. The engine tries to make documents look the same regardless of output format, but sometimes its not possible and things are not perfect. In XLS format, things are more obvious. Thank you, Teodor Link to comment Share on other sites More sharing options...
janve Posted December 19, 2007 Share Posted December 19, 2007 Solution although a bit ugly:I used a bigger reportfont to make the couriertext fit in de pdf. Pdf's are more important for me so this was possible. In this way there was no truncation in pdf but i introduced some blank lines because it doesn't fit perfect. It's a little bit uggly. 2 questions: 1)Is there a possibility to make AWT/Swing wrap up the text the same as the pdf does or vice versa using the courier font? Apperently setting reportfont the same as pdf font doesn't work... 2)If you run de jasperreport and print it with an external pdf writer (example: primopdf) then the pdf looks good without truncation. Can anybody tell why this one goes good and when using Itext in Ireport there is truncation? Thxs Link to comment Share on other sites More sharing options...
lucianc Posted December 19, 2007 Share Posted December 19, 2007 What you're describing seems to be caused by AWT/PDF font mismatch (as described in this FAQ). You can verify this by displaying the report with JasperViewer (on the same machine where the report is being filled) and checking whether the text is displayed with the same font as the one from the PDF export. Is there a possibility to make AWT/Swing wrap up the text the same as the pdf does or vice versa using the courier font? Apperently setting reportfont the same as pdf font doesn't work... If the AWT/PDF fonts match, there shouldn't be any problems. If you have a self-contained sample that can be used to replicate a case where this does not hold, please open a bug for it. If you run de jasperreport and print it with an external pdf writer (example: primopdf) then the pdf looks good without truncation. Can anybody tell why this one goes good and when using Itext in Ireport there is truncation? If you print the report from Java, the AWT fonts will be used for the report text. This could explain why printing to PDF is fine. Regards,Lucian Link to comment Share on other sites More sharing options...
janve Posted December 19, 2007 Share Posted December 19, 2007 Hi Lucian, many thanks for your reply. I'm not sure if question nr.1 refers to a bug. Therefore I attached 3 pict. from a report with courier text so it's possible to see what's happening. Pictures: a) jasperviewer --> all text is shown but layout of "original" courier text is lost; b) primopdf - pdf --> same as jasperviewer (as expected); c) itext - pdf - text behind Actie Specificatie is courier --> layout of courier text is perfect (same as original), but text is truncated. As possible to see the same font is used for AWT and Itext pdf. Question:Is it possible to make AWT calculates the same space and layout as Itext when using courier? Thnx, Jan Post edited by: janve, at: 2007/12/19 15:41Post edited by: janve, at: 2007/12/19 15:42 Link to comment Share on other sites More sharing options...
janve Posted December 19, 2007 Share Posted December 19, 2007 [file name=a__jasperviewer___courier.png size=21420]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/a__jasperviewer___courier.png[/file] Post edited by: janve, at: 2007/12/19 15:48 Link to comment Share on other sites More sharing options...
janve Posted December 19, 2007 Share Posted December 19, 2007 b) size=389]http://www.jasperforge.org/components/com_joomlaboard/uploaded/images/b__primopdf_pdf___courier.png Link to comment Share on other sites More sharing options...
janve Posted December 19, 2007 Share Posted December 19, 2007 c) size=389]http://www.jasperforge.org/components/com_joomlaboard/uploaded/images/c__itext_pdf___courier-931fe2d5c5670b6459929cfa4fd56a4e.png Link to comment Share on other sites More sharing options...
lucianc Posted December 19, 2007 Share Posted December 19, 2007 Could you try to set JRPdfExporterParameter.FORCE_LINEBREAK_POLICY to true when exporting the report to PDF? Also, do you have tab characters in the text? Regards,Lucian Link to comment Share on other sites More sharing options...
janve Posted December 20, 2007 Share Posted December 20, 2007 Hi Lucian, thnx again for your time! I edited the file "default.jasperreports.properties" in the "jasperreports-1.3.1.jar" with winrar and set net.sf.jasperreports.export.pdf.force.linebreak.policy=true. It gives a slight difference in the itext-pdf (see picture, but the courier tekst still is truncated.. There is no use of tab characters in the courier text. size=390]http://www.jasperforge.org/components/com_joomlaboard/uploaded/images/itext_pdf___courier_linebreak_true.png Link to comment Share on other sites More sharing options...
lucianc Posted December 20, 2007 Share Posted December 20, 2007 Do you have a self contained/static JRXML that can be used to replicate this? If we reproduce the issue, we can debug it and identify the cause.. Regards,Lucian Link to comment Share on other sites More sharing options...
janve Posted December 20, 2007 Share Posted December 20, 2007 I tried but it's not possible. De characteristic of the courier string (with comma's, newlines, many spaces, "=" character) will not compile when putting it in a textfield without editing the text. In this way it's losing it's original layout. Best regards, JanPost edited by: janve, at: 2007/12/20 18:44 Link to comment Share on other sites More sharing options...
janve Posted December 21, 2007 Share Posted December 21, 2007 Lucian, Coming this far I want to ask you to make the next effort. I cannot think of another way.... To replicate the situation quickly: 1) Put the courier text in a database. In this case it was stored in Oracle with datatype varchar2(2000)2) Get the field with the courier text with sql3) Set the Font Name to "courier new" and the PDF Font Name to "courier new"4) mark the "checkbox stretch with overflow"5) run the report in jasperviewer and itextpdf to see that text in pdf is truncated [file name=courier_text.txt size=651]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/courier_text.txt[/file] If there is a better possibility to replicate the situation pls let me know.. Best regards, Jan Link to comment Share on other sites More sharing options...
lucianc Posted December 21, 2007 Share Posted December 21, 2007 What width should the text field have? Regards,Lucian Link to comment Share on other sites More sharing options...
janve Posted December 21, 2007 Share Posted December 21, 2007 width: 350 pixels but can be other size too. additional info:The goal was: show some sql statements in pdf report and keep the original layout. If not sql becomes difficult to read. AWT doesn't recognize to start a newline in the courier text. It wraps up all the text. Itext pdf recognize that a new line starts but because the space calculated by AWT is to small the result is truncation. Regards,Jan Link to comment Share on other sites More sharing options...
lucianc Posted December 22, 2007 Share Posted December 22, 2007 I haven't been able to replicate the problem. I'm attaching the JRXML I used, a MySQL dump with the data and the resulting PDF. What am I missing? AWT didn't have any problem with the newlines in my case. What kind of newlines do you use? The file you attached seems to have CRLF/DOS newlines (at least that's how it saved on my machine). Regards,Lucian [file name=courier.zip size=2779]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/courier.zip[/file] Link to comment Share on other sites More sharing options...
janve Posted December 22, 2007 Share Posted December 22, 2007 Char(13) = carriage return and sometimes there is a char(10) = linefeed Link to comment Share on other sites More sharing options...
janve Posted January 5, 2008 Share Posted January 5, 2008 Hi Lucian, the best wishes for the new year! My excuses for uploading the wrong courier text. I hope you can try again using this "good_courier" file. It contains the char(10) en char(13). You can see for example that if you open the file in notepad the text is shown in 1 line, but if you open in wordpad it opens in many lines. Best regards,Jan [file name=good_courier.txt size=668]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/good_courier.txt[/file] Link to comment Share on other sites More sharing options...
lucianc Posted January 7, 2008 Share Posted January 7, 2008 The file you posted contains CR (r or 13) as newline character. CR is not interpreted as newlines by the AWT text measurer/renderer, but they are so by iText/PDF. Please post a bug for this issue here. As a workaround, you can preprocess the strings to replace CR by LF (or CR+LF). Regards,Lucian Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now