Hello,
Failed to embedded font :
public static void xmlToPDF(String xmlFile, String xslFile, OutputStream
out) throws Exception {
File xml = new File(xmlFile);
File xslt = new File(xslFile);
InputStream is =
PDFGenerator.class.getResourceAsStream("myconfig.xml");
org.apache.fop.configuration.Configuration.put("fontBaseDir",
"jar:file:my.jar!/");
Options op = new Options(is);
//Construct driver
Driver driver = new Driver();
//Setup logger
//Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
//driver.setLogger(logger);
//MessageHandler.setScreenLogger(logger);
//Setup Renderer (output format)
driver.setRenderer(Driver.RENDER_PDF);
//Setup output
//OutputStream out = new java.io.FileOutputStream(pdf);
driver.setOutputStream(out);
//Setup XSLT
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new
StreamSource(xslt));
//Setup input for XSLT transformation
Source src = new StreamSource(xml);
//Resulting SAX events (the generated FO) must be piped through to FOP
Result res = new SAXResult(driver.getContentHandler());
//Start XSLT transformation and FOP processing
transformer.transform(src, res);
}
Output -====>
[WARNING] Screen logger not set - Using ConsoleLogger.
[INFO] Using org.apache.xerces.parsers.SAXParser as SAX2 Parser
[INFO] Using org.apache.xerces.parsers.SAXParser as SAX2 Parser
[ERROR] Logger not set
[INFO] building formatting object tree
[INFO] setting up fonts
[INFO] [1]
[INFO] Using org.apache.xerces.parsers.SAXParser as SAX2 Parser
[INFO] Parsing of document complete, stopping renderer
[ERROR] Failed to embed font [10] RS_Song: JAR entry rs_song.ttf not found
in my.jar
Please help.
Best regards,
Eric
----- Original Message -----
From: "Jeremias Maerki" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, June 02, 2003 4:30 PM
Subject: Re: Configuration problem ????
> Here's what I googled out of the net:
> http://javaalmanac.com/egs/java.net/JarUrl.html
>
> So you can do:
> URL mycfg = new URL("jar:file:/C:/Temp/my.jar!/myconfig.xml");
> InputStream in = mycfg.openStream();
> try {
> new Options(in);
> } finally {
> in.close()
> }
>
> In your config file:
> <font metrics-file="jar:file:/C:/Temp/my.jar!/rs_song.xml"
> embed-file="jar:file:/C:/Temp/my.jar!/rs_song.ttf" kerning="yes">
>
> Untested but it should work if you have a recent FOP version (0.20.5rc
> or later).
>
> You can probably also set the "fontBaseDir" value so you don't have to
> change the myconfig.xml file:
> org.apache.fop.configuration.Configuration.put("fontBaseDir",
"jar:file:/C:/Temp/my.jar!/");
>
> or:
> <configuration
> <entry>
> <key>fontBaseDir</key>
> <value>jar:file:/C:/Temp/my.jar!/</value>
> </entry>
>
>
> I hope this helps.
>
> On 02.06.2003 04:46:28 Eric Chow wrote:
> > If I want to use my configuration in embedded program, I can add the
> > following statement in my program for generating PDF.
> >
> > Options op = new Options(new File("myconfig.xml"));
> >
> >
> > It works if the "myconfig.xml" is in the physical folder.
> > and the following is the content of myconfig.xml.
> >
> > <configuration>
> > <fonts>
> > <font metrics-file="rs_song.xml" embed-file="rs_song.ttf"
> > kerning="yes">
> > <font-triplet name="Song" style="normal" weight="normal"/>
> > <font-triplet name="Song" style="normal" weight="bold"/>
> > <font-triplet name="Song" style="italic" weight="normal"/>
> > <font-triplet name="Song" style="italic" weight="bold"/>
> > </font>
> > </fonts>
> > </configuration>
> >
> > Questions and need help:
> >
> > 1. If the "rs_song.xml" and the "rs_song.ttf" are in a JAR file, how can
I
> > do ???
>
>
> Jeremias Maerki
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]