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

PDF Export for Russian Fonts


abyot

Recommended Posts

Hello,

 

I was working on jasperreports to generate locale reports in Russian Llanguage. And my report works fine for HTML preview but not for PDF preview. Below is my configuration for the locale.

 

font=Times New Roman

PDF Font=Times-Roman

PDF Embedded=true

PDF Encoding=Identity-H

 

But below is the error I got.

 

Thanks

Abyot.

 

Error exporting print... Could not load the following font : pdfFontName : Times-Roman pdfEncoding : Identity-H isPdfEmbedded : true

Can't find the translation for key = iReportCompiler.errorExportingPrint: using default (Error exporting print... {0} ) net.sf.jasperreports.engine.JRRuntimeException: Could not load the following font : pdfFontName : Times-Roman pdfEncoding : Identity-H isPdfEmbedded : true at net.sf.jasperreports.engine.export.JRPdfExporter.getFont(JRPdfExporter.java:1551) at net.sf.jasperreports.engine.export.JRPdfExporter.getChunk(JRPdfExporter.java:1454) at net.sf.jasperreports.engine.export.JRPdfExporter.getPhrase(JRPdfExporter.java:1437) at net.sf.jasperreports.engine.export.JRPdfExporter.exportText(JRPdfExporter.java:1794) at net.sf.jasperreports.engine.export.JRPdfExporter.exportElements(JRPdfExporter.java:632) at net.sf.jasperreports.engine.export.JRPdfExporter.exportPage(JRPdfExporter.java:596) at net.sf.jasperreports.engine.export.JRPdfExporter.exportReportToStream(JRPdfExporter.java:539) at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:334) at it.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:1329) at java.lang.Thread.run(Unknown Source) Caused by: ExceptionConverter: java.io.UnsupportedEncodingException: Identity-H

Export running time: 16

Link to comment
Share on other sites

  • Replies 16
  • Created
  • Last Reply

Top Posters In This Topic

Hi,

 

 

The Times-Roman is one of the 14 PDF built-in fonts, so you cannot use isPdfEmbedded="true" and pdfEncoding="Identity-H" with it.

The font should not be embedded and the encoding should be the one that supports Cyrillic, like "CP1251".

 

 

I hope this helps.

Teodor

Link to comment
Share on other sites

  • 2 weeks later...

Further to my previous post and other threads on the same topic:

 

Contrary to what the documentation says, fontName DOES appear to have some impact on what happens during PDF export.

 

For example, I can have fontName as "Courier New" and pdfFont as "Tahoma" and it will fail to render cyrillic.

If I then set fontName to "Arial" it WILL render the cyrillic.

 

Mind you I found I also had to register the PDF Font to allow me to use the font name, rather than the file path to the font file.

Code:
JRProperties.setProperty(JRProperties.PDF_FONT_FILES_PREFIX+"Tahoma","c:/windows/fonts/tahoma.ttf" );

 

and I also found that in order to get it to render bold, I had to also register the bold font - but then I had to explicitly set any bold characters to use that font:

 

Code:
[code]JRProperties.setProperty(JRProperties.PDF_FONT_FILES_PREFIX+"TahomaBD","c:/windows/fonts/tahomabd.ttf" );

 

It's all rather 'clunky'.

Link to comment
Share on other sites

lucianc wrote:

Which documentation is that?
The JasperReports.1.3.4.pdf I purchased which states:

 

The font name introduced by the previously explained fontName attribute is of no use
when exporting to PDF.

 

lucianc wrote:

Have you read this FAQ?
I'll take a look at that shortly.

 

My brain is already hurting from trying to reconcile all the different results/behaviours I have so far experienced.

 

Almost everything now works as expected - except that I'm having problems getting Tahoma to render in italic...

Link to comment
Share on other sites

lucianc wrote:

Have you read this FAQ?
I have had a look at that - ok, so it appears that I should be looking to use the SAME font(name) for fontName and pdfFontName unless I want to risk 'odd' results.

 

 

That's fine, except I need to use Tahoma and so far I'm not seeing italics. I've registered Tahoma as per:

