# Convert PDF Pages To Text With Python

**URL:** <https://onehack.st/t/convert-pdf-pages-to-text-with-python/56233>\
**Category:** Tools & Scripts\
**Tags:** ebook, tips-tricks\
**Created:** [September 8, 2019, 9:42pm UTC](https://onehack.st/t/convert-pdf-pages-to-text-with-python/56233 "2019-09-08T21:42:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheJoker](https://onehack.st/user_avatar/onehack.st/thejoker/32/22660_2.png) [@TheJoker](https://onehack.st/u/TheJoker)\
**Post date:** [September 8, 2019, 9:42pm UTC](https://onehack.st/t/convert-pdf-pages-to-text-with-python/56233/1 "2019-09-08T21:42:14Z")

</div>

# CONVERT PDF PAGES TO TEXT WITH PYTHON

 ![convert-scanned-pdf-to-text](https://onehack.st/uploads/default/original/3X/e/a/ea3d4f086497a5bffa778ad29720154e57294e27.jpeg)

A simple guide to text from PDF. This is an extension of the [Convert PDF pages to JPEG with python](https://simply-python.com/2018/11/15/convert-pdf-pages-to-jpeg-with-python/) post

## Objectives:

- Extract text from PDF

## Required Tools:

- [Poppler for windows](https://blog.alivate.com.au/poppler-windows/)— Poppler is a PDF rendering library . Include the pdftoppm utility
- [Poppler for Mac](http://macappstore.org/poppler/) — If HomeBrew already installed, can use brew install Poppler
- [pdftotext](https://github.com/jalan/pdftotext)— Python module. Wraps the poppler pdftotext utility to convert PDF to text.

# Steps

1. 
  - Install Poppler. For windows, Add “`xxx/bin/`” to env path

2. 
  - `pip install pdftotext`

**Usage (sample code from pdftotext github)**

```
import pdftotext
 
# Load your PDF
with open("Target.pdf", "rb") as f:
    pdf = pdftotext.PDF(f)
 
# Save all text to a txt file.
with open('output.txt', 'w') as f:
    f.write("\n\n".join(pdf))

```

> **Further notes**
> 
> - [https://github.com/jalan/pdftotext](https://github.com/jalan/pdftotext)
