Jump to content
We've recently updated our Privacy Statement, available here ×

Help:Text truncation using courier in pdf


Recommended Posts

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

  • 1 year later...
  • Replies 17
  • Created
  • Last Reply

Top Posters In This Topic

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

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:41

Post edited by: janve, at: 2007/12/19 15:42

Link to comment
Share on other sites

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

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, Jan

Post edited by: janve, at: 2007/12/20 18:44

Link to comment
Share on other sites

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 sql

3) 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

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

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

  • 2 weeks later...

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...