What I have :
1. A bunch of pnm images generated by xsane from a manual.
2. Subsequently, these images are split up and cleaned using unpaper.
3. A working installation of ghostscript on Ubuntu.
4. A growing knowledge of the internal structure of PDFs as gleaned from the
Adobe PDF reference and the pdfmark reference.
5. A fine OCR tool (which is accurate enough for my purposes) - tesseract.
6. The following shell script that I wrote :
(just a segment)
<within a loop>
convert -density 300 outputimage-$m.pgm outputimage-$m.tiff
tesseract outputimage-$m.tiff outputimage-$m
rm outputimage-$m.tiff
convert -density 300 outputimage-$n.pgm outputimage-$n.tiff
tesseract outputimage-$n.tiff outputimage-$n
rm outputimage-$n.tiff
potrace --level3 --backend postscript -r300 outputimage-$m.pgm -o
page-$m.ps
potrace --level3 --backend postscript -r300 outputimage-$n.pgm -o
page-$n.ps
echo "[ /Author (User)
/Creator (User)
/Producer (Ghostscript+potrace)
/Keywords (`cat outputimage-$m.txt`)
/DOCINFO pdfmark
/F (outputimage-$m.txt) (r) file def
[ /_objdef {mystream} /type /stream /OBJ pdfmark
[ {mystream} F /PUT pdfmark
[ /MyPrivateAnnotmyStreamData {mystream}
/SubType /Text
/Rect [ 10 10 30 30 ]
/Contents (`cat outputimage-$m.txt`)
/SrcPg 1
/Open false
/Color [1 1 0]
/Title (Tesseract - OCR)
/ANN pdfmark
[ /Name <feff 0041 0073>
/FS<<
/Type /Filespec
/F (outputimage-$m.txt)
/EF << /F {fstream} >>
>>
/EMBED pdfmark
[ /PageMode /UseOutline
/Page 1 /View [/Fit]
/DOCVIEW pdfmark
[ /Subtype /Text
/Title (Tesseract - OCR)
/Alt (`cat outputimage-$m.txt`)
/StPNE pdfmark
[ {Catalog} <</Markinfo <</Marked true>>>> /PUT pdfmark" > pdfmarks-$m
gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -r300x300 -sPAPERSIZE=letter -dDOPDFMARKS -dPDFSETTINGS=/ebook -dPermissions=-4 -sOutputFile=pageannotated-$m.pdf
page-$m.ps pdfmarks
<loop ends>
pdftk pageannotated-*.pdf cat output pdfjoined.pdf
What I do not have :
1. Properly created PDFs that are searchable.
Any ideas how one might embed OCR'ed text invisibly behind the page ?
I am aware of the amazing tool called gscan2pdf that does what I am seeking
to do here using a perl library called PDF2:API. That tool however makes
temporary copies of all the pnm and other files on the way and requires a
gigantic amount of temporary storage space (think 10G+) for the number of
pages I am trying to put together in a searchable PDF manual (think 1400
pages).