33import pdfkit
44import base64
55import qrcode
6- import uuid
76import fitz # PyMuPDF
87import webbrowser
98from jsonio import update_data , create_data
3029}
3130TEMP_PDF_PATH = "./PDF/temp.pdf"
3231FINAL_PDF_PATH = "./PDF/output.pdf"
33- UID = str ( uuid . uuid4 () )
32+ BIN_ID = create_data ( )
3433QR_FOLDER_PATH = "./QR"
35- UID_FOLDER_PATH = os .path .join (QR_FOLDER_PATH , UID )
34+ UID_FOLDER_PATH = os .path .join (QR_FOLDER_PATH , BIN_ID )
3635OUTPUT_FOLDER_PATH = "./PDF"
3736AR_MARKER_PATH = './_ARMarker/Markers/MarkerIcons03.png'
3837
@@ -54,7 +53,7 @@ def get_ar_marker_coordinates(pdf_path):
5453
5554def generate_qr_codes (num_pages ):
5655 for p_no in range (num_pages ):
57- text = f'{{"id": "{ UID } ", "page": { p_no + 1 } }}'
56+ text = f'{{"id": "{ BIN_ID } ", "page": { p_no + 1 } }}'
5857 qr = qrcode .QRCode (version = 1 , error_correction = qrcode .constants .ERROR_CORRECT_L , box_size = 10 , border = 4 )
5958 qr .add_data (text )
6059 qr .make (fit = True )
@@ -111,29 +110,29 @@ def process_pdf_metadata(pdf_path, url):
111110
112111 total_pages = doc .page_count
113112 item_count = 0
114- bin_id = create_data ()
115- hyperlink_id = UID
116- for page_idx in range (total_pages ):
117- cur_page = doc .load_page (page_idx )
118- links = cur_page .get_links ()
119- hyperlinks = []
120-
121- for item in links :
122- x0 , y0 , x1 , y1 = item ['from' ]
123- coordinates = [round (coord , 5 ) for coord in [x0 , y0 , x1 , y1 ]]
124- uri = item .get ('uri' , '' )
125- hyperlink = {'id' : f"{ hyperlink_id } -{ item_count } " , 'uri' : uri , 'coordinates' : coordinates }
126- hyperlinks .append (hyperlink )
127- item_count += 1
128-
129- json_data ['pages' ].append ({"hyperlinks" : hyperlinks })
130-
131- update_data (bin_id = hyperlink_id , json_data = json_data )
132- doc .close ()
113+
114+ hyperlink_id = BIN_ID
115+ for page_idx in range (total_pages ):
116+ cur_page = doc .load_page (page_idx )
117+ links = cur_page .get_links ()
118+ hyperlinks = []
119+
120+ for item in links :
121+ x0 , y0 , x1 , y1 = item ['from' ]
122+ coordinates = [round (coord , 5 ) for coord in [x0 , y0 , x1 , y1 ]]
123+ uri = item .get ('uri' , '' )
124+ hyperlink = {'id' : f"{ hyperlink_id } -{ item_count } " , 'uri' : uri , 'coordinates' : coordinates }
125+ hyperlinks .append (hyperlink )
126+ item_count += 1
127+
128+ json_data ['pages' ].append ({"hyperlinks" : hyperlinks })
129+
130+ update_data (bin_id = BIN_ID , json_data = json_data )
131+ doc .close ()
133132
134133def making_pdf_qr (path ):
135- pdfkit .from_url (path , output_path = TEMP_PDF_PATH , configuration = CONFIG , options = OPT , verbose = False )
136- num_pages = count_pdf_pages (TEMP_PDF_PATH )
134+ pdfkit .from_url (path , output_path = TEMP_PDF_PATH , configuration = CONFIG , options = OPT , verbose = False )
135+ num_pages = count_pdf_pages (TEMP_PDF_PATH )
137136 generate_qr_codes (num_pages )
138137 add_qr_codes_to_pdf (num_pages , TEMP_PDF_PATH , FINAL_PDF_PATH )
139138 os .remove (TEMP_PDF_PATH )
0 commit comments