How to determine the font family and font size of words in a pdf document?

How to determine the font family and font size of words in a pdf document? We are actually trying to create a pdf document programmatically using iText, but we don’t know how to find out the font family and font size of the original document to be generated. document properties do not seem to contain this information.

+5
source share
3 answers

Fonts are stored in a directory (I suppose, in a subdirectory of type font). If you open the pdf file as a text file, you can find entries in the directory (they start and end with "<" and "β†’" respectively.

pdf :

<</Type/Font/BaseFont/Helvetica-Bold/Subtype/Type1/Encoding/WinAnsiEncoding>>

( PDF , '/Type/Font' .

, , , , .

identifont , ( ).

: . , "ressource", "font". dictionnary, .

 PdfReader reader = new PdfReader(
   new FileInputStream(new File("file.pdf")));
 int nbmax = reader.getNumberOfPages();
 System.out.println("nb pages " + nbmax);

 for (int i = 1; i <= nbmax; i++) {
    System.out.println("----------------------------------------");
    System.out.println("Page " + i);
    PdfDictionary dico = reader.getPageN(i);
    PdfDictionary ressource = dico.getAsDict(PdfName.RESOURCES);
    PdfDictionary font = ressource.getAsDict(PdfName.FONT);
    // we got the page fonts
    Set keys = font.getKeys();
    Iterator it = keys.iterator();
    while (it.hasNext()) {
       PdfName name = (PdfName) it.next();
       PdfDictionary fontdict = font.getAsDict(name);
       PdfObject typeFont = fontdict.getDirectObject(PdfName.SUBTYPE);
       PdfObject baseFont = fontdict.getDirectObject(PdfName.BASEFONT);               
       System.out.println(baseFont.toString());              
    }
 }

( "" ) . PDF . - . , , 12. (, ).

BT 
/F13  12  Tf 
288  720  Td 
the text to find  Tj 
ET
+5

PDF, , Adobe Illustrator, , , , .

, -, PATRY .

.

+1

All Articles