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

PDF text truncated on Linux ( but fine in Windows)


giroe

Recommended Posts


Good mornging,

My problem is, I got some 'long' textfields. En everything looks fine when I run my webapp on windows (for development).
But when I run it on Linux some text is missing.

Example of a textfield on Windows:

This is just a test, on windows it does not get truncated, nananananana

 

On linux:

This is just a test, on windows it does not get tru


(this is not a 'real' example, but just to let you know what my problem is)

I sometimes get te same problem that my text goes out of it's field. I got a border around my textfield.
En the text just goes over the border.



I use Helvetica pdf font.


I know this is some kind of font type issue. I know that there are threads about this problem.
But I'm not able to get this working. I hope I can get some 'personal' assistence from you guys.
Is there an easy way to solve this (perhaps with another font or so)
I've read that you can embed the pdf font? But than you have to have the TTF file or am I wrong?
(I dont got the TTF file for helvetica, because it's not free?)

Thanks in advance

Nick

Link to comment
Share on other sites

  • Replies 10
  • Created
  • Last Reply

Top Posters In This Topic

I did read that FAQ already. But I'm not getting much wiser. I know what the problem is, but not what the solution is :) So the problem is: PDF fonts do not match the Java fonts? But what to do about this :)? Helvetica is a pritty standard font..? Btw, If I say the font of a textfield (in iReport) is helvetica. I don't see that in the jrxml file.. Because it's the standard? Or why? (when I use Helvetica Bold, I do see it in the jrxml file btw) How can I check what fonts are available on the linux machine? Sorry about all the questions, but when text is missing it's pritty irritating :) Thanks for your help, Nick

 

 

 

EDIT, I tried to find how I can see what fonts are available in java.awt.
And I found this:

 

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        String[] fontNames = ge.getAvailableFontFamilyNames();

        for(String font:fontNames){
            System.out.println(font);
        }

 

When I run this in windows (where everything is fine). I also don't see Helvetica. Hmm, getting more confused by the minute

 

EDIT 2:
When I run this on Linux, I dont see the font helvetica either (Linux has much less fonts btw, around 20, windows has around 250). The fact that it is correct on windows is just pure luck than? Linux & Windows pick a default font to calculate space & stuff? And because they use different defailt fonts, the text is truncated on linux sometimes?



Post Edited by giroe janssen at 04/03/09 09:00
Link to comment
Share on other sites

giroe
Wrote:

When I run this on Linux, I dont see the font helvetica either (Linux has much less fonts btw, around 20, windows has around 250). The fact that it is correct on windows is just pure luck than? Linux & Windows pick a default font to calculate space & stuff? And because they use different defailt fonts, the text is truncated on linux sometimes?

Yep, that's probably the case.  IIRC, the default Java sansserif font on Windows is Arial which has similar metrics to Helvetica.

What you need to do if you want Helvetica in PDF is to make Helvetica (or Arial) available in the Linux Java machine and make sure that the text fields use it as fontName.

You can do this in several ways.  If you have Java 6, you can do it programatically via GraphicsEnvironment.registerFont().  Otherwise you could install it in the OS and Java would pick it up.  Or you could use the font extensions introduced in JR 3.1.3 to register the font.

Link to comment
Share on other sites

Ok, then I'm understanding the problem (a bit).

 

Thanks for your replies.

 

If I take a pdf font that is on linux and on windows. Like: LucidaSansRegular.ttf than it should also work fine? I tried this, but than I get error: Could not load the following font : pdfFontName : LucidaSansRegular.ttf pdfEncoding : Cp1252 isPdfEmbedded : true (I get this also when I say isPdfEmbedded false)

 

 I did ad the ttf files to a folder in my eclipse project. And I did add that folder to "java build path=> libraries tab => add class folder". Am I doing something wrong?

 

Thanks in advance,

 

Nick

 

EDIT: I am using java 1.5 (so 1.6 is not an option)

 




Post Edited by giroe janssen at 04/03/09 11:16
Link to comment
Share on other sites

giroe
Wrote:

If I take a pdf font that is on linux and on windows. Like: LucidaSansRegular.ttf than it should also work fine? I tried this, but than I get error: Could not load the following font : pdfFontName : LucidaSansRegular.ttf pdfEncoding : Cp1252 isPdfEmbedded : true (I get this also when I say isPdfEmbedded false)

 

 I did ad the ttf files to a folder in my eclipse project. And I did add that folder to "java build path=> libraries tab => add class folder". Am I doing something wrong?

If the *.ttf file is not the classpath (note that it should be on a folder which is itself placed on the classpath, and not in a subfolder of a classpath folder), then it should be picked up by JR.  What JR version are you using?

Regards,

Lucian

Link to comment
Share on other sites

I am using jasperreports 3.0.0

The .ttf file is in the classpath..

 

I added the folder: war/web-inf/lib to my classpath

and in the lib folder I put the ttf files for lucida.ttf

 

I'm not really getting what I'm doing wrong.

 

Help would be appreciated

 

Thanks

Link to comment
Share on other sites

We encountered a similar problem recently, and our solution was as follows.

With our ttf in the project directory, we used the following code to access our ttf as embedded PDF font:

//--code

import com.lowagie.text.FontFactory;
import com.lowagie.text.pdf.BaseFont;
...
FontFactory.registerDirectories();
URL fontPath = Thread.currentThread().getContextClassLoader().getResource("DejaVuSans.ttf");
FontFactory.register(fontPath.toString(), "DejaVuSans");
com.lowagie.text.Font f = FontFactory.getFont("DejaVuSans", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

//--end code

The font could then be referenced in our template:

pdfFontName="DejaVuSans" pdfEncoding="Identity-H" isPdfEmbedded="true"

 

We still had truncating issues, and this was because the font was not available to our jre. In order to get around this, our solution was fairly convoluted, as we were limited to Java 5. But we were able to duplicate the Java 6 method registerFont(java.awt.Font), which let us reference the font in our template: fontName="DejaVu Sans"

//get Font like so: Font.createFont(java.awt.Font.TRUETYPE_FONT, new File(fontPath.toURI()));

 

Hope that helps!

Link to comment
Share on other sites

  • 4 weeks later...

Hi

i have the same problem of font (text is truncated on pdf generated on Linux). I use java 1.5 (I CAN'T use 1.6) and jasperreports3.1.2

as i read in this forum, i applied this solution :

 Otherwise you could install it in the OS and Java would pick it up.

I use the fontName Arial. I installed on linux the package which includes arial fonts. I stopped and restarted the websphere server, but there is still the problem.

Do i have other thing to do in order that the jvm can pick the arial font up the OS fonts?

regards

Link to comment
Share on other sites

  • 5 months later...

Regarding:


See this FAQ.  You need to have the same font available to Java/AWT.


Questions:

Do you have a complete example (or a war file) that works for Tomcat and Linux showing the Java code (using with FontFactory.register() if that's required possible) and JRXML) and accesses  fonts (regular, bold, and italic) that are  placed into the war and that are  not available in the Linux font registry?


It doesn't matter what the font it is as long as the three are in one family.    It would be most convenient if we did not have to build the fonts into a separate Jar that you call a Font Extension, (we then have to load them back through Maven..). but if that is the only way, please include all the coding necessary to support the Font Extension jar. 

The example you give in the JasperReports distribution is a set of files, not a jar, and it seems to rely on some Spring framework code.   Is that correct?

I have not had any luck using fontName (fontName=Arial for instance) without pdfFontName.  It picks up some totally foreign font when I do that.  



Thanks!

Regards,

Rich

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