/
maratn
/
CountDiffPagePdf
Обзор
Документация
Войти
/
maratn
/
CountDiffPagePdf
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
main.py
67 строк
2 KB
Marat
fixed tast
21 фев 2026, 19:31
21 фев 2026, 19:31
1d93e42
Код
Авторство
О чём код?
from pypdf import PdfReader # import argparse # parser = argparse.ArgumentParser() # parser.add_argument("file") # args = parser.parse_args() # print(args.file) def get_pdf_page_size(pdf_path, list): a4 = 0 a3 = 0 p = None if list: try: p = int(input('Enter number page for size:\n')) list = None except: pass with open(pdf_path, 'rb') as f: reader = PdfReader(f) count_pages = len(reader.pages) if count_pages == 0: return "No pages found" for i in range(count_pages): # Get the page page = reader.pages[i] width_in_points = page.mediabox.width height_in_points = page.mediabox.height if width_in_points > height_in_points: width_in_points, height_in_points = height_in_points, width_in_points if p and p == i+1: print(i+1, ' ', width_in_points, 'x', height_in_points, 'points or',\ int(0.35277777777777775*width_in_points), 'x',\ int(0.35277777777777775*height_in_points), 'mm') if width_in_points < 707 and height_in_points < 1080: a4 += 1 else: a3 += 1 if list: print(i+1, ' ', width_in_points, 'x', height_in_points, 'points or',\ int(0.35277777777777775*width_in_points), 'x',\ int(0.35277777777777775*height_in_points), 'mm') print(f"A4_(little) = {a4};\nA3_(big) = {a3};\nTotal = {count_pages}") file_a = input('Enter link to pdf file:\n') l = None while file_a: if file_a[-3:] == ' -l': l = file_a[-3:] file_a = file_a[:-3] if file_a[0] == "'" or file_a[0] == '"': file_a = file_a[1:-1] get_pdf_page_size(file_a, l) file_a = input('Press Enter to exit or enter link to pdf file: ')