pymupdf

Python library for reading, writing, and manipulating PDF files

brewmacoslinux
Try with needOr install directly
Source

About

Python bindings for the PDF toolkit and renderer MuPDF

Examples

extract text from a PDF file$ python3 -c "import fitz; doc = fitz.open('file.pdf'); print(doc[0].get_text())"
convert PDF pages to images$ python3 -c "import fitz; doc = fitz.open('file.pdf'); pix = doc[0].get_pixmap(); pix.save('page.png')"
merge multiple PDF files together$ python3 -c "import fitz; doc = fitz.open(); doc.insert_pdf(fitz.open('file1.pdf')); doc.insert_pdf(fitz.open('file2.pdf')); doc.save('merged.pdf')"
extract images from PDF document$ python3 -c "import fitz; doc = fitz.open('file.pdf'); [fitz.Pixmap(doc, xref).save('image_%d.png' % i) for i, xref in enumerate(doc.get_page_images(0))]"
add watermark or text overlay to PDF$ python3 -c "import fitz; doc = fitz.open('file.pdf'); doc[0].insert_text((50, 50), 'Watermark', fontsize=12); doc.save('watermarked.pdf')"