Here is one way, which would require some not so common tools:
- ocrodjvu
- pdfbeads, that has it's own requirements which can be found by Google
We can use djvu2hocr
command (from ocrodjvu
package) to extract hidden text layer from DjVu file (it doesn't do any OCR or similar, it just extracts text layer with geometry), i.e.:
djvu2hocr -p 10 sample.djvu | sed 's/ocrx/ocr/g' > pg10.html
sed
intervention corrects class names in output hOCR (which is just simple HTML file)
Now we extract DjVu page to TIFF format with:
ddjvu -format=tiff -page=10 sample.djvu pg10.tif
so that we end with these file in out work folder:
sample.djvu
pg10.html
pg10.tif
This is where pdfbeads
comes in play, and we simple execute:
pdfbeads -o pg10.pdf
then this nifty program takes care of everything that's inside this folder (HTML and TIFF files with same base name) and produces output PDF file with some by-products:
sample.djvu
pg10.html
pg10.tif
pg10.jbig2
pg10.pdf
pg10.sym
which is identical to input DjVu file and has text layer inside:
Comments summary:
Lengthy comments below discuss representing smaller images from DjVu document page as separate objects, which is not easily possible because DjVu document page is itself just a single image with optional text layer, with no "information" about smaller images as separate objects. If DjVu document has color images, then they'll be usually placed on background layer; in this case user can take advantage of tools like ddjvu
(extract only background layer) and imagemagick
(auto-crop) to output just images instead whole canvas, but it can't be automated for creating PDF output
Another saner, but slower approach is use of regular OCR GUI tools. gscan2pdf
(> 1.0) is suggested as possible candidate for Linux PC