The font will be looked for in the resources if it's not found in the file system.
> -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On > Behalf Of Jeff Smith > Sent: Monday, April 18, 2005 9:18 PM > To: [email protected] > Subject: [iText-questions] Reading fonts and images as > resources in a WAR > > I would like to place various external font files and images > into a web application. When the application runs, i want to > be able to use the classloader to find the resources (fonts > and images) as opposed to having them placed on a file system > and having to code a pathname. All of the examples I have > found so far hardcode paths. > > If you want your application to be packaged as a true WAR > file though and to have all of the included resources, then > you need to be able to have methods that can take an > InputStream instead of a String. Is this just a deficiency > with iText? Or do I just not know how to do it correctly? > > Take the example of creating a BaseFont. The javadoc says the method: > > BaseFont.createFont(String name, String encoding, boolean embedded) > > Where name is the name of the font, or the location of the > font file on the hard drive. > > Well that is not going to work if that font is packaged up in > a JAR or included into a WAR. > > Images have a similiar problem but at least with those you > could specify a URL and have the server serve up the file. > > Image.getInstance(Url url) > > I have gotten around these, but it has some limitations by > doing the following. > > 1. The web application can not be in a WAR, it has to be an > exploded war deployment. -and- the resources to be read in > can't be put into a jar. I just have them available on the > classpath so the classloader can find them, for example in > WEB-INF/classes. > > 2. In the case of images, I use the classloader and call > getResource() to give me a URL to the file system. I then > can pass in that URL to Image.getInstance(aUrl). > > 3. In the case of fonts, I basically do the same thing but > then use the getFileName() call on URL to strip off the > "file:/" portion and just pass the filename to the font to > BaseFont.createFont(). > > Here is the pseudo code for how I do the fonts: > > String fontFilename = "fonts/Helvetica-Condensed.afm"; > URL aURL = > YellowSystem.class.getClassLoader().getResource(fontFilename); > fontFilename=aURL.getFile(); > BaseFont bf = BaseFont.createFont( fontFilename, etc..............) > > Is there a better way? > > Thanks! > > Jeff Smith > ------------------------------------------------------- This SF.Net email is sponsored by: New Crystal Reports XI. Version 11 adds new functionality designed to reduce time involved in creating, integrating, and deploying reporting solutions. Free runtime info, new features, or free trial, at: http://www.businessobjects.com/devxi/728 _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions
