Both are possible: using a config file and in code, although in code is
better if you don't know beforehand which directory it will be, i.e. you
have to determine it at runtime.
I simply couldn't believe that this shouldn't work and I wrote a little
test (see below) where I set the font base directory in code. It worked
with no problems. I used the same config file as shown earlier except
that I removed the "font-base" element.
import java.io.File;
import java.io.OutputStream;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.stream.StreamSource;
import org.apache.fop.Version;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.FormattingResults;
import org.apache.fop.apps.MimeConstants;
public class RelFonts {
public void doit() throws Exception {
FopFactory fopFactory = FopFactory.newInstance();
fopFactory.setUserConfig("C:/Dev/FOP/temp/help/MichaelBurke/test.xconf");
File fopRoot = new File("C:/Dev/FOP/main/xml-fop-temp3");
fopFactory.setFontBaseURL(fopRoot.toURL().toExternalForm() +
"test/resources/fonts/");
FOUserAgent userAgent = fopFactory.newFOUserAgent();
File fo = new File("C:/Dev/FOP/temp/help/MichaelBurke/relfont.fo");
File pdf = new File("D:/out.pdf");
OutputStream out = new java.io.FileOutputStream(pdf);
out = new java.io.BufferedOutputStream(out);
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, userAgent, out);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(); // identity
transformer
Source src = new StreamSource(fo);
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(src, res);
// Result processing
FormattingResults foResults = fop.getResults();
System.out.println("Generated " + foResults.getPageCount() + " pages in
total.");
}
public static void main(String[] args) {
try {
System.out.println("FOP Version: " + Version.getVersion());
RelFonts app = new RelFonts();
app.doit();
} catch (Throwable t) {
t.printStackTrace();
}
}
}
On 14.01.2008 19:24:01 Michael Burke wrote:
> I tried that. I can set the font base in code, but
> the fonts will not embed. The only way I've got them
> to embed is if I point to them in my font config file
> by pointing to them using an absolute path
> "file://c:/..", which I can't do, due to the fact that
> I can't change the path for every server. If you want
> to embed the fonts does it have to be done using the
> config file or is it possible to do it in code.
> Thanks again for your help.
>
> Thanks,
> Mike
>
> --- Jeremias Maerki <[EMAIL PROTECTED]> wrote:
>
> > Ah, you wanted to use a relative path on the font
> > base setting, not on
> > the individual paths. Shouldn't really be a problem
> > as long as you know
> > where your "current directory" is (new
> > File(".").getCanonicalPath()).
> > But if you know the absolute base directory, it's
> > better set that.
> >
> > Something like...
> >
> > FopFactory fopFactory = ....
> >
> fopFactory.setFontBaseURL("file:///C:/something/fonts");
> >
> > ...should do the trick.
> >
> > HTH
> >
> > On 14.01.2008 18:34:05 Michael Burke wrote:
> > > Hi Jeremias,
> > >
> > > Thanks for responding so quickly. Is it possible
> > to
> > > set the font base path relatively? Reason being,
> > is
> > > this will be moved to many development, QA and
> > > Production machines so we won't alway know the
> > path
> > > absolute path. If we can't do this in the config
> > file.
> > > Is it possible to do it in code? I've set the
> > > FOPFactory.setFontBasePath to the path of where
> > our
> > > font and font metrics reside. However it does not
> > > embed the fonts. Any help would be greatly
> > > appreciated.
> > >
> > > Thanks,
> > > Michael Burke
> > > --- Jeremias Maerki <[EMAIL PROTECTED]>
> > wrote:
> > >
> > > > Here's a minimal config file demonstrating
> > relative
> > > > fonts. You will
> > > > simply need to adjust the font-base setting
> > > > (glb12.ttf is a font that's
> > > > found in the FOP source distribution).
> > > >
> > > > test.xconf:
> > > >
> > > > <?xml version="1.0"?>
> > > > <fop version="1.0">
> > > >
> > > >
> > >
> >
> <font-base>C:\Dev\FOP\main\trunk-clean\test\resources\fonts</font-base>
> > > > <renderers>
> > > > <renderer mime="application/pdf">
> > > > <fonts>
> > > > <font embed-url="glb12.ttf">
> > > > <font-triplet name="Gladiator"
> > > > style="normal" weight="normal"/>
> > > > <font-triplet name="Gladiator"
> > > > style="normal" weight="bold"/>
> > > > </font>
> > > > </fonts>
> > > > </renderer>
> > > > </renderers>
> > > > </fop>
> > > >
> > > > A minimal FO file (relfont.fo):
> > > >
> > > > <?xml version="1.0" ?>
> > > > <fo:root
> > > > xmlns:fo="http://www.w3.org/1999/XSL/Format">
> > > > <fo:layout-master-set>
> > > > <fo:simple-page-master master-name="first"
> > > > page-height="29.7cm" page-width="21cm"
> > > > margin="2cm">
> > > > <fo:region-body/>
> > > > </fo:simple-page-master>
> > > > </fo:layout-master-set>
> > > >
> > > > <fo:page-sequence master-reference="first">
> > > > <fo:flow flow-name="xsl-region-body">
> > > > <fo:block font-family="Gladiator"
> > > > font-size="14pt">The quick brown fox jumps over
> > the
> > > > lazy dog. (using Gladiator font)</fo:block>
> > > > </fo:flow>
> > > > </fo:page-sequence>
> > > > </fo:root>
> > > >
> > > > Command-line: fop -c test.xconf -fo relfont.fo
> > -pdf
> > > > out.pdf
> > > >
> > > > Tested with FOP 0.94. Works like a charm. Good
> > luck!
> > > >
> > > > On 14.01.2008 15:32:49 mpbjr30 wrote:
> > > > >
> > > > > Hi Everyone,
> > > > >
> > > > > I've just upgraded to 0.94 version of FOP. Is
> > > > there any example of
> > > > > embedding fonts in the config file using
> > relative
> > > > paths? I've tried
> > > > > everything and I can't see to get it to work.
> > Any
> > > > help would be greatly
> > > > > appreciated .
> > > > >
> > > > > Thanks,
> > > > > Mike
> > > > > --
> > > > > View this message in context:
> > > >
> > >
> >
> http://www.nabble.com/Embedded-Fonts-Relative-Path-0.94-tp14802580p14802580.html
> > > > > Sent from the FOP - Users mailing list archive
> > at
> > > > Nabble.com.
> > > >
> > > >
> > > > Jeremias Maerki
> > > >
> > > >
> > > >
> > >
> >
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail:
> > > > [EMAIL PROTECTED]
> > > > For additional commands, e-mail:
> > > > [EMAIL PROTECTED]
> > > >
> > > >
> > >
> > >
> > >
> > >
> >
> ____________________________________________________________________________________
> > > Never miss a thing. Make Yahoo your home page.
> > > http://www.yahoo.com/r/hs
> > >
> > >
> >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > [EMAIL PROTECTED]
> > > For additional commands, e-mail:
> > [EMAIL PROTECTED]
> >
> >
> >
> >
> > Jeremias Maerki
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > [EMAIL PROTECTED]
> > For additional commands, e-mail:
> > [EMAIL PROTECTED]
> >
> >
>
>
>
>
> ____________________________________________________________________________________
> Looking for last minute shopping deals?
> Find them fast with Yahoo! Search.
> http://tools.search.yahoo.com/newsearch/category.php?category=shopping
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
Jeremias Maerki
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]