moves graphics folder

This commit is contained in:
Marcel Gansfusz
2025-07-30 11:17:19 +02:00
parent 46f44901e8
commit ec08eea910
12 changed files with 436 additions and 15 deletions

Binary file not shown.

BIN
app/graphics/empty.pdf Normal file

Binary file not shown.

65
app/graphics/empty.svg Normal file
View File

@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="210mm"
height="297mm"
viewBox="0 0 210 297"
version="1.1"
id="svg1"
inkscape:version="1.4 (e7c3feb100, 2024-10-09)"
sodipodi:docname="empty.svg"
inkscape:export-filename="empty.pdf"
inkscape:export-xdpi="96"
inkscape:export-ydpi="96"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview1"
pagecolor="#ffffff"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
inkscape:document-units="mm"
inkscape:zoom="0.85670232"
inkscape:cx="566.70793"
inkscape:cy="542.77896"
inkscape:window-width="1504"
inkscape:window-height="931"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="layer1" />
<defs
id="defs1" />
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<path
style="fill:#000000;stroke:#ffffff;stroke-width:0.407001;stroke-opacity:0.247707"
d="m 48.79125,72.679957 0.7721,56.517593 27.949953,0.7721 0.30884,-5.25027 -22.545267,-0.7721 -0.772099,-8.33866 22.390848,-0.15442 0.30884,-5.55911 -23.008528,0.46326 -0.926518,-30.72951 23.471787,-0.308837 -0.61768,-7.875403 z"
id="path1" />
<path
style="fill:#000000;stroke:#ffffff;stroke-width:0.407001;stroke-opacity:0.247707"
d="m 88.01384,130.27848 -1.389777,-57.444103 21.309907,25.942499 24.39831,-25.63366 2.00745,56.672004 -5.86794,0.30884 -0.61768,-43.237495 -19.30246,18.993615 -18.067096,-21.155491 1.853035,44.936111 z"
id="path2" />
<path
id="path3"
style="fill:#000000;stroke:#ffffff;stroke-width:0.407001;stroke-opacity:0.247707"
d="m 158.99066,69.906981 c -5.69894,0.0074 -10.75335,1.691886 -10.75335,1.691886 l 0.61805,58.525113 h 8.02949 l -0.46303,-28.25874 c 0,0 18.53005,6.02224 18.37563,-16.523026 -0.0869,-12.681712 -8.47959,-15.444734 -15.80679,-15.435233 z m 1.53117,5.377966 c 2.78363,-0.0438 5.81711,1.425874 6.09162,7.895642 0.48035,11.32111 -8.86154,11.068264 -10.18077,10.976591 0.1175,0.12788 -0.16537,-0.01292 -0.16537,-0.01292 0,0 0.0655,0.006 0.16537,0.01292 -0.004,-0.0048 -0.005,-0.0073 -0.0109,-0.01292 -0.15442,-0.154419 -0.61753,-17.603576 -0.61753,-17.603576 0,0 2.2614,-1.217094 4.71754,-1.255738 z" />
<path
style="fill:#000000;stroke:#ffffff;stroke-width:0.407001;stroke-opacity:0.247707"
d="m 45.548438,148.65442 h 34.126741 v 6.48562 H 64.387633 l 0.308841,37.83282 -6.331207,-0.30884 -0.308837,-37.83281 H 45.239599 Z"
id="path4" />
<path
style="fill:#000000;stroke:#ffffff;stroke-width:0.407001;stroke-opacity:0.247707"
d="M 98.668793,148.34558 105,148.5 l 8.18424,19.61129 12.66241,-19.76571 h 8.33866 l -29.49415,47.25241 -7.103303,-0.46326 12.044733,-22.08201 z"
id="path5" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
app/graphics/greeting.pdf Normal file

Binary file not shown.

193
app/graphics/greeting.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 89 KiB

