improve pdf generation

This commit is contained in:
phail 2022-04-27 23:32:10 +02:00
parent 0e40ef5f35
commit c1efe11cf3
3 changed files with 42 additions and 22 deletions

View File

@ -14,24 +14,20 @@
<div class="col-start-11 col-span-2 row-start-1 text-right">{{ date }}</div>
<div class="col-start-1 row-start-1 text-slate-400 text-right">From</div>
<div class="col-start-1 row-start-1 text-slate-400 text-right">{{ from_label }}</div>
<div class="col-start-2 col-span-8 row-start 1">{{ from }}</div>
<div class="col-start-1 row-start-2 text-slate-400 text-right">Subject</div>
<div class=" col-start-2 col-span-10 row-start 2 font-bold">{{ subject }}
</div>
<div class="col-start-1 row-start-2 text-slate-400 text-right">{{ subject_label }}</div>
<div class=" col-start-2 col-span-10 row-start 2 font-bold">{{ subject }}</div>
<div class="col-start-1 row-start-3 text-slate-400 text-right">To</div>
<div class="col-start-2 col-span-10 row-start 3">{{ to }}
</div>
<div class="col-start-1 row-start-3 text-slate-400 text-right">{{ to_label }}</div>
<div class="col-start-2 col-span-10 row-start 3">{{ to }}</div>
<div class="col-start-1 row-start-4 text-slate-400 text-right">CC</div>
<div class="col-start-2 col-span-10 row-start 4">{{ cc }}
</div>
<div class="col-start-1 row-start-4 text-slate-400 text-right">{{ cc_label }}</div>
<div class="col-start-2 col-span-10 row-start 4">{{ cc }}</div>
<div class="col-start-1 row-start-5 text-slate-400 text-right">BCC</div>
<div class="col-start-2 col-span-10 row-start 5">{{ bcc }}
</div>
<div class="col-start-1 row-start-5 text-slate-400 text-right">{{ bcc_label }}</div>
<div class="col-start-2 col-span-10 row-start 5">{{ bcc }}</div>
</div>
<!-- Separator-->

View File

@ -696,7 +696,7 @@ Ensure the default browser behavior of the `hidden` attribute.
}
.auto-cols-fr {
grid-auto-columns: minmax(0, 1fr);
grid-auto-columns: minmax();
}
.auto-cols-max {
@ -705,23 +705,23 @@ Ensure the default browser behavior of the `hidden` attribute.
}
.grid-cols-5 {
grid-template-columns: repeat(5, minmax(0, 1fr));
grid-template-columns: repeat(5, minmax());
}
.grid-cols-7 {
grid-template-columns: repeat(7, minmax(0, 1fr));
grid-template-columns: repeat(7, minmax());
}
.grid-cols-12 {
grid-template-columns: repeat(12, minmax(0, 1fr));
grid-template-columns: repeat(12, minmax());
}
.grid-rows-4 {
grid-template-rows: repeat(4, minmax(0, 1fr));
grid-template-rows: repeat(4, minmax());
}
.grid-rows-5 {
grid-template-rows: repeat(5, minmax(0, 1fr));
grid-template-rows: repeat(5, minmax());
}
.flex-col {

View File

@ -215,7 +215,7 @@ class TikaDocumentParserEml(DocumentParser):
def generate_pdf(self, document_path):
def clean_html(text: str):
if isinstance(text, list):
text = ", ".join([str(e) for e in text])
text = "\n".join([str(e) for e in text])
if type(text) != str:
text = str(text)
text = text.replace("&", "&amp;")
@ -236,9 +236,20 @@ class TikaDocumentParserEml(DocumentParser):
data = {}
data["subject"] = clean_html(parsed["metadata"].get("dc:subject", ""))
if data["subject"] != "":
data["subject_label"] = "Subject"
data["from"] = clean_html(parsed["metadata"].get("Message-From", ""))
if data["from"] != "":
data["from_label"] = "From"
data["to"] = clean_html(parsed["metadata"].get("Message-To", ""))
if data["to"] != "":
data["to_label"] = "To"
data["cc"] = clean_html(parsed["metadata"].get("Message-CC", ""))
if data["cc"] != "":
data["cc_label"] = "CC"
data["bcc"] = clean_html(parsed["metadata"].get("Message-BCC", ""))
if data["bcc"] != "":
data["bcc_label"] = "BCC"
data["date"] = clean_html(parsed["metadata"].get("dcterms:created", ""))
content = parsed.get("content", "").strip()
@ -273,9 +284,22 @@ class TikaDocumentParserEml(DocumentParser):
),
}
headers = {}
data = {
"marginTop": "0",
"marginBottom": "0",
"marginLeft": "0",
"marginRight": "0",
"paperWidth": "8.27",
"paperHeight": "11.7",
"scale": "1.0",
}
try:
response = requests.post(url, files=files, headers=headers)
response = requests.post(
url,
files=files,
headers=headers,
data=data,
)
response.raise_for_status() # ensure we notice bad responses
except Exception as err:
raise ParseError(f"Error while converting document to PDF: {err}")