Jump to content

isStretchWithOverflow true with padding problem


ge0ffrey

Recommended Posts

In jasperreports 2.0.5, I have a field which holds a long description and needs to stretch dynamically.

 

Code:

<textField isStretchWithOverflow="true">
<reportElement style="myStyle" x="30" y="20" width="510" height="20"
positionType="Float" isRemoveLineWhenBlank="true" />
<textFieldExpression class="java.lang.String">$F{myLongDescription}</textFieldExpression>
</textField>

 

When I use a style (from a jrtx file) with no top or bottom padding, it works:

Code:
[code]<style name="myStyle" ...>
<box leftPadding="2" rightPadding="2" />
</style>

and I get something like

Code:
[code]This is the first sentence.
This is the second sentance which is to long for one
line and shows up on the next line too.

 

However, when I use top and bottom padding, it doesn't work:

Code:
[code]<style name="myStyle" ...>
<box padding="2" />
</style>

because I get something like

Code:
[code]This is the first sentence.
This is the second sentance which is to long for one
Link to comment
Share on other sites

  • Replies 9
  • Created
  • Last Reply

Top Posters In This Topic

It happens only in PDF, not in the JasperViewer apparently.

 

I've just added this to my PDFExporter

Code:
                exporter.setParameter(JRPdfExporterParameter.FORCE_LINEBREAK_POLICY, Boolean.TRUE);

but that doesn't solve the problem.

 

According to the FAQ it could be because the PDF font doesn't match the AWT font.

I declared the fonts as such:

Code:
[code]<style name="base" isBlankWhenNull="true"
fontName="Times New Roman" fontSize="12" pdfFontName="Times-Roman">
<box padding="2"/>
</style>
<style name="text" style="base" isDefault="true">
</style>
<style name="textEmphasis" style="base"
isItalic="true" pdfFontName="Times-Italic">
</style>
<style name="textStrongEmphasis" style="base"
isBold="true" pdfFontName="Times-Bold">
</style>

 

But those definitly don't match.

Removing all pdfFontName attributes (and relying on the default awt2pdf font mapping, which I 'd like to do) doesn't solve it either.

 

Thanks for the help :)

Link to comment
Share on other sites

If I drop the pdfFontName attribute, it's definitly no longer Times New Roman in the pdf, so the default awt2pdf font mapping isn't correct (is there such a mapping out of the box?)?

 

If I do set the pdfFontName attribute, it turns out that awt "Times New Roman" doesn't match pdf "Times-Roman" as I lose a line.

Link to comment
Share on other sites

There is no default AWT-PDF font mapping, so if you want to be sure that the fonts match you'll need to explicitly set the font attributes.

 

Could you try to set pdfFontName to the absolute path of the Times New Roman .ttf file (e.g. c:/windows/fonts/times.ttf) and see whether this fixes the issue. If so, it means that the PDF built-in Times-Roman font does not match the OS/Java Times New Roman font. If this is the case, you can register all OS fonts as PDF fonts by putting something like

Code:

net.sf.jasperreports.export.pdf.fontdir.os=c:/windows/fonts

in your jasperreports.properties file.

 

Regards,

Lucian

Link to comment
Share on other sites

Is there any way to do this platform independend?

My software needs to run at least on linux (Red Hat, CentOs, Ubuntu) and Windows (XP, Vista).

 

I don't really care which font ttf is used exactly, but I 'd like to furfill these requirements:

Font Times New Roman (or something that looks like it)

Platform independend

I should never lose a line of text in my PDF

[/ul]

 

Is there anything that could explain why I only lose that line when I am using padding?

The PDF now doesn't show the line, probably because it has 1 pixel height to few to show it. Is it possible to force the PDF exporter to show as much of the line as possible anyway?

Link to comment
Share on other sites

I figured that embedding the font into pdf should solve my issue with the lines disappearing:

 

Code:
<style name="text" fontName="Times New Roman" fontSize="12" isPdfEmbedded="true" pdfEncoding="Cp1252">

 

but it doesn't. What could explain the lines disappearing?

Link to comment
Share on other sites

Hi,

 

If you run on JDK 1.4 or 1.6, you can register fonts at runtime. This way you could ship your application with needed TTF files in the JAR itself and you register them at runtime with Font.createFont() (plus an additional GraphicsEnvironment.registerFont() in JDK1.6).

For fontName you'll be using the name of the logical font you installed on the fly with the JVM, while for the pdfFontName attribute you give the relative classpath location of the TTF file in your JAR.

 

This will not work in JDK1.5 apparently, but maybe you have a suitable environment.

 

I hope this helps.

Teodor

Link to comment
Share on other sites

Even when using the exact same font, lines still disappear:

 

I took the liberty of making an issue:

http://jasperforge.org/sf/go/artf3235?nav=1

 

 

When trying to use an external font, AWT doesn't recognize the ttf format:

 

java.lang.IllegalArgumentException: font format not recognized

 

 

Code:
Font font = Font.createFont(12,
getClass().getResourceAsStream("/jasperpoc/font/LiberationSans-Regular.ttf"«»));
GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(font);
Link to comment
Share on other sites

I made a mistake in how to register the font, it should be:

 

Code:
InputStream in = getClass().getResourceAsStream(ttfResource);
Font font = Font.createFont(Font.TRUETYPE_FONT, in);
GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(font);
in.close();

 

The line still is missing though I 've used the exact same font in pdf as in jasperviewer, see the screenshot in the issue.

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...