File size: 1,542 Bytes
842ff0c
 
 
 
 
 
8040a44
 
 
 
 
842ff0c
 
1a02be9
8040a44
 
 
 
 
 
 
 
 
 
 
 
842ff0c
8040a44
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import pypdfium2 as pdfium
# read a PDF document and its text
#
pdf = pdfium.PdfDocument("/Users/selimgilon/Desktop/SportBoost/Projects/Iflyers/Magazines_pdf/Circulaire hebdomadaire 2.pdf")
version = pdf.get_version()  # get the PDF standard version
n_pages = len(pdf)  # get the number of pages in the document
page = pdf.get_page(0)
pil_image = page.render().to_pil()
# get height and width of the page
width_img, height_img = pil_image.size
print("width", width_img, "height", height_img)
width, height = page.get_size()
print("width", width, "height", height)


# image_name = "test"
# image_name =f"{image_name}.jpg"
# pil_image.save(image_name)

# page = pdf[0]  # get the first page
# # Load a text page helper
# textpage = page.get_textpage()
# page = pdf.get_page(page_number)
# # Get the page size in pixels
# width, height = page.get_size()
# print("width", width, "height", height)
#
# # # Extract text from the whole page
# text_all = textpage.get_text_range()
# print(text_all)
# print("=====================================")
# # # Extract text from a specific rectangular area
# text_part = textpage.get_text_bounded(left=width-150, bottom=100, right=width-50, top=height-100)
# print(text_part)
# print("=====================================")
# # # Locate text on the page
# searcher = textpage.search("TÉLÉ INTELLIGENTE", match_case=False, match_whole_word=False)
# # # This returns the next occurrence as (char_index, char_count), or None if not found
# first_occurrence = searcher.get_next()
# print(first_occurrence)