Adds setting to Gotenberg API call for outputting the correct PDF/A format

This commit is contained in:
Trenton H 2023-01-26 08:00:02 -08:00
parent 3ccb83e49c
commit 1b2cb13a21
2 changed files with 21 additions and 1 deletions

View File

@ -271,6 +271,16 @@ class MailDocumentParser(DocumentParser):
"paperHeight": "11.7",
"scale": "1.0",
}
# Set the output format of the resulting PDF
# Valid inputs: https://gotenberg.dev/docs/modules/pdf-engines#uno
if settings.OCR_OUTPUT_TYPE in {"pdfa", "pdfa-2"}:
data["pdfFormat"] = "PDF/A-2b"
elif settings.OCR_OUTPUT_TYPE == "pdfa-1":
data["pdfFormat"] = "PDF/A-1a"
elif settings.OCR_OUTPUT_TYPE == "pdfa-3":
data["pdfFormat"] = "PDF/A-3b"
try:
response = requests.post(
url,

View File

@ -95,9 +95,19 @@ class TikaDocumentParser(DocumentParser):
),
}
headers = {}
data = {}
# Set the output format of the resulting PDF
# Valid inputs: https://gotenberg.dev/docs/modules/pdf-engines#uno
if settings.OCR_OUTPUT_TYPE in {"pdfa", "pdfa-2"}:
data["pdfFormat"] = "PDF/A-2b"
elif settings.OCR_OUTPUT_TYPE == "pdfa-1":
data["pdfFormat"] = "PDF/A-1a"
elif settings.OCR_OUTPUT_TYPE == "pdfa-3":
data["pdfFormat"] = "PDF/A-3b"
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(