Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
Using pdfplumber¶
In [1]:
import pdfplumber
In [2]:
!wget www.legendu.net/media/wolfram/sum_and_product.pdf
In [13]:
with pdfplumber.open("sum_and_product.pdf") as pdf:
img = pdf.pages[0].to_image(resolution=200)
img
Out[13]:
In [14]:
type(img)
Out[14]:
In [15]:
img.save("0.png")
In [ ]:
Using PyMuPDF / fitz¶
In [ ]:
!wajig install python3-fitz
In [6]:
import fitz
In [10]:
pdffile = "source.pdf"
In [11]:
doc = fitz.open(pdffile)
In [12]:
zoom = 4
mat = fitz.Matrix(zoom, zoom)
count = 0
# Count variable is to get the number of pages in the pdf
for p in doc:
count += 1
for i in range(count):
val = f"my_image_{i+1}.png"
page = doc.load_page(i)
pix = page.get_pixmap()
pix.save(val)
doc.close()