voyent
Messages posted by: dwhytock  XML
Profile for dwhytock -> Messages posted by dwhytock [3]
Author Message
I produced a test file. Using the code in my previous post, the results were:

Number of pages: 1
PageTree: number of pages: 1
Page 1 came back null.
Okay, thanks, that did help with seeing the fonts in that particular file. (It comes up as Calibri.) Trying it with three other files (which unfortunately I'm not allowed to show you) which were produced with iText comes up with two null font lists and one page 1 not found. The last one was a PDF containing nothing but an image, but the other two have fonts in them that I can see in Adobe Reader using right-click->DocumentProperties->Fonts.

BTW, the link I wound up using was

http://sventon.icesoft.org/svn/repos/repo/show/icepdf/trunk/icepdf/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/fonts/FindFontsTask.java?revision=HEAD

Code:

pdf.setFile(filePath);

Library library = pdf.getCatalog().getLibrary();
System.out.println("Number of pages: " + pdf.getNumberOfPages());
PageTree pagetree = pdf.getPageTree();
System.out.println("PageTree: number of pages: " + pagetree.getNumberOfPages());
Page page = pagetree.getPage(1);
if (page == null)
{
System.out.println("Page 1 came back null.");
return false;
}

page.initPageResources();
Resources resources = page.getResources();
if (resources == null)
{
System.out.println("Resources came back null.");
return false;
}
HashMap fonts = resources.getFonts();
if (fonts != null && fonts.size() > 0)
{
System.out.println("number of fonts: " + fonts.size());
Set fontKeys = fonts.keySet();
for (Object key: fontKeys)
{
System.out.println("key to string:" + key.toString());
Object fontObject = fonts.get(key);
System.out.println("font object to string: " + fontObject.toString());
if (fontObject instanceof Reference)
{
Reference fontReference = (Reference) fontObject;
fontObject = library.getObject(fontReference);
if (fontObject instanceof org.icepdf.core.pobjects.fonts.Font)
{
Font font = (Font) fontObject;
font.init();
System.out.println("font name: " + font.getName());
System.out.println("base font name: " + font.getBaseFont());
}
}
}
return false;
}
else
System.out.println("Fonts are null.");

Output:

Number of pages: 7
PageTree: number of pages: 7
Fonts are null.
Hi...I'm having font-loading issues, so I'm trying to find out what fonts are included in PDFs my Java program is sending to the printer. My understanding is that this would be Document.getPageTree().getResources.getFonts(), but the getResources() call is returning null.

Code:

Document pdf = new Document();

Exception exception = null;
try {
// load the file specified by the command line
pdf.setFile(filePath);

System.out.println("Number of pages: " + pdf.getNumberOfPages());
PageTree pagetree = pdf.getPageTree();
System.out.println("PageTree: number of pages: " + pagetree.getNumberOfPages());
Page page = pagetree.getPage(1);
if (page == null)
{
System.out.println("Page 1 came back null.");
return false;
}

Resources resources = pagetree.getResources();
if (resources == null)
{
System.out.println("Resources came back null.");
return false;
}
HashMap fonts = resources.getFonts();

Output:

Number of pages: 3
PageTree: number of pages: 3
Resources came back null.

I also tried pagetree.getPage(1).getResources, but that also came back null.

File attached.

Thanks...

Don
 
Profile for dwhytock -> Messages posted by dwhytock [3]
Go to:   
Powered by JForum 2.1.7ice © JForum Team