Skip to content

Commit 70162b4

Browse files
author
Rodelph
committed
fixed uid issue v2
1 parent 33f1336 commit 70162b4

10 files changed

Lines changed: 24 additions & 25 deletions

File tree

PdfGenerator/PDF/output.pdf

-6.78 KB
Binary file not shown.

PdfGenerator/PDFEngineIO.py

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import pdfkit
44
import base64
55
import qrcode
6-
import uuid
76
import fitz # PyMuPDF
87
import webbrowser
98
from jsonio import update_data, create_data
@@ -30,9 +29,9 @@
3029
}
3130
TEMP_PDF_PATH = "./PDF/temp.pdf"
3231
FINAL_PDF_PATH = "./PDF/output.pdf"
33-
UID = str(uuid.uuid4())
32+
BIN_ID = create_data()
3433
QR_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)
3635
OUTPUT_FOLDER_PATH = "./PDF"
3736
AR_MARKER_PATH = './_ARMarker/Markers/MarkerIcons03.png'
3837

@@ -54,7 +53,7 @@ def get_ar_marker_coordinates(pdf_path):
5453

5554
def 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

134133
def 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)
726 Bytes
Loading
711 Bytes
Loading
695 Bytes
Loading
683 Bytes
Loading
813 Bytes
Loading
816 Bytes
Loading
801 Bytes
Loading
821 Bytes
Loading

0 commit comments

Comments
 (0)