Skip to content

Commit 7e77a5f

Browse files
author
N.A
authored
Merge pull request #1 from Rodelph/feature/combine_final_applications
Feature/combine final applications
2 parents 70162b4 + b5635df commit 7e77a5f

1,353 files changed

Lines changed: 925 additions & 855176 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.DS_Store

-10 KB
Binary file not shown.

.gitattributes

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
PdfGenerator/dist/* filter=lfs diff=lfs merge=lfs -text
2-
PdfGenerator/wkhtmltopdf/* filter=lfs diff=lfs merge=lfs -text
1+
ARchivist_document_generator/dist/* filter=lfs diff=lfs merge=lfs -text
2+
ARchivist_document_generator/wkhtmltopdf/* filter=lfs diff=lfs merge=lfs -text

.gitignore

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
/[Ll]ogs/
1111
/[Uu]ser[Ss]ettings/
1212

13-
/PdfGenerator/__pycache__/
14-
/PdfGenerator/build/
15-
/PdfGenerator/dist/
16-
/PdfGenerator/access.txt
17-
/PdfGenerator/*.spec
18-
/PdfGenerator/*.zip
19-
/PdfGenerator/_ARMarker/*
20-
!/PdfGenerator/_ARMarker/Markers
21-
/PdfGenerator/_ARMarker/Markers/*.meta
22-
/PdfGenerator/_ARMarker/Markers/*.asset
13+
/ARchivist_document_generator/__pycache__/
14+
/ARchivist_document_generator/build/
15+
/ARchivist_document_generator/dist/
16+
/ARchivist_document_generator/access.txt
17+
/ARchivist_document_generator/*.spec
18+
/ARchivist_document_generator/*.zip
19+
/ARchivist_document_generator/_ARMarker/*
20+
!ARchivist_document_generatorr/_ARMarker/Markers
21+
/ARchivist_document_generator/_ARMarker/Markers/*.meta
22+
/ARchivist_document_generator/_ARMarker/Markers/*.asset
2323

2424
# MemoryCaptures can get excessive in size.
2525
# They also could contain extremely sensitive data
@@ -67,7 +67,6 @@ ExportedObj/
6767
sysinfo.txt
6868

6969
# Builds
70-
*.apk
7170
*.aab
7271
*.unitypackage
7372
*.app
@@ -81,3 +80,21 @@ crashlytics-build.properties
8180
# Temporary auto-generated Android Assets
8281
/[Aa]ssets/[Ss]treamingAssets/aa.meta
8382
/[Aa]ssets/[Ss]treamingAssets/aa/*
83+
84+
# More Unity stuff to ignore
85+
*Library*
86+
*Logs*
87+
*Temp*
88+
*UserSettings*
89+
*build*
90+
91+
92+
# More python stuff to ignore
93+
*vscode*
94+
*ipynb_checkpoints*
95+
*__pycache*
96+
*PDF/*
97+
98+
99+
# More MacOS stuff to ignore
100+
*DS_Store*

.vscode/launch.json

Lines changed: 0 additions & 26 deletions
This file was deleted.

.vscode/tasks.json

Lines changed: 0 additions & 41 deletions
This file was deleted.

PdfGenerator/wkhtmltopdf/bin/wkhtmltopdf.exe renamed to ARchivist.apk

28.8 MB
Binary file not shown.

PdfGenerator/PDFEngineGit.py renamed to ARchivist_document_generator/PDFEngineGit.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,21 @@
1515
from github import Github
1616
import json
1717

18+
# Check which platform the program is being executed on
1819
if sys.platform == "win32":
1920
PATH_TO_WKHTMLTOPDF = r'./wkhtmltopdf/bin/wkhtmltopdf.exe'
2021
elif sys.platform in ["linux", "linux2"]:
2122
PATH_TO_WKHTMLTOPDF = r'./wkhtmltopdf/wkhtmltopdf'
2223
elif sys.platform in ["darwin", "os2", "os2emx"]:
2324
PATH_TO_WKHTMLTOPDF = r'./wkhtmltopdf/wkhtmltopdf-mcos'
2425

26+
# Coordinates for where to place the qr code
27+
AP, BP, WID, HEI = 200, 660, 120, 120
28+
29+
# Config setup that looks for the wktml executables within the project
2530
CONFIG = pdfkit.configuration(wkhtmltopdf=PATH_TO_WKHTMLTOPDF)
31+
32+
# Parameter initialization for files and directories
2633
OPT = {
2734
'margin-top': '2in',
2835
'margin-bottom': '1in',
@@ -32,35 +39,31 @@
3239
}
3340
TEMP_PDF_PATH = "./PDF/temp.pdf"
3441
FINAL_PDF_PATH = "./PDF/output.pdf"
42+
43+
# Creating a unique id for the json data
3544
UID = str(uuid.uuid4())
3645

46+
# Returns the number of pages in a PDF file.
3747
def count_pdf_pages(temp_pdf_path):
3848
with open(temp_pdf_path, 'rb') as file:
3949
pdf_reader = PdfReader(file)
4050
return len(pdf_reader.pages)
4151

42-
def get_ar_marker_coordinates(pdf_path):
43-
pdf_document = fitz.open(pdf_path)
44-
image_list = pdf_document.get_page_images(0, full=True)
45-
ar_marker_coordinates = pdf_document[0].get_image_rects(image_list[0][7], transform=True)[0][0]
46-
pdf_document.close()
47-
return ar_marker_coordinates
48-
52+
# Generates QR codes for each page in the PDF.
4953
def generate_qr_codes(num_pages, uid_folder_path):
5054
for p_no in range(num_pages):
51-
text = f'{{"id": "{UID}", "page": {p_no + 1}}}'
55+
text = f'{{"id": "{UID}", "page": {p_no}}}'
5256
qr = qrcode.QRCode(version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4)
5357
qr.add_data(text)
5458
qr.make(fit=True)
5559
img = qr.make_image(fill='black', back_color='white')
5660
img.save(os.path.join(uid_folder_path, f"{p_no}.png"))
5761

62+
# Embeds QR codes and AR markers into each page of the PDF.
5863
def add_qr_codes_to_pdf(num_pages, temp_pdf_path, final_pdf_path, uid_folder_path):
5964
pdf_reader = PdfReader(temp_pdf_path)
6065
pdf_writer = PdfWriter()
6166

62-
a, b = 200, 660
63-
wid, hei = 120, 120
6467
ar_marker_path = './_ARMarker/Markers/MarkerIcons03.png'
6568

6669
with open(ar_marker_path, 'rb') as marker_file:
@@ -77,8 +80,8 @@ def add_qr_codes_to_pdf(num_pages, temp_pdf_path, final_pdf_path, uid_folder_pat
7780

7881
image_pdf_path = 'image_page.pdf'
7982
c = canvas.Canvas(image_pdf_path, pagesize=letter)
80-
c.drawImage(f"data:image/png;base64,{marker_base64}", a, b, width=wid, height=hei)
81-
c.drawImage(f"data:image/png;base64,{qr_base64}", a + wid + 5, b, width=wid, height=hei)
83+
c.drawImage(f"data:image/png;base64,{marker_base64}", AP, BP, width=WID, height=HEI)
84+
c.drawImage(f"data:image/png;base64,{qr_base64}", AP + WID + 5, BP, width=WID, height=HEI)
8285
c.save()
8386

8487
with open(image_pdf_path, 'rb') as image_pdf_file:
@@ -92,15 +95,12 @@ def add_qr_codes_to_pdf(num_pages, temp_pdf_path, final_pdf_path, uid_folder_pat
9295
with open(final_pdf_path, 'wb') as output_pdf:
9396
pdf_writer.write(output_pdf)
9497

98+
# Extracts hyperlinks from the PDF and updates the JSON bin with metadata.
9599
def process_pdf_metadata(pdf_path, url):
96-
ar_marker_coordinates = get_ar_marker_coordinates(pdf_path)
97100
doc = fitz.open(pdf_path)
98101
json_data = {
99102
'URL': url,
100-
'ar_marker_coordinates': [
101-
ar_marker_coordinates.x0, ar_marker_coordinates.y0,
102-
ar_marker_coordinates.x1, ar_marker_coordinates.y1
103-
],
103+
'ar_marker_coordinates': [AP, (792 - (BP + HEI)), (AP + WID), (792 - BP)],
104104
'pages': []
105105
}
106106

@@ -132,6 +132,7 @@ def process_pdf_metadata(pdf_path, url):
132132
file_path = f'Assets/CustomAssets/{UID}.json'
133133
repo.create_file(file_path, "Added entry", file_content)
134134

135+
# Converts a URL to a PDF, generates QR codes, embeds them, processes metadata, and opens the final PDF.
135136
def making_pdf_qr(path):
136137
pdfkit.from_url(path, output_path=TEMP_PDF_PATH, configuration=CONFIG, options=OPT, verbose=False)
137138
num_pages = count_pdf_pages(TEMP_PDF_PATH)
@@ -146,6 +147,7 @@ def making_pdf_qr(path):
146147
process_pdf_metadata(FINAL_PDF_PATH, path)
147148
webbrowser.open(FINAL_PDF_PATH)
148149

150+
# Converts a existing HTMLin a local diractory to a PDF, generates QR codes, embeds them, processes metadata, and opens the final PDF.
149151
def process_pdf_file(file_path):
150152
num_pages = count_pdf_pages(file_path)
151153
uid_folder_path = os.path.join("./QR", UID)
@@ -158,6 +160,7 @@ def process_pdf_file(file_path):
158160
process_pdf_metadata(FINAL_PDF_PATH, file_path)
159161
webbrowser.open(FINAL_PDF_PATH)
160162

163+
# GUI Application
161164
class PDFGeneratorApp(QWidget):
162165
def __init__(self):
163166
super().__init__()

0 commit comments

Comments
 (0)