19 lines
1.5 KiB
Python
19 lines
1.5 KiB
Python
"""Inspect the browser-generated PDF without changing it or its originals."""
|
|
from pathlib import Path
|
|
import json, hashlib, sys
|
|
from pypdf import PdfReader
|
|
root=Path(__file__).resolve().parent.parent
|
|
private=root/'storage/app/private/investmoz-v2/portal-audit'
|
|
file=private/'consumer-land-derived-20261010.pdf'
|
|
reader=PdfReader(file)
|
|
texts=[p.extract_text()for p in reader.pages]
|
|
text='\n'.join(texts)
|
|
for expected in ['Terra e DUAT','Moçambique (MZ)','Portugal (PT)','Referência interna','dados guardados']:assert expected in text,expected
|
|
for unwanted in ['Terminar sessão','Caminho de navegação','Contactar Apoio ao Investidor','ç','ã','â€']:assert unwanted not in text,unwanted
|
|
assert not reader.is_encrypted
|
|
assert not reader.get_fields()
|
|
assert not reader.trailer['/Root'].get('/OpenAction')
|
|
proof={'result':'passed'if '--visually-reviewed' in sys.argv else 'text_checked_pending_visual','sha256':hashlib.sha256(file.read_bytes()).hexdigest(),'pages':len(reader.pages),'page_text_lengths':[len(t)for t in texts],'menus_omitted':True,'countries_separate':True,'visual_review':'all rendered pages inspected'if '--visually-reviewed' in sys.argv else 'pending','tagged':bool(reader.trailer['/Root'].get('/StructTreeRoot')),'accessibility_integral':'not accepted','form':'filled static preparation copy; source original unchanged','active_writes':0}
|
|
(private/'consumer-pdf-presentation-qa.json').write_text(json.dumps(proof,ensure_ascii=False,indent=2),encoding='utf-8')
|
|
print(json.dumps(proof,ensure_ascii=False))
|