Code:
          JRProperties.setProperty(JRProperties.PDF_FONT_FILES_PREFIX+"Tahoma","c:/windows/fonts/tahoma.ttf" );
JRProperties.setProperty(JRProperties.PDF_FONT_FILES_PREFIX+"Tahoma-Bold","c:/windows/fonts/tahomabd.ttf" ); these being the ONLY Tahoma fonts on the system. So how to get italics?
Link to comment
Share on other sites

OK, some progress.

 

I tried setting the PDF font directory:

Code:
JRProperties.setProperty(JRProperties.PDF_FONT_DIRS_PREFIX+"jasper","c:/windows/fonts/" );

And was expecting from there that would mean I could refer to font names directly, or at least by file name. e.g.

Code:
[code]fontMap.put(new FontKey("Tahoma", true, false), new PdfFont("Tahoma Bold" , "Cp1252", false, false, false));

OR

Code:
[code]fontMap.put(new FontKey("Tahoma", true, false), new PdfFont("tahomabd.ttf" , "Cp1252", false, false, false));

But that doesn't seem to work. Tracing through the code, at one point the JRPdfExporter class tries to load the font using

Code:
[code]bytes = JRLoader.loadBytesFromLocation(pdfFont.getPdfFontName(), classLoader, urlHandlerFactory);

But it does NOT use the PDF_FONT_DIR as defined and hence fails to load the font.

 

 

I have found that if I register the font explicitly:

Code:
[code]JRProperties.setProperty(JRProperties.PDF_FONT_FILES_PREFIX+"Tahoma-Bold","c:/windows/fonts/tahomabd.ttf" );

Then I can later refer to it as follows:

Code:
[code]fontMap.put(new FontKey("Tahoma", true, false), new PdfFont("Tahoma-Bold", "Cp1252", false, false, false));

and then things kinda work.

 

It also allows 'alternate' fonts to be mapped, e.g.:

Code:
[code]fontMap.put(new FontKey("Tahoma-ru", false, false), new PdfFont("Tahoma" , "Cp1251", false, false, false));

which then allows cyrillics to be rendered in PDF files.

 

 

The whole font handling stuff is all very confusing - and the documentation doesn't really make things any clearer.

 

 

I hope that the information I've posted will help some other poor souls equally lost in font-hell and that maybe, someone who has some better understanding of how it's supposed to work will actually point out where I'm going wrong!

Link to comment
Share on other sites

sww wrote:

I tried setting the PDF font directory:
Code:
JRProperties.setProperty(JRProperties.PDF_FONT_DIRS_PREFIX+"jasper","c:/windows/fonts/" );

And was expecting from there that would mean I could refer to font names directly, or at least by file name. e.g.

Code:
[code]fontMap.put(new FontKey("Tahoma", true, false), new PdfFont("Tahoma Bold" , "Cp1252", false, false, false));

 

I've just tried the same and it worked fine. Any pointers in reproducing the behaviour you are describing? Note that when registering font directories, only font names can be used as PDF font names (and not font file names).

 

The whole font handling stuff is all very confusing.

 

We are open to any (feasible) suggestions of improving this area.

 

Regards,

Lucian

Link to comment
Share on other sites

lucianc wrote:

Note that when registering font directories, only font names can be used as PDF font names (and not font file names).
Aha! I actually hadn't tried that... (I'd only tried accessing the fonts by file names - e.g. "tahomabd.ttf") Mind you, it seemed to manage ok finding "tahoma.ttf" - but I'm now suspecting it wasn't reading the ".ttf" as a file extension.

 

 

I'm right now trying it with the font name "Tahoma Bold"...

 

lucianc wrote:

We are open to any (feasible) suggestions of improving this area.

Once I've fully bottomed out all the issues, I will see if I can come up with some suggestions.

 

 

For now, it would be good if there was some clear documentation on how to set up the properties for PDF_FONT_DIRS_PREFIX - I'm now using:

Code:
JRProperties.setProperty(JRProperties.PDF_FONT_DIRS_PREFIX+"jasper","c:/windows/fonts/" );

but I only concluded from a comment in the Font sample that after the prefix it should be "jasper" - or is it an arbitrary tag?

 

 

The font sample also has:

