Choosing the right font for your documents can be hard if you don't know much about typography and design. But if you have a document with a font that you like, you can easily extract the font name through the command line. All you need is a tool called pdffonts.

In this article, you will learn about pdffonts and how to install it on your computer. You'll also find a detailed guide on how to identify fonts in a PDF document using it.

What Is pdffonts?

Pdffonts is a command-line utility used to extract useful information related to fonts in a PDF file. You can get the following details using pdffonts:

  • Name of the font.
  • Font type.
  • Embed status.
  • Subset information.
  • Encoding details.
  • Font location.
  • The object ID of the font.

Since pdffonts is a part of the Poppler library, you'll have to install the complete utility suite in order to use pdffonts. Poppler is a free library used to render and analyze PDF files efficiently.

To install pdffonts on Debian and Ubuntu:

        sudo apt install poppler-utils
    

On Arch Linux:

        sudo pacman -S poppler
    

On Fedora, CentOS, and other RHEL-based distros:

        sudo dnf install poppler-utils
    

Related: Best Tools to Edit a PDF File Anywhere

How to Analyze Fonts in a PDF

Pdffonts comes with several options to get information about the name and type of the font used in the PDF file.

The basic syntax of the command is:

        pdffonts option pdffile
    

...where option is the flag that invokes the various methods of the command, and pdffile is the absolute or relative path to the PDF file.

When you execute the pdffonts command, it reads the xpdfrc configuration file in the home directory. If the file is not found, it looks for the system-wide configuration file located at /usr/local/etc.

The most simple pdffonts command includes only the file name. For example, to check the fonts used in the dummy lorem-ipsum.pdf file:

        pdffonts lorem-ipsum.pdf
    

Pdffonts will generate an output similar to the one below:

getting font details using pdffont

You can see that the output includes the following information: font name, font type, encoding, embedding details, subset information, Unicode, and the object ID.

Analyze a Range of Pages

The -f and -l flags are useful if you want to extract the font details from some specific page or range of pages. Just specify the page number along with the options as follows:

        pdffonts -f 1 -l 3 lorem-ipsum.pdf
    

The aforementioned command will only provide the font information for pages one to three. To process the first page of a PDF file using pdffonts:

        pdffonts -f 1 -l 1 lorem-ipsum.pdf
    

Learn More: How to Convert Multiple Pages Into a Single PDF

Extract Fonts From a Password-Protected PDF

Using pdffonts, you can even get font information from password-protected PDF files using the -opw and -upw flags. These flags stand for owner password and user password respectively.

Enter the following command to process a PDF file protected using a password. Make sure to replace password with the password of the file.

        pdffonts -opw password lorem-ipsum.pdf
pdffonts -upw password lorem-ipsum.pdf

Pdffonts will automatically bypass the authentication process using the password provided.

Working With PDF Files in Linux

Pdffonts is a great utility if you regularly create and edit PDF files on your Linux system. It provides information related to the font name, font type, and the encoding format for all the fonts used in the file.

If for some reason you are unable to use pdffonts on your computer, try converting the PDF file to images. Then, you can simply extract the font details from the image using a font analyzer web app. Alternatively, if you can't decide on which font to use, you can use the built-in font packs available in Linux PDF editors.