First of all, thanks to everybody who answered my Mac-related Font problems.
Before preparing Mac OS X fonts for iText usage, download and install fondu
open terminal, start a csh and fire
>>> setenv PATH /usr/local/bin:$PATH setenv MANPATH /usr/local/man <<<
Switch to your personal Fonts directory [e.g. /Users/sp/Library/Fonts ] and fire [fondu asks, before it overwrites any file]
fondu *
After fondu finished its job, iText knows much more fonts. In my case 0 iText-compatible fonts before and 113 after fondu's work.
After fondu did its job, you might wish to evaluate your newly available fonts. Try this iText based source, which prepares a font report PDF:
>>> Document document = new Document( PageSize.A4 );
ByteArrayOutputStream oBuffer = new ByteArrayOutputStream();
try { PdfWriter.getInstance( document, oBuffer );
try { document.open();
// First of all, let's see if iText works at all document.add(new Paragraph("Font report as of " + new Date().toString() ));
// Next, register OS X's well know places for fonts // For non OS X users: These directories exist on each and any OS X box int systemFontNr = FontFactory.registerDirectory( "/Library/Fonts/" ); int systemFontNr2 = FontFactory.registerDirectory( "/System/Library/Fonts/" );
// Next, let iText add our personal account's font directory too // In this case, I register fonts of user 'sp' int userFontNr = FontFactory.registerDirectory( "/Users/sp/Library/Fonts/" );
// Emit details, how much fonts are available System.err.println("Fonts: " + userFontNr + " user, " + systemFontNr + " system, " + systemFontNr2 + " system-core" );
int aFontIndex = 0;
for ( Iterator i = FontFactory.getRegisteredFamilies().iterator(); i.hasNext(); ) {
aFontIndex ++;
String currentFontName = (String) i.next();
try {
Paragraph para = new Paragraph(aFontIndex + " [This is font family " + currentFontName + "] ", FontFactory.getFont(currentFontName, 12)); document.add( para );
} catch ( Exception ex) { System.err.println("getFont failed: " + ex.getMessage() + "[" + currentFontName + "]"); }
}
} catch ( Exception ex) { System.err.println("Document problem 2: " + ex.getMessage()); }
// step 5: we close the document document.close(); <<<
Additionally, if you are using Apple's WebObjects and your are preparing a WOResponse, you might wish to add this:
>>> response.setContent( new NSData( oBuffer.toByteArray() ) ); response.setHeader("application/pdf", "Content-Type"); <<<
|