Skip to content

Commit

Permalink
Pdf File close after opening
Browse files Browse the repository at this point in the history
  • Loading branch information
justinjosephmkj committed May 30, 2024
1 parent 9c92f5c commit b21db56
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions doctr/io/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,19 @@ def read_pdf(
the list of pages decoded as numpy ndarray of shape H x W x C
"""
# Rasterise pages to numpy ndarrays with pypdfium2
pdf = pdfium.PdfDocument(file, password=password, autoclose=True)
return [page.render(scale=scale, rev_byteorder=rgb_mode, **kwargs).to_numpy() for page in pdf]

# Initialize an empty list to store rendered pages
rendered_pages = []

# Create a PdfDocument object
pdf = pdfium.PdfDocument(file, password=password)

# Render pages to numpy ndarrays
for page in pdf:
rendered_page = page.render(scale=scale, rev_byteorder=rgb_mode, **kwargs).to_numpy()
rendered_pages.append(rendered_page)

# Close the PdfDocument object
pdf.close()

return rendered_pages

0 comments on commit b21db56

Please sign in to comment.