BIN
app/graphics/text2.pdf Normal file

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="210mm"
height="297mm"
viewBox="0 0 210 297"
version="1.1"
id="svg1"
inkscape:version="1.4 (e7c3feb100, 2024-10-09)"
sodipodi:docname="unsupported.svg"
inkscape:export-filename="unsupported.pdf"
inkscape:export-xdpi="96"
inkscape:export-ydpi="96"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview1"
pagecolor="#ffffff"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
inkscape:document-units="mm"
inkscape:zoom="0.60578002"
inkscape:cx="149.39416"
inkscape:cy="642.14729"
inkscape:window-width="1504"
inkscape:window-height="931"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="layer1" />
<defs
id="defs1" />
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<path
style="fill:#000000;stroke:#ffffff;stroke-width:0.407001;stroke-opacity:0.247707"
d="M 9.4195981,19.765714 9.1107587,86.16616 45.708215,86.320579 45.862634,19.920134 38.759331,20.074553 39.22259,80.607052 14.361026,80.452634 v -60.68692 z"
id="path1" />
<path
style="fill:#000000;stroke:#ffffff;stroke-width:0.407001;stroke-opacity:0.247707"
d="m 57.135267,86.320579 -0.926518,-66.400445 11.118215,0.154419 30.11183,56.672009 -1.080937,-58.061785 8.493083,-0.15442 0.46326,66.400445 -11.890318,0.30884 -31.501606,-60.5325 0.463259,62.076696 z"
id="path2" />
<path
style="fill:#000000;stroke:#ffffff;stroke-width:0.407001;stroke-opacity:0.247707"
d="M 45.553793,98.674152 C 43.08308,98.82857 10.037277,98.210893 10.037277,98.210893 c 0,0 -1.0809379,31.810447 -0.4632594,31.656027 0.6176784,-0.15442 27.0234374,-0.15442 27.0234374,-0.15442 l 0.154418,27.48669 -26.869016,-0.77209 0.15442,6.48562 31.964866,0.15442 c 0,0 0.926518,-39.22259 0,-39.22259 -0.926518,0 -26.714599,-0.46326 -26.714599,-0.46326 l -1.235357,-21.30991 31.501606,0.61768 z"
id="path3" />
<path
style="fill:#000000;stroke:#ffffff;stroke-width:0.407001;stroke-opacity:0.247707"
d="m 56.363168,98.82857 c 0,0.772099 0.926518,65.16509 0.926518,65.16509 l 38.296072,0.15442 0.154418,-66.246028 -7.875399,-0.154418 1.080937,60.532496 -24.861562,-0.15442 -0.926518,-58.988299 z"
id="path4" />
<path
id="path5"
style="fill:#000000;stroke:#ffffff;stroke-width:0.407001;stroke-opacity:0.247707"
d="M 109.7318 98.26377 C 107.54339 98.239641 106.08655 98.365055 106.08655 98.365055 L 106.08655 165.22919 L 113.4985 164.61114 L 112.88097 124.61668 C 112.88097 124.61668 129.7124 123.5357 129.55798 109.94678 C 129.44217 99.755078 116.29705 98.336154 109.7318 98.26377 z M 113.65301 103.46139 C 113.65301 103.46139 122.45454 104.54227 122.45454 111.95441 C 122.45454 119.36655 113.65301 118.90334 113.65301 118.90334 L 113.65301 103.46139 z " />
<path
id="path6"
style="fill:#000000;stroke:#ffffff;stroke-width:0.407001;stroke-opacity:0.247707"
d="M 139.54187 99.033748 C 138.14225 99.050713 137.27896 99.137618 137.27896 99.137618 C 137.27896 100.68182 137.7425 165.38319 137.7425 165.38319 L 146.54403 165.07468 L 146.39003 132.02863 C 146.39003 132.02863 160.90518 134.34533 161.36844 115.50613 C 161.74484 100.19928 145.60687 98.960233 139.54187 99.033748 z M 146.85305 106.08655 C 146.85305 106.08655 155.19184 107.63034 155.6551 116.58668 C 156.11836 125.54302 146.85305 125.85227 146.85305 125.85227 C 146.85305 125.85227 147.00747 124.61691 146.85305 106.08655 z " />
<path
id="path7"
style="fill:#000000;stroke:#ffffff;stroke-width:0.407001;stroke-opacity:0.247707"
d="M 8.0300008 183.60481 L 3.8607463 250.77746 L 43.855204 251.08648 L 43.855204 184.06835 L 8.0300008 183.60481 z M 37.67832 191.17128 L 35.825203 244.44606 L 11.272697 245.21862 L 14.515393 191.32579 C 16.522849 191.63463 37.67832 191.17128 37.67832 191.17128 z " />
<path
id="path8"
style="fill:#000000;stroke:#ffffff;stroke-width:0.407001;stroke-opacity:0.247707"
d="M 59.1783 184.00479 C 55.307442 184.00008 52.502738 184.37686 52.502738 184.37686 L 52.657251 250.62295 L 60.532739 250.62295 L 60.532739 218.19495 L 77.673295 248.92434 L 86.474825 248.46132 L 61.458781 210.01095 C 61.458781 210.01095 82.151296 214.79777 81.688037 197.65719 C 81.369547 185.87304 67.694188 184.01516 59.1783 184.00479 z M 61.767806 189.16416 C 61.767806 189.16416 72.113748 193.02454 73.503524 198.42923 C 74.893301 203.83392 61.304785 204.14258 61.304785 204.14258 L 61.767806 189.16416 z " />
<path
style="fill:#000000;stroke:#ffffff;stroke-width:0.407001;stroke-opacity:0.247707"
d="m 94.96808,185.61241 41.07562,-0.15442 0.61768,8.33866 -17.60384,-0.30884 0.30884,53.89245 h -7.72098 l -0.7721,-54.51013 -16.677319,-0.15442 z"
id="path9" />
<path
style="fill:#000000;stroke:#ffffff;stroke-width:0.407001;stroke-opacity:0.247707"
d="m 142.22049,185.45799 0.46326,62.69437 h 26.40576 l -0.30884,-6.79446 -20.53782,-0.61768 -0.46325,-23.16295 20.69223,0.46326 v -8.33866 h -19.76572 l -0.15442,-19.30245 19.14804,-0.7721 0.15442,-5.40469 z"
id="path10" />
<path
id="path11"
style="fill:#000000;stroke:#ffffff;stroke-width:0.407001;stroke-opacity:0.247707"
d="M 186.10389 183.67096 C 184.99641 183.67051 184.24207 183.78828 184.06835 183.75933 C 183.14183 183.60491 176.50189 184.22286 176.50189 184.22286 L 176.65588 248.61583 L 182.83277 248.61583 C 182.83277 248.61583 201.20876 243.82841 201.82644 211.86355 C 202.32831 185.8921 190.90296 183.67292 186.10389 183.67096 z M 182.67826 190.39923 C 182.67826 190.39923 193.79653 191.17146 193.95095 212.94462 C 194.10537 234.71779 182.83277 242.28444 182.83277 242.28444 L 182.67826 190.39923 z " />
</g>
</svg>

