Add font to document template

3
I have followed the steps to add a new font for a document template. I have kopied all ttf data in the resouces map and also a new fop.xconf file with the following text: <font-triplet name="Calibri" style="normal" weight="normal"/> <font-triplet name="CalibriMT" style="normal" weight="normal"/> I have also added font-family: Calibri to the template style, but the modeler will not look at the files in the resources map. Do I missed something or is there maybe a difference between Mendix version 2 and 4, because it works in version 2.5.8!
asked
5 answers
3

Add this configuration to the fop.xconf in your resource folder for calibri:

    <font kerning="yes" embed-url="calibri.ttf">
      <font-triplet name="calibri" style="normal" weight="normal"/>
    </font>
<font kerning="yes" embed-url="calibrii.ttf">
      <font-triplet name="calibri" style="italic" weight="normal"/>
    </font>
<font kerning="yes" embed-url="calibrib.ttf">
      <font-triplet name="calibri" style="normal" weight="bold"/>
    </font>
<font kerning="yes" embed-url="calibriz.ttf">
      <font-triplet name="calibri" style="italic" weight="bold"/>
    </font>

Also you need to copy all referenced ttf files into the resources folder. Also be aware that the font name is case sensitive, so

name="Calibri"

is not the same as

name="calibri"

and only the latter will work (for calibri font). In your document template add this as a custom style:

font-family: Calibri;
answered
2
  1.  go to C:\Program Files\Mendix\<mx version>\runtime\lib\
  2. copy fop.xconf file to your project inside folder named resources.
  3.  download your desired font and copy it as well inside resources .
  4.  edit fop.xconf file and within the <fonts> tag, copy the following :

         <font kerning="yes" embed-url="desired font.ttf">
             <font-triplet name="desired font" style="normal" weight="normal"/>
         </font>

* makesure the font-triplet name  is a lowercase.

       5. save. 

       6. in mendix modular, the document template edit the desired element and in custom styles tab copy the following 

        font-family: desired font;

hope this fix the issue 

answered
1

We have it working in 4.8.6. I have placed the fop example below.

<?xml version="1.0"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- $Id: fop.xconf 447325 2006-09-18 08:55:33Z jeremias $ -->

<!--

This is an example configuration file for FOP.
This file contains the same settings as the default values
and will have no effect if used unchanged.

Relative config url's will be resolved relative to
the location of this file.

-->

