Spaces:
No application file
No application file
Download test.py from SelimGilon/Flyers: direct link, hf CLI and curl.
- Browser
- Download file 1.54 kB
-
https://huggingface.co/spaces/SelimGilon/Flyers/resolve/main/test.py
- Command line
-
hf download hf://spaces/SelimGilon/Flyers/test.py
-
curl -L -o test.py https://huggingface.co/spaces/SelimGilon/Flyers/resolve/main/test.py
1.54 kB
| 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) | |