After

Width:  |  Height:  |  Size: 6.1 KiB

View File

@@ -3,6 +3,10 @@ from typing import List, Dict, Tuple
from annotated_types import IsDigit
from fastapi import FastAPI, File, HTTPException, UploadFile, Request, Form
from fastapi.responses import FileResponse
# import multiprocessing
# import threading
# import concurrent.futures
# import asyncio
# import fastapi
from fastapi.staticfiles import StaticFiles
@@ -48,6 +52,9 @@ EX_DATE_CATEGORIES = ["Prüfungen", "Klausuren"]
EX_DATE_CATEGORIES_I = [0, 1]
UNIZEUG_PATH = "./app/dest/"
FILES_IN_PROGRESS = "./app/files/"
EMPTYFILE = "./app/graphics/empty.pdf"
UNSUPPORTEDFILE = "./app/graphics/unsupported.pdf"
GREETINGFILE = "./app/graphics/greeting.pdf"
# cur = db.cursor()
@@ -66,10 +73,12 @@ async def get_file(file_id: str):
"""returns the file that cooorosponds with the given ID"""
if file_id == "unsupported":
error("File is unsupported")
return FileResponse(FILES_IN_PROGRESS + "unsupported.pdf")
return FileResponse(UNSUPPORTEDFILE)
if file_id == "empty":
error("File Id empty")
return FileResponse(FILES_IN_PROGRESS + "empty.pdf")
return FileResponse(EMPTYFILE)
if file_id == "greeting":
return FileResponse(GREETINGFILE)
cur = db.cursor()
try:
cur.execute("Select filename from FIP where id=?", (file_id,))
@@ -308,7 +317,7 @@ async def get_submission(
pagescales: Annotated[
str, Form()
], # Scales of Pages # Annotated[List[Dict[str, float]], Form()],
censor: Annotated[str, Form()] | bool = False,
censor: Annotated[str, Form()],
):
"""handles submission"""
print(
@@ -333,13 +342,15 @@ async def get_submission(
except ValueError as e:
error(f"Error creating savepath: f{e}")
raise HTTPException(status_code=400, detail=str(e))
censor_pdf(filepath, dest, rects_p, scales_p, False if censor is False else True)
await censor_pdf(
filepath, dest, rects_p, scales_p, False if censor == "False" else True
)
# return {"done": "ok"}
print(dest)
return FileResponse(dest, content_disposition_type="inline")
def censor_pdf(
async def censor_pdf(
path: str,
destpath: str,
rects: List[List[List[float]]],
@@ -360,10 +371,13 @@ def censor_pdf(
doc = pymupdf.open(path)
output = pymupdf.open()
page = doc[0]
width = page.rect.width
height = page.rect.height
print(width, height)
for i in range(doc.page_count):
# width = page.rect.width
# height = page.rect.height
# print(width, height)
npage = doc.page_count
# pages = []
# tasks = []
for i in range(npage):
page = doc[i]
if i < len(rects) and rects[i] != []:
print(i)
@@ -382,18 +396,53 @@ def censor_pdf(
fill=(0, 0, 0),
)
if secure:
# pages.append(page)
bitmap = page.get_pixmap(dpi=400)
pdf_bytes = bitmap.pdfocr_tobytes(
language="deu",
tessdata="/usr/share/tessdata/", # tesseract needs to be installed; this is the path to thetesseract files
)
output.insert_pdf(pymupdf.Document(stream=pdf_bytes))
print(f" Page {i}/{doc.page_count} CENSORING DONE")
# tasks.append(asyncio.create_task(censor_page(page)))
print(f"Page {i + 1}/{npage}: CENSORING DONE")
else:
output.insert_pdf(doc, i, i)
# if secure:
# pages_bytes: List[bytes] = []
# censor_page(pages[0])
# with multiprocessing.Pool(npage) as p:
# pages_bytes = p.map(censor_page, pages)
# pages_bytes = p.map(test_function, [1, 2, 3, 4])
# for pdf_bytes in pages_bytes:
# output.insert_pdf(pymupdf.Document(stream=pdf_bytes))
# with concurrent.futures.ThreadPoolExecutor() as executor:
# futures = []
# for page in pages:
# futures.append(executor.submit(censor_page, page))
# for future in futures:
# output.insert_pdf(pymupdf.Document(stream=future.result()))
#
# for task in tasks:
# output.insert_pdf(pymupdf.Document(stream=await task))
# print("CENSORING DONE")
output.save(destpath)
def test_function(i: int) -> bytes:
return b"\x00\x66\x99"
async def censor_page(page: pymupdf.Page) -> bytes:
bitmap = page.get_pixmap(dpi=400)
pdf_bytes = bitmap.pdfocr_tobytes(
language="deu",
tessdata="/usr/share/tessdata/", # tesseract needs to be installed; this is the path to thetesseract files
)
# print(pdf_bytes)
return pdf_bytes
# def save_without_censoring(dest)

View File

@@ -273,6 +273,9 @@ function submitPdf(eve) {
formdata.append("fileId", doc.fID);
//formdata.append("filename", doc.filename);
formdata.append("ftype", doc.filetype);
if (!formdata.has("censor")) {
formdata.append("censor", "False");
}
console.log(formdata);
submitForm(formdata);
}
@@ -361,12 +364,13 @@ function initListeners() {
});
}
const startPdf = () => {
doc = new PDFDocument(
"./files/b78c869f-e0bb-11ef-9b58-84144d05d665",
"b78c869f-e0bb-11ef-9b58-84144d05d665",
"pdf",
);
// doc = new PDFDocument(
// "./files/b78c869f-e0bb-11ef-9b58-84144d05d665",
// "b78c869f-e0bb-11ef-9b58-84144d05d665",
// "pdf",
// );
//pdf = new PDFView("./VO_Mathematik_3.pdf");
doc = new PDFDocument("./files/greeting", "greeting", "pdf");
initDraw();
initUpload();
initListeners();

View File

@@ -170,9 +170,21 @@ function autocomplete(inp, type) {
closeAllLists(e.target);
});
}
function enter_current_semeseter() {
var semField = document.getElementById("sem");
var today = new Date();
var year = today.getFullYear();
var month = today.getMonth();
if (month < 9 && month > 1) {
semField.value = String(year) + "S";
} else {
semField.value = String(year) + "W";
}
}
function init() {
autocomplete(document.getElementById("lva"), "lva");
autocomplete(document.getElementById("prof"), "prof");
autocomplete(document.getElementById("subcat"), "subcat");
enter_current_semeseter();
}
window.addEventListener("load", init);

View File

@@ -39,6 +39,15 @@ span {
justify-content: space-between;
}
button {
background-color: #0872a9;
/* border-radius: 20px; */
border-top-left-radius: 10px;
border-top-right-radius: 10px;
border-bottom-right-radius: 0px;
border-bottom-left-radius: 0px;
}
.main {
height: 100vh;
width: 100vw;