<!-- NOTE: This is the version of the configuration -->
<fop version="1.0">

  <!-- Base URL for resolving relative URLs -->
  <base>.</base>

  <!-- Source resolution in dpi (dots/pixels per inch) for determining the size of pixels in SVG and bitmap images, default: 72dpi -->
  <source-resolution>72</source-resolution>
  <!-- Target resolution in dpi (dots/pixels per inch) for specifying the target resolution for generated bitmaps, default: 72dpi -->
  <target-resolution>72</target-resolution>

  <!-- Default page-height and page-width, in case
       value is specified as auto -->

  <!-- Information for specific renderers -->
  <!-- Uses renderer mime type for renderers -->
  <renderers>
    <renderer mime="application/pdf">
      <filterList>
        <!-- provides compression using zlib flate (default is on) -->
        <value>flate</value>

        <!-- encodes binary data into printable ascii characters (default off)
             This provides about a 4:5 expansion of data size -->
        <!-- <value>ascii-85</value> -->

        <!-- encodes binary data with hex representation (default off)
             This filter is not recommended as it doubles the data size -->
        <!-- <value>ascii-hex</value> -->
      </filterList>

      <fonts>
        <!-- embedded fonts -->
        <!--
        This information must exactly match the font specified
        in the fo file. Otherwise it will use a default font.

        For example,
        <fo:inline font-family="Arial" font-weight="bold" font-style="normal">
            Arial-normal-normal font
        </fo:inline>
        for the font triplet specified by:
        <font-triplet name="Arial" style="normal" weight="bold"/>

        If you do not want to embed the font in the pdf document
        then do not include the "embed-url" attribute.
        The font will be needed where the document is viewed
        for it to be displayed properly.

        possible styles: normal | italic | oblique | backslant
        possible weights: normal | bold | 100 | 200 | 300 | 400
                          | 500 | 600 | 700 | 800 | 900
        (normal = 400, bold = 700)
        -->

        <!--
        <font metrics-url="arial.xml" kerning="yes" embed-url="arial.ttf">
          <font-triplet name="Arial" style="normal" weight="normal"/>
          <font-triplet name="ArialMT" style="normal" weight="normal"/>
        </font>
        <font metrics-url="arialb.xml" kerning="yes" embed-url="arialb.ttf">
          <font-triplet name="Arial" style="normal" weight="bold"/>
          <font-triplet name="ArialMT" style="normal" weight="bold"/>
        </font>
        -->

        <font kerning="yes" embed-url="tahoma.ttf">
          <font-triplet name="tahoma" style="normal" weight="normal"/>
          <font-triplet name="tahomaMT" style="normal" weight="normal"/>
        </font>
        <font kerning="yes" embed-url="tahomabd.ttf">
          <font-triplet name="tahoma" style="normal" weight="bold"/>
          <font-triplet name="tahomaMT" style="normal" weight="bold"/>
        </font>
        <font kerning="yes" embed-url="tahoma.ttf">
          <font-triplet name="tahoma" style="italic" weight="normal"/>
          <font-triplet name="tahomaMT" style="italic" weight="normal"/>
        </font>
        <font kerning="yes" embed-url="tahomabd.ttf">
          <font-triplet name="tahoma" style="italic" weight="bold"/>
          <font-triplet name="tahomaMT" style="italic" weight="bold"/>
        </font>

        <font kerning="yes" embed-url="arial.ttf">
          <font-triplet name="Arial" style="normal" weight="normal"/>
          <font-triplet name="ArialMT" style="normal" weight="normal"/>
        </font>
        <font kerning="yes" embed-url="arialbd.ttf">
          <font-triplet name="Arial" style="normal" weight="bold"/>
          <font-triplet name="ArialMT" style="normal" weight="bold"/>
        </font>
        <font kerning="yes" embed-url="ariali.ttf">
          <font-triplet name="Arial" style="italic" weight="normal"/>
          <font-triplet name="ArialMT" style="italic" weight="normal"/>
        </font>
        <font kerning="yes" embed-url="arialbi.ttf">
          <font-triplet name="Arial" style="italic" weight="bold"/>
          <font-triplet name="ArialMT" style="italic" weight="bold"/>
        </font>

        <font kerning="yes" embed-url="thesans.ttf">
          <font-triplet name="thesans" style="normal" weight="normal"/>
        </font>

        <font kerning="yes" embed-url="thesansbold.ttf">
          <font-triplet name="thesansbold" style="normal" weight="bold"/>
        </font>


      </fonts>

      <!-- This option lets you specify additional options on an XML handler -->
      <!--xml-handler namespace="http://www.w3.org/2000/svg">
        <stroke-text>false</stroke-text>
      </xml-handler-->

    </renderer>

    <renderer mime="application/postscript">
      <!-- This option forces the PS renderer to rotate landscape pages -->
      <!--auto-rotate-landscape>true</auto-rotate-landscape-->

      <!-- This option lets you specify additional options on an XML handler -->
      <!--xml-handler namespace="http://www.w3.org/2000/svg">
        <stroke-text>false</stroke-text>
      </xml-handler-->
    </renderer>

    <renderer mime="application/vnd.hp-PCL">
    </renderer>

    <!-- MIF does not have a renderer
    <renderer mime="application/vnd.mif">
    </renderer>
    -->

    <renderer mime="image/svg+xml">
      <format type="paginated"/>
      <link value="true"/>
      <strokeText value="false"/>
    </renderer>

    <renderer mime="application/awt">
    </renderer>

    <renderer mime="image/png">
      <!--transparent-page-background>true</transparent-page-background-->
    </renderer>

    <renderer mime="image/tiff">
      <!--transparent-page-background>true</transparent-page-background-->
      <!--compression>CCITT T.6</compression-->
    </renderer>

    <renderer mime="text/xml">
    </renderer>

    <!-- RTF does not have a renderer
    <renderer mime="text/rtf">
    </renderer>
    -->

    <renderer mime="text/plain">
      <pageSize columns="80"/>
    </renderer>

  </renderers>

</fop>
answered
0

I've had exactly the same issue here. It seems like the custom fop.xconf in the resources folder is ignored. Instead Mendix takes the fop.xconf from the modeler installation folder.

answered
0

For debugging purposes, you could make a Java action that returns the path string to the resources folder (and also returns it as a string)

    // BEGIN USER CODE
    String path = Core.getConfiguration().getResourcesPath().toString();
    Core.getLogger("log").info("path: " + path);
    return path;
    // END USER CODE

What does this print for you? It should be the folder that contains the fop.xconf file. If it doesn't then it won't be able to find your custom config file and will just take the default.

answered