diff --git a/.gitignore b/.gitignore index 857c115..1d3715c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ /node_modules/ .idea + +.venv +scripts/*.pdf \ No newline at end of file diff --git a/files/assets/css/main.css b/files/assets/css/main.css index 57710f2..1cf1a25 100644 --- a/files/assets/css/main.css +++ b/files/assets/css/main.css @@ -2,8 +2,17 @@ display: flex; flex-direction: column; overflow-y: hidden; - width: 100vw; - height: 95vh; + width: 100%; + height: 100%; +} + +html, +body { + margin: 0; + padding: 0; + width: 100%; + height: 100%; + font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; } .navbar { @@ -17,7 +26,6 @@ color: white; padding: 8px; text-decoration: none; - font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .nav-link:visited { diff --git a/scripts/add_home.py b/scripts/add_home.py new file mode 100644 index 0000000..8847ed7 --- /dev/null +++ b/scripts/add_home.py @@ -0,0 +1,54 @@ +from pypdf import PdfWriter, PdfReader, Transformation +from pypdf.generic import RectangleObject +from pypdf.annotations import Link +from copy import copy + +# constants +FILE_NAME = "Yearbook 2021.pdf" +ICON_NAME = "house.pdf" +FILE_OUT = "merged-pdf.pdf" +PAGES = range(6, 103, 2) +HOME_PAGE_INDEX = 2 +MARGIN = 5 + +# get the base file +reader_base = PdfReader(FILE_NAME) + +# get the icon +reader = PdfReader(ICON_NAME) +page_icon = reader.pages[0] + +# get the icon size +icon_width: float = page_icon.mediabox.width +icon_height: float = page_icon.mediabox.height + +# result writer +writer = PdfWriter(clone_from=reader_base) + +for page in range(len(writer.pages)): + page_base = writer.pages[page] + + if page in PAGES: + # get the page size + page_width: float = page_base.mediabox.width + page_height: float = page_base.mediabox.height + + # transform the icon to the right, with a small margin + trans = Transformation().translate(tx=page_width - icon_width - MARGIN, ty=MARGIN) + page_icon_copy = copy(page_icon) + page_icon_copy.mediabox = RectangleObject((0, 0, page_width, page_height)) + page_icon_copy.add_transformation(trans) + + page_base.merge_page(page_icon_copy, over=True) + + # add a link annotation to page 2 + annotation = Link( + rect=(page_width - icon_width - MARGIN, MARGIN, page_width - MARGIN, icon_height + MARGIN), + target_page_index=HOME_PAGE_INDEX + ) + writer.add_annotation(page_number=page, annotation=annotation) + else: + writer.add_page(page_base) + +with open("merged-pdf.pdf", "wb") as fp: + writer.write(fp) \ No newline at end of file diff --git a/scripts/optimize.py b/scripts/optimize.py new file mode 100644 index 0000000..92177b8 --- /dev/null +++ b/scripts/optimize.py @@ -0,0 +1,11 @@ +from pikepdf import Pdf, ObjectStreamMode, settings +from tqdm import tqdm + +settings.set_flate_compression_level(9) + +INPUT_PDF = "Yearbook-2020.pdf" +OUTPUT_PDF = "Yearbook-2020-opt.pdf" + +with Pdf.open(INPUT_PDF) as pdf: + with tqdm(total=100, unit="%") as pbar: + pdf.save(OUTPUT_PDF, recompress_flate=True, object_stream_mode=ObjectStreamMode.generate, linearize=True, progress=(lambda x: pbar.update(x - pbar.n))) \ No newline at end of file diff --git a/scripts/requirements.txt b/scripts/requirements.txt new file mode 100644 index 0000000..f7daadd --- /dev/null +++ b/scripts/requirements.txt @@ -0,0 +1,8 @@ +Deprecated==1.2.14 +lxml==5.0.0 +packaging==23.2 +pikepdf==8.11.2 +Pillow==10.1.0 +pypdf==3.17.4 +tqdm==4.66.1 +wrapt==1.16.0