Skip to content

First steps

In this page you will read your first PDF. It takes about a minute.

Get a PDF

Download the sample report and save it as report.pdf. It has three short pages, and every example in this documentation uses it, so your output will match what you see here.

Write the code

Create a file called main.py in the same folder:

main.py
import ozaru

text = ozaru.extract_text("report.pdf")
pages = ozaru.page_count("report.pdf")

print(f"Pages: {pages}")
print(f"Title: {text.splitlines()[0]}")

Run it

python main.py

You should see:

Pages: 3
Title: Quarterly Report

What just happened

  1. ozaru.extract_text opened report.pdf and returned all of its text as a str.
  2. ozaru.page_count returned the number of pages as an int.
  3. From there it's regular Python: splitlines() cut the text into lines, and [0] picked the first one.

Info

ozaru returns plain Python values. You don't have to open or close anything, because ozaru takes care of the file for you.

Next: learn more about extracting text.