At 07:39 AM 8/2/2004, Joris Verschoor wrote:
>Hi,
>
>I"d like to know how I can reuse a font that is used in a template pdf >(after adding the PdfImportedPage)
>


I am having the same problem. I want to add text to an existing PDF and use the existing fonts in the PDF. I found solution at :
http://sourceforge.net/mailarchive/message.php?msg_id=9125204


but I can not get the code to compile. The line

     result = BaseFont.createFont(iRef);

Returns an error of com/gentiva/PDF.java [114:1] cannot resolve symbol
symbol : method createFont (com.lowagie.text.pdf.PRIndirectReference)
location: class com.lowagie.text.pdf.BaseFont
{ result = BaseFont.createFont(iRef);}


I tried updating to the newest version of iText (1.02b) it did not help. Sure enough when I checked the API docs for iText it did not list a .createFont() method that excepted a PRIndirectReference object. i.e. there was no .createFont(PRIndirectReference object) method. I am sure I am missing something simple. Any pointers on what I might be missing would be great. Was this example based on another library other than iText? I included the code I am using below.


<Code>
static BaseFont getFont (String fontName, PdfReader reader, int pageNum){
BaseFont result = null;
PdfDictionary pages = (PdfDictionary)
PdfReader.getPdfObject(reader.getCatalog().get(PdfName.PAGES));
PdfArray kids = (PdfArray)
PdfReader.getPdfObject(pages.get(PdfName.KIDS));
PdfDictionary pageDictionary = (PdfDictionary)
PdfReader.getPdfObject((PdfObject) kids.getArrayList()
.get(pageNum - 1));
PdfDictionary pageResourcesDict = (PdfDictionary)
PdfReader.getPdfObject(pageDictionary.get(PdfName.RESOURCES));
PdfDictionary pageFontsDict = (PdfDictionary)
PdfReader.getPdfObject(pageResourcesDict.get(PdfName.FONT));
if (pageFontsDict != null) {
Set pageFontNames = pageFontsDict.getKeys();
for (Iterator iter = pageFontNames.iterator(); iter.hasNext();) {
PdfName internalFontName = (PdfName) iter.next();
PdfDictionary fontDict = (PdfDictionary)
PdfReader.getPdfObject(pageFontsDict.get(internalFontName));
PdfName baseFontName = (PdfName)
PdfReader.getPdfObject(fontDict.get(PdfName.BASEFONT));


// compare names, ignoring the initial '/ ' in the baseFontName
if (fontName.regionMatches(0, baseFontName.toString(), 1,
fontName.length())){
PRIndirectReference iRef = (PRIndirectReference)
pageFontsDict.get(internalFontName);
if (iRef != null)
{ result = BaseFont.createFont(iRef); }
}
}
}
return result;
}
</Code>




begin:vcard
fn:Brian Cook
n:Cook;Brian
org:Print Time Inc.
email;internet:[EMAIL PROTECTED]
title:Digital Services Analyst
tel;work:913.345.8900
x-mozilla-html:FALSE
url:http://www.printtimepostcards.com
version:2.1
end:vcard

Reply via email to