Skip to content

Commit

Permalink
Fix the creator to be a list
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed May 23, 2023
1 parent 9df89d8 commit 058c18f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 4 additions & 4 deletions scan_to_paperless/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -1580,11 +1580,11 @@ def finalize(
with pikepdf.open(temporary_pdf.name, allow_overwriting_input=True) as pdf_:
scan_to_paperless_meta = f"Scan to Paperless {os.environ.get('VERSION', 'undefined')}"
with pdf_.open_metadata() as meta:
meta["{http://purl.org/dc/elements/1.1/}creator"] = [
f"{scan_to_paperless_meta}, {tesseract_producer}"
meta["{http://purl.org/dc/elements/1.1/}creator"] = (
[scan_to_paperless_meta, tesseract_producer]
if tesseract_producer
else scan_to_paperless_meta
]
else [scan_to_paperless_meta]
)
pdf_.save(temporary_pdf.name)
if progress:
call(["cp", temporary_pdf.name, os.path.join(root_folder, f"{count}-pikepdf.pdf")])
Expand Down
7 changes: 5 additions & 2 deletions tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,13 @@ def test_full(progress):

pdf_filename = os.path.join("/results", f"{os.path.basename(root_folder)}.pdf")

creator_re = re.compile(r"^Scan to Paperless 1.[0-9]+.[0-9]+\+[0-9]+, Tesseract 4.[0-9]+.[0-9]+$")
creator_scan_tp_paperless_re = re.compile(r"^Scan to Paperless 1.[0-9]+.[0-9]+\+[0-9]+$")
creator_tesseract_re = re.compile(r"^Tesseract 4.[0-9]+.[0-9]+$")
with pikepdf.open(pdf_filename) as pdf_:
with pdf_.open_metadata() as meta:
assert creator_re.match(meta["{http://purl.org/dc/elements/1.1/}creator"])
assert len(meta["{http://purl.org/dc/elements/1.1/}creator"]) == 2
assert creator_scan_tp_paperless_re.match(meta["{http://purl.org/dc/elements/1.1/}creator"][0])
assert creator_tesseract_re.match(meta["{http://purl.org/dc/elements/1.1/}creator"][1])

pdfinfo = process.output(["pdfinfo", pdf_filename]).split("\n")
regex = re.compile(r"([a-zA-Z ]+): +(.*)")
Expand Down

0 comments on commit 058c18f

Please sign in to comment.