Easily Install Python Poppler with PIP on Linux Ubuntu

Posted April 11, 2024
Easily Install Python Poppler with PIP on Linux Ubuntu

Python uses Poppler a PDF rendering library. This guide teaches you how to install Poppler with PIP on Linux Ubuntu and how to use it to render PDFs.

Along this how to install Poppler with PIP guide:

  • Ensure you have Python installed on your Linux Ubuntu machine.

Related: How to Install Python 3.11 on Ubuntu

  • Have Pip3 installed on Ubuntu

Related: How to APT Install Python pip2|pip3| on Ubuntu

Ready? Now learn how to Easily Install Python Poppler with PIP on Linux Ubuntu

Poppler Linux Ubuntu Requirements

To install Poppler Library, you must install its development files. They will add Poppler support and ensure you have an easy wat to PDF rendering. Use the following command:

sudo apt-get install -y poppler-utils libpoppler-cpp-dev

You will have:

  • poppler-utils to add command-line utilities to work with PDF files.
  • libpoppler-cpp-dev with development files compile Python apps with the Poppler C++ API.

On the same, Poppler uses Python development tools to build Python packages from source. Here you will need to make sure you have Pip3 installed and add python3-dev with the following command:

sudo apt-get install -y python3-dev python3-pip

Verifying Poppler on Ubuntu

At this point, you should have Poppler ready. Confirm that Poppler is installed . To do so, Poppler should be accessible from Python, just checking its version:

pdftoppm -v

You will get an output the version of Poppler installed on your Ubuntu system:

Easily Install Python Poppler with PIP on Linux Ubuntu

Installing Python Bindings with Poppler

Poppler works with Python bindings. In this case you will install libraries that will use Poppler. A good example is. Its bindings for Poppler read, write PDF files or extract PDF data:

pip install pdfrw

Easily Install Python Poppler with PIP on Linux Ubuntu

To make sure this package is good to go, check if pdfrw is installed through Pip:

pip show pdfrw

Easily Install Python Poppler with PIP on Linux Ubuntu

Testing If Poppler Works on Ubuntu

At this point, everything should be ready. You should test if Poppler is working. In my case, I have the following script that should read a PDF file and print the total number of pages in the given PDF file:

import pdfrw

pdf_path = 'test.pdf'
pdf = pdfrw.PdfReader(pdf_path)

num_pages = len(pdf.pages)
print(f'Total number of pages: {num_pages}')

Conclusion

I hope you have been able to easily install Python Poppler bindings on Ubuntu. You can now start working with PDF files in Python within your Ubuntu machine.

Easily Install Python Poppler with PIP on Linux Ubuntu

Written By:

Joseph Chege