Here's the program to read fonts:
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
import java.util.*;
public class DumpFontNames {
static PdfReader reader;
static TreeMap fontMap = new TreeMap();
static final PdfName F1 = new PdfName("FontFile");
static final PdfName F2 = new PdfName("FontFile2");
static final PdfName F3 = new PdfName("FontFile3");
public static void processResource(PdfDictionary resource) throws
Exception {
if (resource == null)
return;
PdfDictionary xos =
(PdfDictionary)reader.getPdfObject(resource.get(PdfName.XOBJECT));
if (xos != null) {
for (Iterator it = xos.getKeys().iterator(); it.hasNext();) {
PdfDictionary xo =
(PdfDictionary)reader.getPdfObject(xos.get((PdfName)it.next()));
processResource((PdfDictionary)reader.getPdfObject(xo.get(PdfName.RESOURCES)
));
}
}
PdfDictionary fonts =
(PdfDictionary)reader.getPdfObject(resource.get(PdfName.FONT));
if (fonts == null)
return;
for (Iterator it = fonts.getKeys().iterator(); it.hasNext();) {
PdfDictionary font =
(PdfDictionary)reader.getPdfObject(fonts.get((PdfName)it.next()));
String name =
((PdfName)reader.getPdfObject(font.get(PdfName.BASEFONT))).toString();
if (name.length() > 8 && name.charAt(7) == '+') {
name = name.substring(8) + " subset";
}
else {
name = name.substring(1);
PdfDictionary desc =
(PdfDictionary)reader.getPdfObject(font.get(PdfName.FONTDESCRIPTOR));
if (desc != null) {
if (desc.get(F1) != null || desc.get(F2) != null ||
desc.get(F3) != null)
name += " embedded";
}
else
name += " nofontdescriptor";
}
fontMap.put(name, null);
}
}
public static void main(String[] args) {
try {
reader = new PdfReader(args[0]);
for (int k = 1; k <= reader.getNumberOfPages(); ++k) {
PdfDictionary page = reader.getPageN(k);
processResource((PdfDictionary)reader.getPdfObject(page.get(PdfName.RESOURCE
S)));
}
for (Iterator it = fontMap.keySet().iterator(); it.hasNext();)
System.out.println((String)it.next());
}
catch(Exception e) {
e.printStackTrace();
}
}
}
Best Regards,
Paulo Soares
----- Original Message -----
From: "Paulo Soares" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Monday, February 10, 2003 18:26
Subject: RE: [iText-questions] Embedded fonts
> I find strange that the font doesn't have a font descriptor. That's
> required
> even if the font is not embedded, except for built-in ones.
> I'll make you a program tomorrow to check the embedded and subset status
> of
> the fonts, it's easier than all this circular talk.
>
> Best Regards,
> Paulo Soares
>
> > -----Original Message-----
> > From: David Nielsen [SMTP:[EMAIL PROTECTED]]
> > Sent: Monday, February 10, 2003 18:15
> > To: 'Paulo Soares'; [EMAIL PROTECTED]
> > Subject: RE: [iText-questions] Embedded fonts
> >
> > But how can i know that the fonts doesnt fail ?
> >
> > i know that the Dax-ExtraBoldItalic font fails in acrobat.
> > saying "Unable to find or create font 'Dax-ExtraBoldItalic'. Some
> > characters
> > may not display or print correctly."
> > And the "Document" info says:
> >
> > Type: Type1,
> > Encoding: Custum,
> > Used font: Font not available.
> >
> >
> > I added this below, and cannot se anything wrong with the
> > Dax-ExtraBoldItalic font.
> >
> > while(fontIterator.hasNext()) {
> > PdfDictionary font =
> >
> (PdfDictionary)reader.getPdfObject(fonts.get((PdfName)fontIterator.next(
> ))
> > );
> > Set descriptKeys = font.getKeys();
> > Iterator desripItegator = descriptKeys.iterator();
> > while(desripItegator.hasNext()) {
> > try{
> > PdfName next = (PdfName)desripItegator.next();
> > System.out.print(next.toString() + " : ");
> > System.out.println(reader.getPdfObject(font.get(next)));
> > } catch(NullPointerException e) {
> > System.out.println("NullPointerException");
> > }
> > }
> > System.out.println("-------");
> > }
> >
> >
> > and the output:
> >
> > -------
> > /BaseFont : /Dax-BoldItalic
> > /FirstChar : 1
> > /Name : /F18
> > /FontDescriptor : NullPointerException
> > /Encoding : NullPointerException
> > /Subtype : /Type1
> > /LastChar : 255
> > /Type : /Font
> > /Widths : NullPointerException
> > -------
> > /BaseFont : /Dax-ExtraBoldItalic
> > /FirstChar : 1
> > /Name : /F17
> > /FontDescriptor : NullPointerException
> > /Encoding : NullPointerException
> > /Subtype : /Type1
> > /LastChar : 255
> > /Type : /Font
> > /Widths : NullPointerException
> > -------
> >
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED]]On Behalf Of Paulo
> > Soares
> > Sent: 10. februar 2003 17:34
> > To: '[EMAIL PROTECTED]'; [EMAIL PROTECTED]
> > Subject: RE: [iText-questions] Embedded fonts
> >
> >
> >
> >
> > > -----Original Message-----
> > > From: David Nielsen [SMTP:[EMAIL PROTECTED]]
> > > Sent: Monday, February 10, 2003 16:16
> > > To: [EMAIL PROTECTED]
> > > Subject: RE: [iText-questions] Embedded fonts
> > >
> > > For what i can read in the PDF Reference (Third edition), the font
> > > desriptor
> > > is a dictionary.
> > > But when i try getting the fontdesriptor with:
> > >
> > > PdfDictionary dict = reader.getPageN(i);
> > > PdfDictionary pageResources =
> > > (PdfDictionary)reader.getPdfObject(dict.get(PdfName.RESOURCES));
> > > PdfDictionary fonts =
> > > (PdfDictionary)reader.getPdfObject(pageResources.get(PdfName.FONT));
> > > PdfDictionary fontsdescrip =
> > >
> (PdfDictionary)reader.getPdfObject(fonts.get(PdfName.FONTDESCRIPTOR));
> > >
> > > The last line retuns null.
> > >
> > 'fonts' is a dictionary of names and fonts. The font descriptor
> is
> > not here yet.
> >
> > > I tryed with:
> > >
> > > Set fontkeys = fonts.getKeys();
> > > Iterator fontIterator = fontkeys.iterator();
> > > while(fontIterator.hasNext()) {
> > > PdfDictionary font =
> > >
> >
> (PdfDictionary)reader.getPdfObject(fonts.get((PdfName)fontIterator.next(
> ))
> > > );
> > >
> > This works. Now you have the font and can get the descriptor.
> >
> > > System.out.println(font.isFont());
> > >
> > This will not workhere, only when creating content. What you
> have is
> > a generic dictionary that happens to be a font.
> >
> > > }
> > >
> > > output:
> > > java.lang.NullPointerException
> > > at com.lowagie.text.pdf.PdfDictionary.isFont(Unknown
> Source)
> > > at mypackage5.FontsItext.<init>(FontsItext.java:26)
> > > at mypackage5.FontsItext.main(FontsItext.java:37)
> > >
> > > should'nt it be a Font ?
> > >
> > > and with:
> > > Set fontkeys = fonts.getKeys();
> > > Iterator fontIterator = fontkeys.iterator();
> > > while(fontIterator.hasNext()) {
> > > PdfDictionary font =
> > > (PdfDictionary)fonts.get((PdfName)fontIterator.next()); // Here
> > > System.out.println(font.isFont());
> > > }
> > > output:
> > > java.lang.ClassCastException:
> > > com.lowagie.text.pdf.PRIndirectReference
> > > at mypackage5.FontsItext.<init>(FontsItext.java:25)
> > > at mypackage5.FontsItext.main(FontsItext.java:37)
> > >
> > Use the other form. the work is done.
> >
> > Best Regards,
> > Paulo Soares
> >
> > > The botton line i have a PDF with a font in it that isnt embedded.
> and
> > > Acrobat fails when i open the file,
> > > replacing the text with ........
> > > i just need to know which fonts are used in the document and are
> they
> > > embedded or available, so i can tell before opening the file in
> acrobat
> > if
> > > there are missing fonts.
> > >
> > > Regards,
> > > David
> > >
> > >
> > >
> > >
> > > -----Original Message-----
> > > From: Paulo Soares [mailto:[EMAIL PROTECTED]]
> > > Sent: 6. februar 2003 16:14
> > > To: '[EMAIL PROTECTED]'
> > > Subject: RE: [iText-questions] Embedded fonts
> > >
> > >
> > > Do:
> > >
> > > PdfDictionary dict = reader.getPageN(i);
> > > PdfDictionary pageResources =
> > > (PdfDictionary)reader.getPdfObject(dict.get(PdfName.RESOURCES));
> > > PdfDictionary fonts =
> > > (PdfDictionary)reader.getPdfObject(pageResources.get(PdfName.FONT));
> > >
> > > The values in fonts are the actual fonts. Get them with
> > > reader.getPdfObject() because most of them are indirect references.
> > >
> > > Best Regards,
> > > Paulo Soares
> > >
> > > > -----Original Message-----
> > > > From: Archangel [SMTP:[EMAIL PROTECTED]]
> > > > Sent: Thursday, February 06, 2003 13:53
> > > > To: 'Paulo Soares'
> > > > Subject: RE: [iText-questions] Embedded fonts
> > > >
> > > > You say go to the fonts resources ?
> > > > i can do the:
> > > > PdfDictionary dict = reader.getPageN(i);
> > > > PdfObject pageResorces =
> > > (PdfObject)dict.get(PdfName.RESOURCES);
> > > >
> > > > but what type is the pageResorces then, its not a PdfDictionary,
> is it
> > a
> > > > PdfResources, if so how do i get anything out of this when its
> > Private.
> > > >
> > > > its not the pdf specs i dont undestand, i just cant se how the api
> is
> > > > doing
> > > > it.
> > > >
> > > > i cant find any examples in any posts in mailarchive or in the
> > Tutorial.
> > > > You have any, im growing hair.
> > > >
> > > > Regards,
> > > > David
> > > > sorry.. i see i have used a wrong email address.
> > > >
> > > > -----Original Message-----
> > > > From: Paulo Soares [mailto:[EMAIL PROTECTED]]
> > > > Sent: 6. februar 2003 12:19
> > > > To: '[EMAIL PROTECTED]'
> > > > Subject: RE: [iText-questions] Embedded fonts
> > > >
> > > >
> > > > Page->Resources->Font
> > > >
> > > > > -----Original Message-----
> > > > > From: Archangel [SMTP:[EMAIL PROTECTED]]
> > > > > Sent: Thursday, February 06, 2003 11:13
> > > > > To: 'Paulo Soares'
> > > > > Subject: RE: [iText-questions] Embedded fonts
> > > > >
> > > > > Yes..
> > > > > But what i can read is that the FONT name is a Dictionary
> Object.
> > and
> > > > not
> > > > > a
> > > > > Null Object,
> > > > > so shouldnt the PdfObject font = dict.get(PdfName.FONT); return
> a
> > FONT
> > > > > Dictionary, it returns null, i cant see or undestand the why
> this
> > > > shouldnt
> > > > > be right
> > > > >
> > > > > Best Regards,
> > > > > David Nielsen
> > > > >
> > > > > -----Original Message-----
> > > > > From: Paulo Soares [mailto:[EMAIL PROTECTED]]
> > > > > Sent: 6. februar 2003 11:42
> > > > > To: '[EMAIL PROTECTED]'
> > > > > Subject: RE: [iText-questions] Embedded fonts
> > > > >
> > > > >
> > > > > Do you have the pdf reference (it's downloadable from
> > > > partners.adobe.com)?
> > > > >
> > > > > Best Regards,
> > > > > Paulo Soares
> > > > >
> > > > > > -----Original Message-----
> > > > > > From: Archangel [SMTP:[EMAIL PROTECTED]]
> > > > > > Sent: Thursday, February 06, 2003 10:43
> > > > > > To: 'Paulo Soares'
> > > > > > Subject: RE: [iText-questions] Embedded fonts
> > > > > >
> > > > > > I cant se so get this correct..
> > > > > > why does the font.isDictionary() throw a NullPointerException.
> > > > > > isnt it a PdfDictionary. or isnt it the way to go?
> > > > > >
> > > > > >
> > > > > > try {
> > > > > > PdfReader reader = new PdfReader("M2003-02-05_240.pdf");
> > > > > > for(int i = 1; i <= reader.getNumberOfPages(); i++) {
> > > > > > PdfDictionary dict = reader.getPageN(i);
> > > > > > PdfObject font = dict.get(PdfName.FONT);
> > > > > > System.out.println(font.isDictionary());
> > > > > > }
> > > > > > } catch(Exception e) {
> > > > > > System.out.println("Exception caught !");
> > > > > > e.printStackTrace();
> > > > > > }
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > -----Original Message-----
> > > > > > From: [EMAIL PROTECTED]
> > > > > > [mailto:[EMAIL PROTECTED]]On Behalf
> Of
> > > Paulo
> > > > > > Soares
> > > > > > Sent: 5. februar 2003 20:39
> > > > > > To: '[EMAIL PROTECTED]';
> > [EMAIL PROTECTED]
> > > > > > Subject: RE: [iText-questions] Embedded fonts
> > > > > >
> > > > > >
> > > > > > It's quite easy if you know the pdf specification. Use
> > > > > > PdfReader.getPageN()
> > > > > > to get the page dictionary, go to the font resources and get
> the
> > > > names.
> > > > > > You'll have information in the font descriptor if the font is
> > > > embedded.
> > > > > >
> > > > > > Best Regards,
> > > > > > Paulo Soares
> > > > > >
> > > > > > > -----Original Message-----
> > > > > > > From: Archangel [SMTP:[EMAIL PROTECTED]]
> > > > > > > Sent: Wednesday, February 05, 2003 19:29
> > > > > > > To: [EMAIL PROTECTED]
> > > > > > > Subject: [iText-questions] Embedded fonts
> > > > > > >
> > > > > > > Hi There...
> > > > > > > Is it possible somehow to get a list of fonts in an existing
> PDF
> > > og
> > > > > more
> > > > > > > relevant the fonts that are used but not embedded in the
> file.
> > > > > > >
> > > > > > >
> > > > > > > David Nielsen.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > -------------------------------------------------------
> > > > > > > This SF.NET email is sponsored by:
> > > > > > > SourceForge Enterprise Edition + IBM + LinuxWorld =
> Something 2
> > > See!
> > > > > > > http://www.vasoftware.com
> > > > > > > _______________________________________________
> > > > > > > iText-questions mailing list
> > > > > > > [EMAIL PROTECTED]
> > > > > > > https://lists.sourceforge.net/lists/listinfo/itext-questions
> > > > > >
> > > > > >
> > > > > > -------------------------------------------------------
> > > > > > This SF.NET email is sponsored by:
> > > > > > SourceForge Enterprise Edition + IBM + LinuxWorld = Something
> 2
> > See!
> > > > > > http://www.vasoftware.com
> > > > > > _______________________________________________
> > > > > > iText-questions mailing list
> > > > > > [EMAIL PROTECTED]
> > > > > > https://lists.sourceforge.net/lists/listinfo/itext-questions
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> > >
> > >
> > >
> > > -------------------------------------------------------
> > > This SF.NET email is sponsored by:
> > > SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
> > > http://www.vasoftware.com
> > > _______________________________________________
> > > iText-questions mailing list
> > > [EMAIL PROTECTED]
> > > https://lists.sourceforge.net/lists/listinfo/itext-questions
> >
> >
> > -------------------------------------------------------
> > This SF.NET email is sponsored by:
> > SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
> > http://www.vasoftware.com
> > _______________________________________________
> > iText-questions mailing list
> > [EMAIL PROTECTED]
> > https://lists.sourceforge.net/lists/listinfo/itext-questions
> >
>
>
> -------------------------------------------------------
> This SF.NET email is sponsored by:
> SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
> http://www.vasoftware.com
> _______________________________________________
> iText-questions mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
>
-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions