HI ,

After updating to FOP 2.6, while trying to use Apache FOP to use custom fonts, 
I am getting below error.
org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font "Symbol,normal,700" not found. Substituting with 
"Symbol,normal,400".
org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font "ZapfDingbats,normal,700" not found. Substituting with 
"ZapfDingbats,normal,400".
org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font "Arial,normal,700" not found. Substituting with "any,normal,700".
org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font "GTSuperDisplayLight,normal,700" not found. Substituting with 
"any,normal,700".

Configuration file:

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


        -->

        <directory>C:\Windows\Fonts</directory>

        <directory recursive="true">C:\Windows\Fonts</directory>


        <font kerning="yes" embed-url="C:/Windows/Fonts/Arial.ttf" 
embedding-mode="subset">
               <font-triplet name="Arial" style="normal" weight="normal"/>
        </font>

        <font kerning="yes" embed-url="/System/Library/Fonts/Arial.ttf" 
embedding-mode="subset">
               <font-triplet name="Arial" style="normal" weight="normal"/>
         </font>

        <!-- automatically detect operating system installed fonts -->

        <auto-detect/>

      </fonts>

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

    </renderer>

Java Code :

try
    {
        /*
         * Register Apache FOP to use our fonts. By default we set this config 
file to auto-detect the fonts
         * installed on the user's computer, but custom fonts can be specified. 
Please refer to Apache FOP official
         * documentation to do that.
         */

            fopFactory = FopFactory.newInstance( new File( getConfigFileURI( 
xslFullName ) ).toURI() );

            foUserAgent = fopFactory.newFOUserAgent();
            bufferedOutputStream = new FileOutputStream( pdfFilename );
            bufferedOutputStream = new BufferedOutputStream( 
bufferedOutputStream );
    }
    catch( Exception ex )
    {
        CMEReportPADPDFTranslate.logger.error( "Exception in CreatePDF() -> 
setOutputStream(): " + ex );
    }

    //Setup XML input
    Source src = new StreamSource(xmlFilename);
    Source xsltSrc = new StreamSource(xslFullName);

    try {
        // Construct fop with desired output format
        Fop fop = 
fopFactory.newFop(org.apache.xmlgraphics.util.MimeConstants.MIME_PDF, 
foUserAgent, bufferedOutputStream);

        // Setup XSLT
        // Specify TransformerFactoryImpl to allow CMEReportXalanDebug to work.
        org.apache.xalan.processor.TransformerFactoryImpl transformerFactory
               = new org.apache.xalan.processor.TransformerFactoryImpl();
        Transformer transformer = transformerFactory.newTransformer(xsltSrc);

        // Set the value of a <param> in the stylesheet
        transformer.setParameter("versionParam", "2.0");

        // Resulting SAX events (the generated FO) must be piped through to FOP
        Result res = new SAXResult( fop.getDefaultHandler() );

        // This is for debug settings.
        CMEReportXalanDebug.addDebugMode(registry, transformer);
        CMEReportPADPDFTranslate.logger.debug("Before transform");

        // Start XSLT transformation and FOP processing
        transformer.transform(src, res);

        CMEReportPADPDFTranslate.logger.debug("After transform");
    }

Thanks
Ashish S
[email protected]

Reply via email to