PDA

View Full Version : BaseFont.createFont failed



Anonymous
08-20-2002, 11:43 PM
Hi,all,
I try to run JFreeReport as a servlet on webLogic server,it works fun,
but it fails in recognizing some fonts,I do not know the reason,can
anyone tell me??the following is the message that is printed on the
console:
WARN: BaseFont.createFont failed.
com.lowagie.text.DocumentException: Font 'Arial Unicode MS' with 'Cp1252' is not
recognized.
at com.lowagie.text.pdf.BaseFont.createFont(Unknown Source)
at com.lowagie.text.pdf.BaseFont.createFont(Unknown Source)
at com.jrefinery.report.targets.PDFOutputTarget.setFont(PDFOutputTarget.
java:667)
at com.jrefinery.report.TextElement.draw(TextElement.java:252)
at com.jrefinery.report.Band.draw(Band.java:331)
at com.jrefinery.report.ReportProcessor.draw(ReportProcessor.java:102)
at com.jrefinery.report.ReportProcessor.draw(ReportProcessor.java:76)
at com.jrefinery.report.ReportProcessor.printGroupHeader(ReportProcessor
.java:173)
at com.jrefinery.report.ReportState$PreGroupHeader.advance(ReportState.j
ava:244)
at com.jrefinery.report.JFreeReport.processPage(JFreeReport.java:676)
at com.jrefinery.report.JFreeReport.processReport(JFreeReport.java:562)

Anonymous
08-22-2002, 03:15 AM
Hi,

the pdf library needs access to the ttf-files making up the true-type-fonts. In which environment do you run the websphere server? Windows or Unix? If windows, then JFreeReport tries to load the available fonts from %windir%/fonts. If unix it searches the fonts on /usr/X11R6/lib/X11/fonts/truetype.
If you have stored your fonts in other directories, you have to iniitalize the font engine manually by calling:

PDFOutputTarget.getFontFactory().registerFontPath(String)

or

PDFOutputTarget.getFontFactory().registerFontFile (String filenameOfTTF);

Then everyting should be fine.

Have more fun,
said Thomas

Anonymous
08-22-2002, 03:20 AM
Ha!

Cp1252 sound like Mac, doesn't it? I can be that a mac is not recognized correctly by JFreeReport. So if you coud send me the contents of the "System.os" system-property and the location of the default font directory containing ttf-files, I could add this to the lib, so that such things won't happen again..

And I saw: WebLogic, not ~shpere ... but the result is the same ...

Have more fun,
said Thomas

Anonymous
08-22-2002, 03:47 PM
Hi,

I reproduced the bug here. The font you want to use is not available in your system, neither Java nor the iText library have access to this font. Are you sure you have the font installed?

This error is repeatable by changing the font name in any report definition to something stupid, like "%$%

Anonymous
08-22-2002, 09:45 PM
Hu,Thomas,
Thank you for your replay:)
I studied the tutor document of iText,and find some information.
First,let's see an example of BaseFont.createFont:

BaseFont.createFont("Helvetica", BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

The second parameter is the encoding.Cp1252,latin 1 extended with 27 characters; the encoding is also known as 'winansi'.

I am in China and use simple Chinese.I find the information
like this:

CJK Fonts
You can also add text in some predefined Chinese/Korean/Japanese fonts (using UNICODE):
BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
Font FontChinese = new Font(bfChinese, 12, Font.NORMAL);
Chunk chunk = new Chunk("\u6e96\u53d7\u4fdd\u4eba", FontChinese);
document.add(chunk);
This piece of code is used in example 9 and you can take a look a the result here.

You can create PDF-documents with the following fonts:

Chinese Simplified
STSong-Light with the encodings UniGB-UCS2-H and UniGB-UCS2-V

Does that mean i can only use font STSong-Light with the encodings UniGB-UCS2-H and UniGB-UCS2-V in simple Chinese??

thanks again:)

Anonymous
08-23-2002, 03:25 PM
Hi,

From the examples documentation:
<quote>
Important:
Remember that you can't embed these fonts in the PDF file using iText. Before trying to view a pdf with these Asian characters, you must download the Asian font pack from Adobe at: http://www.adobe.com/products/acrobat/acrrasianfontpack.html. or use a localized Windows. An alternative for this kind of fonts, is using a True Type Asian Font or Collection such as msgothic.ttc with the encoding BaseFont.IDENTITY_H or BaseFont.IDENTITY_V. You can use them exactly the same way as we did in the section about True Type Fonts and there will be no need to use the Asian font pack from Adobe because a subset of the font will be embedded in the document.
</quote>

Anyway, you are not tied to that fonts. Any unicode font will do the job. I altered report3.xml to show you a better way ... and the beast crashed when saving the pdf :(

I had to fix the handling of the standard-fonts Serif, SansSerif and Monospace, which get mapped into the PDF-Standardfonts Helvetica, Times-Roman and Courier. These standardfonts do not accept the IDENTITY_H or IDENTITY_V encoding, they want an "iso-8859-x" string instead. I added a special handling for those fonts to the OutputTargets.

Additionally the LineBreak-methods were broken, but thats another issue ... I love this day :)

If you have the truetype font "Arial Unicode MS" installed on your maschine, you should be able to run and save report3.xml without any problems. I added the Unicode sequence from Example 9 to the reports group footer, in the group header you'll find another sequence of characters (Korean, if I remember right, I found them on Unicode.org a long time ago).

If you use JFreeReport in your programms, make sure that the fonts are registered properly, or they cannot be embedded into the pdf and will result in this evil "DocumentException".

To register the fonts, you'll have to insert the line
PDFOutputTarget.getFontFactory ().registerDefaultFontPath ();
into your code, or you have to set the system property "com.jrefinery.report.targets.PDFOutputTarget.AUTOINIT" to true.

JFreeReport searches your Systems known font locations for *.ttf files and adds their names to the internal repository of fonts. This data is later used to transparently map between the logical fontnames (f.i. "Arial Unicode MS" and the real font filename (in this case it is most likely "arialuni.ttf").

The fonts "STSong-Light" and the other fonts mentioned seem to be special fonts (like Helvetica is for the western fonts), but Java does not know them, so they are limited to PDF only and not currently supported. (Reason: There seems to be no way to display those fonts in the Preview or in other OutputTargets).

(Warning: You won't see a missing font in the Preview, as Java-AWT seems to ignore buggy font specifications or handles them without throwing an exception.)

Have more fun,
said Thomas

Anonymous
08-24-2002, 11:03 PM
Hi,Thomas,
I cannt open the page http://sourceforge.net/projects/jfreereport,
and cannt download the package.Could you send me the new
report3.xml and the source code of the functions that you have
modified?I will try it as you mentioned..
thanks a lot

tsingt