code='AX-017B'
p=pdf('文字付き原文.pdf',[code+'   QTY 3   15:00'])
with fitz.open(p) as doc:
    pix=doc[0].get_pixmap(matrix=fitz.Matrix(2,2))
    d=fitz.open();page=d.new_page(width=420,height=300);page.insert_image(page.rect,stream=pix.tobytes('png'));d.save(folder/'画像だけの原文.pdf',no_new_id=True);d.close()
txt1=run(['pdftotext','-layout',str(p),'-']).decode().strip()
txt2=run(['pdftotext','-layout',str(folder/'画像だけの原文.pdf'),'-']).decode().strip()
img=folder/'読み取り用.png';pix.save(img)
ocr=run(['tesseract',str(img),'stdout','-l','eng','--psm','6']).decode().strip()
assert code in txt1 and not txt2 and code in ocr, (txt1,txt2,ocr)
finish({'text':txt1,'image_text':txt2,'ocr':ocr},[['確認条件','読み出した行'],['文字入りPDF・テキスト抽出',txt1],['画像PDF・テキスト抽出','文字なし'],['画像を英語OCR',ocr]],'同じ英数字の連絡票を文字入りPDFと画像PDFに保存。PopplerのpdftotextとTesseractの英語OCRで比較しました。')
# PDF review notes: annotation vs baked PDF; actual rendering comparison.
共通関数・環境を含む全体の実行用ソースは https://kensetsu-app-navi.com/assets/v60/b/experiments.py.txt に掲載しています。
