Test cases / pdf

deft pdf number

Add page numbers: --format

6 runs on real files, 11 tests on generated files, not shown. 0 failed.

Fixed cases

Generated files, compared with ground truth by tools other than deft.

the number moves off an existing footerPassed

It must print bottom centre already has.

deft pdf number nda.pdf --format 'Page {n} of {total}' -o out.pdf

Input

nda.pdf 147.9 KB · 2 pages
Page 1Page 2

Output

out.pdf 148.5 KB · 2 pages
Page 1Page 2
What it printed
ok pdf.number nda.pdf -> out.pdf  2 pages numbered  0.02s
warning: the bottom centre already has text or pictures on 2 pages (page 1, 2), so the numbers went to the top; give --position to choose
Automatic checks (1)
  • changed: file = "out.pdf", from = "nda.pdf", page = 1, y = [0, 0.06]

a given position is kept, with a warning when it is takenPassed

It must print overlaps existing text.

deft pdf number nda.pdf --position bottom -o out.pdf

Input

nda.pdf 147.9 KB · 2 pages
Page 1Page 2

Output

out.pdf 148.4 KB · 2 pages
Page 1Page 2
What it printed
ok pdf.number nda.pdf -> out.pdf  2 pages numbered  0.02s
warning: the number overlaps existing text or pictures on 2 pages (page 1, 2); try another --position or --margin

Real-file tasks

Real files and a plain-language job, from the agent benchmark. These are the reference answers, not an agent run.

Assemble an application from mixed filesPassed

Put together one application.pdf for a portal: letter.docx first, then the photo DSCN0010.jpg, then fw9.pdf. Number the pages at the bottom. The portal rejects anything over 1MB.

deft doc to-pdf letter.docx -o letter.pdf
deft image to-pdf DSCN0010.jpg -o photo.pdf
deft pdf merge letter.pdf photo.pdf fw9.pdf -o joined.pdf
deft pdf number joined.pdf -o numbered.pdf
deft pdf compress numbered.pdf --target-size 1MB -o application.pdf

Input

DSCN0010.jpg 157.9 KB · 640x480
DSCN0010.jpg
fw9.pdf 137.5 KB · 6 pages
Page 1Page 2Page 3
letter.docx 11.3 KB
Rendered by macOS Quick Look, first page

Rendered by macOS Quick Look, first page

Text inside
I am a test document
This is page 1
I am Calibri (Body) in font size 11

This is page two
It’s Arial Black in 16 point
It’s also in blue

Output

application.pdf 222.6 KB · 9 pages
Page 1Page 2Page 3
joined.pdf 220.9 KB · 9 pages
Page 1Page 2Page 3
letter.pdf 9.6 KB · 2 pages
Page 1Page 2
numbered.pdf 224.1 KB · 9 pages
Page 1Page 2Page 3
photo.pdf 158.6 KB · 1 page
Page 1
Automatic checks (2)
  • max_bytes: file = "application.pdf", bytes = 1048576
  • python: code = "import subprocess\ndef text(first, last):\n return subprocess.run(['gs', '-q', '-dNOPAUSE', '-dBATCH', '-sDEVICE=txtwrite', f'-dFirstPage={first}', f'-dLastPage={last}', '-sOutputFile=-', 'application.pdf'], capture_output=True, text=True, errors='replace').stdout\nn = int(subprocess.check_output(['gs', '-q', '-dNODISPLAY', '--permit-file-read=application.pdf', '-c', '(application.pdf) (r) file runpdfbegin pdfpagecount = quit'], text=True).split()[-1])\nw9 = subprocess.check_output(['gs', '-q', '-dNODISPLAY', '--permit-file-read=fw9.pdf', '-c', '(fw9.pdf) (r) file runpdfbegin pdfpagecount = quit'], text=True).split()[-1]\nassert n >= int(w9) + 2, n\nassert 'W-9' in text(n - int(w9) + 1, n - int(w9) + 1), 'the form is not last'\nassert 'W-9' not in text(1, 1), 'the letter is not first'\nassert str(n) in text(n, n).split(), 'last page has no number'\n"

Chinese page numbersPassed

给 f1040.pdf 每页底部加上“第 1 页”这样的页码,保存为 numbered.pdf。

deft pdf number f1040.pdf --format "第 {n} 页" -o numbered.pdf

Input

f1040.pdf 215.1 KB · 2 pages
Page 1Page 2

Output

numbered.pdf 227.9 KB · 2 pages
Page 1Page 2
Automatic checks (2)
  • pdf_pages: file = "numbered.pdf", pages = 2
  • pdf_changed: file = "numbered.pdf", from = "f1040.pdf", page = 1, min_difference = 0.01

Add page numbersPassed

Add page numbers like "Page 3 of 14" at the bottom of every page of paper.pdf. Save as numbered.pdf.

deft pdf number paper.pdf --format "Page {n} of {total}" -o numbered.pdf

Input

paper.pdf 992.5 KB · 14 pages
Page 1Page 2Page 3

Output

numbered.pdf 939.6 KB · 14 pages
Page 1Page 2Page 3
Automatic checks (2)
  • pdf_pages: file = "numbered.pdf", pages = 14
  • pdf_text: file = "numbered.pdf", contains = ["Page 1 of 14", "Page 14 of 14"], visible = true

Merge, number and stamp in one goPassed

Combine fw9.pdf and f1040.pdf, number the pages like 1/8, stamp every page with the word DRAFT, and save the result as packet.pdf.

deft pdf merge fw9.pdf f1040.pdf -o a.pdf
deft pdf number a.pdf --format {n}/{total} -o b.pdf
deft pdf watermark b.pdf --text DRAFT -o packet.pdf

Input

f1040.pdf 215.1 KB · 2 pages
Page 1Page 2
fw9.pdf 137.5 KB · 6 pages
Page 1Page 2Page 3

Output

a.pdf 191.3 KB · 8 pages
Page 1Page 2Page 3
b.pdf 204.3 KB · 8 pages
Page 1Page 2Page 3
packet.pdf 217.4 KB · 8 pages
Page 1Page 2Page 3
Automatic checks (3)
  • pdf_pages: file = "packet.pdf", pages = 8
  • pdf_text: file = "packet.pdf", contains = ["1/8", "8/8"], visible = true
  • pdf_changed: file = "packet.pdf", from = "fw9.pdf", page = 2, min_difference = 0.3