1. Given a pdf file, and a html file in hocr format for the OCRed text, can we merge the OCRed text into the pdf file, so that the new pdf file can be searchable for text?

    For example, I have a pdf by scanning without searchable text, about 5MB. I convert it to a djvu file and then split it into single-page tiff files, and then merge some hocr files for the pages with the tiff files using pdfbeads. Now my new pdf file is 23MB. So I would like to know if I can merge the hocr files directly to the original pdf file, to achieve a much smaller size than 23MB?

  2. Conversely, given a pdf file with OCRed text, can we export its OCRed text into a html file in hocr format?

    Can we also remove the OCRed text from the pdf file, without printing to pdf file?

  3. If not limited to hocr format, are there other formats which have programs to do the above merging and/or extraction?


1 Answer 1

  1. Probably yes - there is hocr2pdf tool (from ExactImage) available, but I haven't tried it to be able confirm

Some notes: if you just want to make searchable PDF you can use simpler GUI programs like, gscan2pdf and others, which allow pdf input. You can also make searchable PDF with recent versions of tesseract.

  1. In html file you can export with pdf2html from xpdf toolkit, but I would guess that you wont be very happy with the results, and they wont be in hocr format.

For your last question, I don't know, but you surely can remove more easily is text is OCRed. Just FYI, using djvudigital to make HQ djvu from pdf, you can easily remove the text with djvused from djvulibre.

Forgot to mention LibreDraw, which is excellent for editing PDF files. I don't have right here OCRed PDF so don't know what it will give, but it should be worth a try.

  • Thanks. 1. AFAIK, hocr2pdf takes in images in tiff formats.
    – Tim
    Commented Nov 27, 2014 at 16:58
  • Yes for overlaying hocr text, but I didn't tried it as mentioned
    – zetah
    Commented Nov 27, 2014 at 17:06
  • Is there a program doing the opposite of pdf2html? I think I shouldn't limit myself to hocr format.
    – Tim
    Commented Nov 27, 2014 at 17:09
  • Well HOCR, is XHTML so it is XML, and there are tools many ways for producing PDF out of it, but that's involved, and other formats like EPUB or else... If I would have to do something like (assuming making PDF image for printing) then I'd use Python and convert HOCR to SVG. From SVG I'll have much more options, but that's just me...
    – zetah
    Commented Nov 27, 2014 at 17:13
  • By converting to SVG, do you not keep the scanned images in the original pdf file? That is why I am wondering about "merging" text with scanned image in original pdf
    – Tim
    Commented Nov 27, 2014 at 17:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .