Created
March 19, 2015 19:37
-
-
Save kBashar/0dfe6adf7586b7352d72 to your computer and use it in GitHub Desktop.
A font encoding finder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.kbashar.pdfboxtry; | |
import org.apache.pdfbox.encoding.Encoding; | |
import org.apache.pdfbox.pdmodel.PDDocument; | |
import org.apache.pdfbox.pdmodel.PDPage; | |
import org.apache.pdfbox.pdmodel.PDResources; | |
import org.apache.pdfbox.pdmodel.font.PDFont; | |
import org.apache.pdfbox.pdmodel.font.PDTrueTypeFont; | |
import org.apache.pdfbox.pdmodel.font.PDType0Font; | |
import java.io.IOException; | |
import java.util.Iterator; | |
import java.util.Map; | |
import java.util.Set; | |
/** | |
* Created by kbashar on 3/19/15. | |
*/ | |
public class CharacterCodeFinder { | |
public static void main(String[] args) throws IOException { | |
PDDocument docu = PDDocument.load("Google+.pdf"); | |
PDResources resources =((PDPage) docu.getDocumentCatalog().getAllPages().get(0)).getResources(); | |
Iterator<Map.Entry<String, PDFont>> fonts = resources.getFonts().entrySet().iterator(); | |
PDFont font = fonts.next().getValue(); | |
if (font!=null) { | |
Encoding encoding = font.getFontEncoding(); | |
if (encoding==null) | |
{ | |
System.out.println("encoding is null"); | |
return; | |
} | |
System.out.println(encoding.getClass().getName()); | |
System.out.println(encoding.getCode("G")); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment