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 Eric Chow <ec...@macaucabletv.com> on 2003/06/02 04:46:28 UTC

Configuration problem ????

Hello,

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


Please help.

Best regards,
Eric




==========================
If you know what you are doing,
it is not called RESEARCH!
==========================


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


Re: Configuration problem ????

Posted by Jeremias Maerki <de...@greenmail.ch>.
What you want to do is a bit tricky. Try the following:

Instead of ...getResourceAsStream("myconfig.xml") try:

URL cfgUrl = ...getResource("myconfig.xml");
String baseURL = cfgURL.toExternalForm();
...then snip the "myconfig.xml" part from the URL and set it as
"fontBaseDir". Maybe that could solve the problem.

If that doesn't work you need to change FOP to do what you want. There's
some code in FOP (see SingleByteFont) that enables you to read the
embeddable font file using getResource. This is triggered by an "embed"
element in the metrics XML (See FontReader). But I'm pretty sure there's
so such mechanism for the metrics file so I think the whole thing is
pretty useless.

If you have to change FOP I suggest you start with the URLBuilder class
which could be a good starting point to resolve URLs. The redesigned FOP
will have better mechanisms to do that but that's future talk.

Good luck!

On 02.06.2003 12:14:39 Eric Chow wrote:
>       InputStream is =
> PDFGenerator.class.getResourceAsStream("myconfig.xml");
> 
>       org.apache.fop.configuration.Configuration.put("fontBaseDir",
> "jar:file:my.jar!/");



Jeremias Maerki


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


Re: Configuration problem ????

Posted by Eric Chow <ec...@macaucabletv.com>.
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" <de...@greenmail.ch>
To: <fo...@xml.apache.org>
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: fop-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: fop-user-help@xml.apache.org
>


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


Re: Configuration problem ????

Posted by Eric Chow <ec...@macaucabletv.com>.
Hello Jerimias,

Thanks for you help.

But if I want to do as following, I think it can't use that solution.

In pdf-util.jar contains the following file structures:

META-INF/
my/
    /test/
          /GenPDF.class
          /myconfig.xml
          /rs_song.xml
          /rs_song.ttf

And I will get the InputStream for myconfig.xml with the following
statement:

InputStream is = GenPDF.class.getResourceAsStream("myconfig.xml");


And, now, I don't know how I can define the "myconfig.xml" to use the
"rs_song.xml" and "rs_song.ttf" ??

Please help me.

Best regards,
Eric




----- Original Message -----
From: "Jeremias Maerki" <de...@greenmail.ch>
To: <fo...@xml.apache.org>
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: fop-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: fop-user-help@xml.apache.org
>


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


Re: Configuration problem ????

Posted by Eric Chow <ec...@macaucabletv.com>.
Hi, Jeremias ,

In fact, I want to put all the config file and TTF files in a JAR file that
will be put into the /WEB-INF/lib if a WAR file or EAR file?


How can FOP get the configurations files and  TTF files ??

Best regards,
Eric



----- Original Message -----
From: "Jeremias Maerki" <de...@greenmail.ch>
To: <fo...@xml.apache.org>
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: fop-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: fop-user-help@xml.apache.org
>


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


Re: Configuration problem ????

Posted by Jeremias Maerki <de...@greenmail.ch>.
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: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org