You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.3 KiB

4 months ago
# this is for doing some math operations
import math
# this is for handling the PDF operations
import fitz
# importing PhotoImage from tkinter
from tkinter import PhotoImage
class PDFMiner:
def __init__(self, filepath):
# creating the file path
self.filepath = filepath
# opening the pdf document
self.pdf = fitz.open(self.filepath)
# loading the first page of the pdf document
self.first_page = self.pdf.load_page(0)
# getting the height and width of the first page
self.width, self.height = self.first_page.rect.width, self.first_page.rect.height
# initializing the zoom values of the page
zoomdict = {800:0.8, 700:0.6, 600:1.0, 500:1.0}
# getting the width value
width = int(math.floor(self.width / 100.0) * 100)
# zooming the page
self.zoom = zoomdict[width]
# this will get the metadata from the document like
# author, name of document, number of pages
def get_metadata(self):
# getting metadata from the open PDF document
metadata = self.pdf.metadata
# getting number of pages from the open PDF document
numPages = self.pdf.page_count
# returning the metadata and the numPages
return metadata, numPages