You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Jonny Pony <jo...@hotmail.com> on 2003/12/12 16:25:52 UTC

Integrate fonts in java-application?

Hi,

I want to integrate some extra fonts into my java-application that creates 
pdf from xml/xsl-Files.

My Java so far (Creates a pdf from a StreamSource):
________________________________________________________
//Java
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;

//JAXP
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerException;
import javax.xml.transform.Source;
import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.sax.SAXResult;

//FOP
import org.apache.fop.apps.Driver;
import org.apache.fop.apps.FOPException;

public class CreatePDFFile {
  public void convertXML2PDF(StreamSource xml, String xslFile, String 
filename) throws
      IOException,
      FOPException, TransformerException {

    Driver driver = new Driver();
    driver.setRenderer(Driver.RENDER_PDF);

    OutputStream out = new java.io.FileOutputStream(filename);
    out = new java.io.BufferedOutputStream(out);
    try {
      driver.setOutputStream(out);

      // Setup XSLT
      TransformerFactory factory = TransformerFactory.newInstance();
      Transformer transformer = factory.newTransformer(new 
javax.xml.transform.
          stream.StreamSource(xslFile));

      Result res = new SAXResult(driver.getContentHandler());

      transformer.transform(xml, res);

    }
    catch (Exception e) {
      e.printStackTrace();
    }
    finally {
      out.close();
    }
  }
}
________________________________________________________

Since I want some extra fonts in my pdf, I created some TrueType Font 
Metrics, with something like this code:
________________________________________________
java -cp build\fop.jar;lib\avalon-framework.jar;lib\xml-apis.jar;
         lib\xercesImpl.jar;lib\xalan.jar
           org.apache.fop.fonts.apps.TTFReader
             C:\myfonts\cmr10.ttf ttfcm.xml
_______________________________________________


I created a config-File "userconfig" with something ike this:
__________________________
...
<fonts>
<font metrics-file="arial.xml" kerning="yes" 
embed-file="file:///C:/Windows/Fonts/arial.ttf">
                 <font-triplet name="Arial" style="normal" weight="normal"/>
                <font-triplet name="ArialMT" style="normal" 
weight="normal"/>
</font>
<font metrics-file="arial-black.xml" kerning="yes" 
embed-file="file:///C:/Windows/Fonts/AriBlk.ttf">
	<font-triplet name="Arial" style="normal" weight="bold"/>
	<font-triplet name="ArialBl" style="normal" weight="normal"/>
</font>
....
___________________________


Running fop from commandline works.

But I want this to work in an java application. Like in my java-code up 
there.
So how can I work with the config-file and font-XMLs and *.TTFs in my code?
(I don't want to have absolute paths, like 
"embed-file="file:///C:/Windows/Fonts/AriBlk.ttf" in my code)
Has anyone got sample code for this? Is there a tutorial?

Thanks
Jonny

_________________________________________________________________
FreeSMS abräumen mit dem MSN Messenger - der Countdown läuft! 
http://messenger-mania.msn.de Jetzt mitmachen und gewinnen!


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org


Re: Integrate fonts in java-application?

Posted by "J.Pietschmann" <j3...@yahoo.de>.
Jonny Pony wrote:
> So how can I work with the config-file and font-XMLs and *.TTFs in my code?

See
  http://xml.apache.org/fop/embedding.html#config-external

> (I don't want to have absolute paths, like 
> "embed-file="file:///C:/Windows/Fonts/AriBlk.ttf" in my code)
> Has anyone got sample code for this? Is there a tutorial?

Check the font base URL. See
  http://xml.apache.org/fop/fonts.html
near the end.

J.Pietschmann


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org