Code:
[code]net.sf.jasperreports.export.pdf.font.Arial.Bold=../fonts/ARIALBD.TTF
net.sf.jasperreports.export.pdf.font.Arial.Slanted=../fonts/ARIALI.TTF

But there is no obvious explanation in the code (or documentation) as to how the ".Bold" or ".Slanted" [btw, the word 'Italic' would be better...] are supposed to be used.

 

 

Now that I have some font mappings, things seem to be generally working, though I've had to add font registration in between report filling and the pdf export. I was originally using

Code:
[code]runReportToPdfFile(file, parameters, data_source)
to generate the report, but I don't see how the font registration can work with that.

Post edited by: sww, at: 2008/01/14 16:27

Link to comment
Share on other sites

sww wrote:

For now, it would be good if there was some clear documentation on how to set up the properties for PDF_FONT_DIRS_PREFIX - I'm now using:
Code:
JRProperties.setProperty(JRProperties.PDF_FONT_DIRS_PREFIX+"jasper","c:/windows/fonts/" );

but I only concluded from a comment in the Font sample that after the prefix it should be "jasper" - or is it an arbitrary tag?

 

The suffix is arbitrary and only used to prevent property name conflicts in the case of multiple font directories.

 

But there is no obvious explanation in the code (or documentation) as to how the ".Bold" or ".Slanted" [btw, the word 'Italic' would be better...] are supposed to be used.

 

Suffixes in this case can be used as font aliases, e.g. one could use Arial.Bold or Arial.Slanted as PDF font names.

 

Regards,

Lucian

Link to comment
Share on other sites

lucianc wrote:

Suffixes in this case can be used as font aliases, e.g. one could use Arial.Bold or Arial.Slanted as PDF font names.

OK. That's one more thing cleared up.

 

Now all I need is a simpler way to do font mappings than:

Code:
      Map fontMap = new HashMap();
fontMap.put(new FontKey("Tahoma", false, false), new PdfFont("Tahoma" , "Cp1252", false, false, false));
fontMap.put(new FontKey("Tahoma", false, true), new PdfFont("Tahoma" , "Cp1252", false, false, true));
fontMap.put(new FontKey("Tahoma", true, false), new PdfFont("Tahoma Bold", "Cp1252", false, false, false));
fontMap.put(new FontKey("Tahoma", true, true), new PdfFont("Tahoma Bold", "Cp1252", false, false, true));
fontMap.put(new FontKey("Tahoma-ru", false, false), new PdfFont("Tahoma" , "Cp1251", false, false, false));
fontMap.put(new FontKey("Tahoma-ru", false, true), new PdfFont("Tahoma" , "Cp1251", false, false, true));
fontMap.put(new FontKey("Tahoma-ru", true, false), new PdfFont("Tahoma Bold", "Cp1251", false, false, false));
fontMap.put(new FontKey("Tahoma-ru", true, true), new PdfFont("Tahoma Bold", "Cp1251", false, false, true));

exporter.setParameter(JRExporterParameter.FONT_MAP, fontMap);

and then I'd be quite satisfied :)

 

 

Thanks for your replies so far.

Link to comment
Share on other sites

  • 3 months later...

Hi,

 

Did you get it working? If so could you please provide the detail steps how to set the pdffont during the export?

 

I wanted to load different fonts based on the Locale at the run time and I'm using the codes like this:

 

FontKey key = new FontKey("SansSerif", true, false);

// PdfFont font = new

PdfFont font = new PdfFont(" Arial", "Cp1250", true, false, false);

fontMap.put(key, font);

exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString());

exporter.setParameter(JRExporterParameter.FONT_MAP, fontMap);

 

exporter.exportReport();

 

I added the font dir to the classpath, however, the pdf file still contains the default font which was used in the ireport .jrxml.

 

I know I have missed something, please provide some inputs.

 

Many thanks,

 

mz

Link to comment
Share on other sites

  • 4 years later...

I wanted to get some general guidance on the following fonts to be used in PDFs: Russian, Chzech, Chinese, Hebrew.

 

I am looking for a place where I can download the fonts for the languages mentioned above and embed in the software.

 

Any guidance/instructions on this topic would be helpful.

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