XSL-FO: how to add “helvetica neue” fonts and output to pdf

情到浓时终转凉″ 提交于 2020-01-05 09:37:48

问题


Am I correct that it's not possible to use fonts from windows 7 c:\windows\fonts* when using XSL-FO (Apache FOP) to generate a pdf?

I've just installed the "helvetica neue" font in OTF format.

According to https://xmlgraphics.apache.org/fop/trunk/fonts.html

"Support for system fonts relies on the Java AWT subsystem for font metric information. Through operating system registration, the AWT subsystem knows what fonts are available on the system, and the font metrics for each one.

When working with renderers that supports system fonts (see above table) and you're missing a font, you can just install it in your operating system and it should be available for these renderers. Please note that this is not true for output formats, such as PDF or PostScript, that only support custom fonts."

If my understanding is correct, it's saying that if my render is PDF (meaning output is pdf??), then I can't access the fonts through AWT/OS, therefore, I won't be able to generate the text with such fonts in PDF using the the windows 7 fonts?

------------------------------Update, this works only for ttf font, not otf. Not sure how I can get otf fonts to work.

-----------------------------update: 20150402:

Using FOP 1.1:

I downloaded this particular free helvetica neue font from: http://www.ephifonts.com/free-helvetica-font-helvetica-neue.html

I configured fop to use fop.xconf but I'm getting an error processing the ttf file, and I don't know how to edit the font ttf file with fontforge:

fop -c fop.xconf -xml xml.xml -xsl coversheet.xsl -pdf output.pdf

Apr 2, 2015 6:53:55 PM org.apache.fop.fonts.truetype.TTFFile readCMAP
SEVERE: Unsupported TrueType font: No Unicode or Symbol cmap table not    present. Aborting
Apr 2, 2015 6:53:55 PM org.apache.fop.events.LoggingEventListener    processEvent
WARNING: Unable to load font file: file:/C:/windows/FONTS/HelveticaNeue.ttf. Reason: java.io.IOException: TrueType font is not supported: file:/C:/windows/FONTS/HelveticaNeue.ttf

Apr 2, 2015 6:53:55 PM org.apache.fop.fonts.truetype.TTFFile getTTCnames
INFO: This is a TrueType collection file with 4 fonts

Thanks


回答1:


(preliminary disclosure: I'm a FOP developer)

Am I correct that it's not possible to use fonts from windows 7 c:\windows\fonts* when using XSL-FO (Apache FOP) to generate a pdf?

Fonts need to be configured in order to be recognised and used by FOP, but the configuration can be really simple: you can tell FOP to look at all the font files in a specific directory (even recursively), or simply to look for font in the "usual" places.

This configuration fragment is taken from the same font configuration page linked in your question:

<renderers>
  <renderer mime="application/pdf">
     <fonts>
        <!-- register all the fonts found in a directory -->
        <directory>C:\MyFonts1</directory>

        <!-- register all the fonts found in a directory and all of its sub directories (use with care) -->
        <directory recursive="true">C:\MyFonts2</directory>

        <!-- automatically detect operating system installed fonts -->
        <auto-detect/>
     </fonts>
  </renderer>
</renderers>

You can find additional details concerning the font configuration in this answer.

Update, this works only for ttf font, not otf. Not sure how I can get otf fonts to work.

OpenType fonts support has been added with version 2.0.



来源:https://stackoverflow.com/questions/29379281/xsl-fo-how-to-add-helvetica-neue-fonts-and-output-to-pdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!