More Resources
Table of Contents
More Resources
Adding Custom Fonts
Custom Fonts
Customize your PDF by using custom fonts. You can install them locally or compile them with your plugin.
Adding Fonts Locally
Installing Custom Fonts, Finding Font Names
Adding Custom Fonts to the XML
Edit the XML document to include the custom fonts.
Compiling Custom Fonts for Plugin
Creating the XML Font Metric File, Creating a Custom fop Configuration
Editing the XSL Stylesheet
Add XSL styling to the custom.xsl file to tell the build file to use the new fonts for the specific sections.
Custom Fonts

Customize your PDF by using custom fonts. You can install them locally or compile them with your plugin.
By default, the DITA OT uses the fonts installed on the computer running the publish. If you want to publish locally using your computer, you can use custom fonts by Adding Fonts Locally on your computer.
When publishing through easyDITA, you have to package the custom fonts with your plugin. See Compiling Custom Fonts for Plugin for more information.
To use custom fonts in your PDF output:
Adding Custom Fonts to the XML

Edit the XML document to include the custom fonts.
You want to tell the DITA build file that you want to use new fonts when creating PDFs.
  1. Open the font-mappings.xml file (located in cfg/fo/ folder) within your DITA-OT install.
  2. Add a new logical-font attribute for the custom font. This element should be next to the other logical-font definitions within the < font-table> tag.

    Step Information
    Tip:You can add as many of these new logical-fonts as you want, as long as they have distinct names.

    Example
    < logical-font name="{font_description}"> 
    	< physical-font char-set="default"> 
    		< font-face> {font-face_name}< /font-face> 
    	< /physical-font> 
    < /logical-font> 

  3. Fill in {font_description} with a recognizeable name for the font that you can use in the xsl stylesheets.
  4. Fill in {font-face_name} with the correct font name.

    1. If you’re testing fonts locally, use the name in Finding Font Names.
    2. If you’re compiling your font with your plugin, use the “font-face_name” value that you added to your custom fop.xconf file in Creating a Custom fop Configuration.
  5. (Optional) You can also change the default fonts by going into the logical-font name=”Sans” (for headers) and name=”Serif” (for body) and changing the char-set=”default” font-face to the (font-face_name) in Step 4.
  6. Open your catalog.xml file and double check that it is referencing your font-mappings file.
DITA recognizes these new fonts. Now, you’ll need to look at Editing the XSL Stylesheet.
Note:If you change the defaults (Step 5), you don’t need to edit the custom.xsl.xsl file. For more information, see Editing the XSL Stylesheet.

Editing the XSL Stylesheet

Add XSL styling to the custom.xsl file to tell the build file to use the new fonts for the specific sections.
You want to tell the build file to use the custom fonts.

  1. Open the custom-attrs.xsl file (located in cfg/fo/attrs/).

    Expected Result
    The XSL stylesheet has no content.
  2. To change the font for the header, insert the following code:

    Example
    < xsl:attribute-set name="common.title"> 
    	< xsl:attribute name="font-family"> {font_description}< /xsl:attribute> 
    < /xsl:attribute-set> 

  3. To change the font for the body, insert the following code:

    Example
    < xsl:attribute-set name="__fo__root"> 
    	< xsl:attribute name="font-family"> {font_description}< /xsl:attribute> 
    < /xsl:attribute-set> 

  4. Replace {font_description} with the logical-font name created in Adding Custom Fonts to the XML.
DITA associates the headers and body with the new fonts.