Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the creator #1029

Merged
merged 1 commit into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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