title: Polish special letters not available while using Apache FOP
body: <p>I've been struggling a lot with generating a PDF using FOP, with Polish letters. I have been reading a lot of posts here on SO but so far no success! </p>
  
  <p>Here is my Template: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"&gt;
    &lt;xsl:template match="root"&gt;
      &lt;fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"&gt;
        &lt;fo:layout-master-set&gt;
          &lt;fo:simple-page-master master-name="simpleA4" page-height="29.7cm" page-width="21cm" margin-top="2cm" margin-bottom="2cm" margin-left="2cm" margin-right="2cm"&gt;
            &lt;fo:region-body/&gt;
          &lt;/fo:simple-page-master&gt;
        &lt;/fo:layout-master-set&gt;
        &lt;fo:page-sequence master-reference="simpleA4"&gt;
          &lt;fo:flow flow-name="xsl-region-body"&gt;
            &lt;fo:block font-size="11pt" font-family='Arial'&gt;
              &lt;xsl:value-of select="TestString"/&gt;
            &lt;/fo:block&gt;
          &lt;/fo:flow&gt;
        &lt;/fo:page-sequence&gt;
      &lt;/fo:root&gt;
    &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>And my XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;root&gt;
    &lt;TestString&gt;Chcemy mieć pewność, że nasze produkty będą miały długą żywotność i stosujemy opakowania, aby uchronić je przed uszkodzeniem podczas przenoszenia i transportu.&lt;/TestString&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>and my Java code calling it: </p>
  
  <pre><code>private void PolishTest() throws IOException, FOPException, TransformerException {
      // the XSL FO file
      File xsltFile = new File("C:\\Temp\\PolishTest.xsl");
      // the XML file which provides the input
      StreamSource xmlSource = new StreamSource(new File("C:\\Temp\\PolishTest.xml"));
      // create an instance of fop factory
      FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI());
      // a user agent is needed for transformation
      FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
  
      // Setup output
      OutputStream out = new FileOutputStream("C:\\Temp\\PolishTest.pdf");
  
      try {
          // Construct fop with desired output format
          Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
  
          // Setup XSLT
          TransformerFactory factory = TransformerFactory.newInstance();
          Transformer transformer = factory.newTransformer(new StreamSource(xsltFile));
  
          // Resulting SAX events (the generated FO) must be piped through to FOP
          Result res = new SAXResult(fop.getDefaultHandler());
  
          // Start XSLT transformation and FOP processing
          // That's where the XML is first transformed to XSL-FO and then
          // PDF is created
          transformer.transform(xmlSource, res);
      } finally {
          out.close();
      }
  }
  </code></pre>
  
  <p>as seen in my template I'm using Arial as font family, and if I type the text in word, using Arial it works out very fine. But when calling it from Java</p>
  
  <p>I get a lot of warnings: </p>
  
  <pre><code>jul. 10, 2018 8:16:57 AM org.apache.fop.events.LoggingEventListener processEvent
  WARNING: Font "Arial,normal,400" not found. Substituting with "any,normal,400".
  jul. 10, 2018 8:16:57 AM org.apache.fop.events.LoggingEventListener processEvent
  WARNING: Glyph "ć" (0x107, cacute) not available in font "Times-Roman".
  jul. 10, 2018 8:16:57 AM org.apache.fop.events.LoggingEventListener processEvent
  WARNING: Glyph "ś" (0x15b, sacute) not available in font "Times-Roman".
  jul. 10, 2018 8:16:57 AM org.apache.fop.events.LoggingEventListener processEvent
  WARNING: Glyph "ż" (0x17c, zdot) not available in font "Times-Roman".
  jul. 10, 2018 8:16:57 AM org.apache.fop.events.LoggingEventListener processEvent
  WARNING: Glyph "ę" (0x119, eogonek) not available in font "Times-Roman".
  jul. 10, 2018 8:16:57 AM org.apache.fop.events.LoggingEventListener processEvent
  WARNING: Glyph "ą" (0x105, aogonek) not available in font "Times-Roman".
  jul. 10, 2018 8:16:57 AM org.apache.fop.events.LoggingEventListener processEvent
  WARNING: Glyph "ł" (0x142, lslash) not available in font "Times-Roman".
  jul. 10, 2018 8:16:57 AM org.apache.fop.events.LoggingEventListener processEvent
  </code></pre>
  
  <p>So my question is (ofcause) what am I doing wrong? </p>
  
  <p>How come FOP chooses "Times-Roman", even though I've specified Arial? And more important how to fix it? </p>
  
  <p>** UPDATE **</p>
  
  <p>With the code from am9417's answer I've updated my Java code to the following: </p>
  
  <pre><code>private static String config = "&lt;?xml version=\"1.0\" encoding=\"utf-8\" ?&gt;\n" +
          "&lt;fop&gt;\n" +
          "  &lt;renderers&gt;\n" +
          "    &lt;renderer mime=\"application/pdf\"&gt;\n" +
          "      &lt;fonts&gt;\n" +
          "        &lt;auto-detect/&gt;\n" +
          "      &lt;/fonts&gt;\n" +
          "    &lt;/renderer&gt;\n" +
          "  &lt;/renderers&gt;\n" +
          "&lt;/fop&gt;";
  
  private void PolishTest() throws IOException, SAXException, TransformerException {
      // the XSL FO file
      File xsltFile = new File("C:\\Temp\\PolishTest.xsl");
      // the XML file which provides the input
      StreamSource xmlSource = new StreamSource(new File("C:\\Temp\\PolishTest.xml"));
      // create an instance of fop factory
  
      URI uri =  new File(".").toURI();
      InputStream configSource = new ByteArrayInputStream(config.getBytes());
  
      FopFactory fopFactory = FopFactory.newInstance(uri, configSource);
      // a user agent is needed for transformation
      FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
  
  
      // Setup output
      OutputStream out = new FileOutputStream("C:\\Temp\\PolishTest.pdf");
  
      try {
          // Construct fop with desired output format
          Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
  
          // Setup XSLT
          TransformerFactory factory = TransformerFactory.newInstance();
          Transformer transformer = factory.newTransformer(new StreamSource(xsltFile));
  
          // Resulting SAX events (the generated FO) must be piped through to FOP
          Result res = new SAXResult(fop.getDefaultHandler());
  
          // Start XSLT transformation and FOP processing
          // That's where the XML is first transformed to XSL-FO and then
          // PDF is created
          transformer.transform(xmlSource, res);
      } finally {
          out.close();
      }
  }
  </code></pre>