mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-28 18:24:38 -05:00
Feature: Upgrade Gotenberg to v8 (#7094)
This commit is contained in:
@@ -9,7 +9,9 @@ from django.conf import settings
|
||||
from django.utils.timezone import is_naive
|
||||
from django.utils.timezone import make_aware
|
||||
from gotenberg_client import GotenbergClient
|
||||
from gotenberg_client.options import Margin
|
||||
from gotenberg_client.options import MarginType
|
||||
from gotenberg_client.options import MarginUnitType
|
||||
from gotenberg_client.options import PageMarginsType
|
||||
from gotenberg_client.options import PageSize
|
||||
from gotenberg_client.options import PdfAFormat
|
||||
from humanize import naturalsize
|
||||
@@ -20,6 +22,7 @@ from tika_client import TikaClient
|
||||
from documents.parsers import DocumentParser
|
||||
from documents.parsers import ParseError
|
||||
from documents.parsers import make_thumbnail_from_pdf
|
||||
from paperless.models import OutputTypeChoices
|
||||
|
||||
|
||||
class MailDocumentParser(DocumentParser):
|
||||
@@ -30,17 +33,22 @@ class MailDocumentParser(DocumentParser):
|
||||
|
||||
logging_name = "paperless.parsing.mail"
|
||||
|
||||
@staticmethod
|
||||
def _settings_to_gotenberg_pdfa() -> Optional[PdfAFormat]:
|
||||
def _settings_to_gotenberg_pdfa(self) -> Optional[PdfAFormat]:
|
||||
"""
|
||||
Converts our requested PDF/A output into the Gotenberg API
|
||||
format
|
||||
"""
|
||||
if settings.OCR_OUTPUT_TYPE in {"pdfa", "pdfa-2"}:
|
||||
if settings.OCR_OUTPUT_TYPE in {
|
||||
OutputTypeChoices.PDF_A,
|
||||
OutputTypeChoices.PDF_A2,
|
||||
}:
|
||||
return PdfAFormat.A2b
|
||||
elif settings.OCR_OUTPUT_TYPE == "pdfa-1": # pragma: no cover
|
||||
return PdfAFormat.A1a
|
||||
elif settings.OCR_OUTPUT_TYPE == "pdfa-3": # pragma: no cover
|
||||
elif settings.OCR_OUTPUT_TYPE == OutputTypeChoices.PDF_A1: # pragma: no cover
|
||||
self.log.warn(
|
||||
"Gotenberg does not support PDF/A-1a, choosing PDF/A-2b instead",
|
||||
)
|
||||
return PdfAFormat.A2b
|
||||
elif settings.OCR_OUTPUT_TYPE == OutputTypeChoices.PDF_A3: # pragma: no cover
|
||||
return PdfAFormat.A3b
|
||||
return None
|
||||
|
||||
@@ -329,7 +337,14 @@ class MailDocumentParser(DocumentParser):
|
||||
response = (
|
||||
route.index(email_html_file)
|
||||
.resource(css_file)
|
||||
.margins(Margin(top=0.1, bottom=0.1, left=0.1, right=0.1))
|
||||
.margins(
|
||||
PageMarginsType(
|
||||
top=MarginType(0.1, MarginUnitType.Inches),
|
||||
bottom=MarginType(0.1, MarginUnitType.Inches),
|
||||
left=MarginType(0.1, MarginUnitType.Inches),
|
||||
right=MarginType(0.1, MarginUnitType.Inches),
|
||||
),
|
||||
)
|
||||
.size(PageSize(height=11.7, width=8.27))
|
||||
.scale(1.0)
|
||||
.run()
|
||||
@@ -404,7 +419,14 @@ class MailDocumentParser(DocumentParser):
|
||||
route.index(html_clean_file)
|
||||
|
||||
# Set page size, margins
|
||||
route.margins(Margin(top=0.1, bottom=0.1, left=0.1, right=0.1)).size(
|
||||
route.margins(
|
||||
PageMarginsType(
|
||||
top=MarginType(0.1, MarginUnitType.Inches),
|
||||
bottom=MarginType(0.1, MarginUnitType.Inches),
|
||||
left=MarginType(0.1, MarginUnitType.Inches),
|
||||
right=MarginType(0.1, MarginUnitType.Inches),
|
||||
),
|
||||
).size(
|
||||
PageSize(height=11.7, width=8.27),
|
||||
).scale(1.0)
|
||||
|
||||
|
Reference in New Issue
Block a user