I've read all similar questions here, and most of the answers suggest using calibre for this task, however, I'm trying to improve the output. Here I explain:

I've extracted text from a PDF using pdftohtml (part of Poppler) using -c and -s options. I got an HTML that contains text and surprisingly text is correctly un-wrapped, so the main problem of extracting text from PDFs is gone. If I feed this Html to calibre (specifically to ebook-convert) I get a dirty epub with the following problems that need to be solved:

  • the title of the document repeats at header of every page -> it should be removed
  • page numbers were in the pdf and appear in the epub, that make no sense -> they should be removed
  • footnotes appear as normal text -> they should be recognized as footnotes and properly linked
  • text is "dirty": there are many different classes for <p> paragraphs, with "absolute position" attributes, leading to messy text: sentences are in the correct order, but the different settings for every class make the text rendered slightly under, above, before or after (a few pixels) the place where it should be -> all the classes should be removed and replaced only with <b> and <i> when needed
  • titles appear in bold, and are somehow recognized by calibre heuristic conversion, however, this process is not always correctly performed
  • additionally, no table of contents is created, and should be

Is there any software or library that performs these tasks? I'm not a developer, but I'd rather code something than editing every book by hand. I can't believe that in 2021 there's not a program that does that, since open source world is so vast and rich with every kind of tools. I think that what I'm explaining is a very common need, and that thousands of people have felt the same need. Looking forward to hear your suggestions.

  • The issue with at least the first 3 points is that they are in the text of the pdf - There is no general rule to recognise plain text from the cases you have given. It is all text. The reason for there not being code to do this is people will look for the source that created the pdf or a version in a structured format e.g. epub and that works in most cases. Getting structured information from a pdf is a difficult problem. You can probably write scripts for each book to remove page numbers and title as they will be constant in the book
    – mmmmmm
    Commented May 3, 2021 at 10:48

2 Answers 2


Because PDF describes page formatting, rather than being an editable, smoothly-flowing document, it is difficult to convert to word-processing document format, such as Word's DOCX and LibreOffice's ODT. In fact, some PDF files have no text, only images of the text, so optical character recognition (OCR) is needed to convert the image back to text. Such conversion needs some "artificial intelligence" to make a decent document.

The cleanest and most accurate conversion I've seen is using online sites to convert PDF to document format, such as PDF2Doc, FreeConvert and Zamzar. Once the converted file is downloaded, Calibre does a very good job of converting DOCX, ODT and similar word-processing documents to EPUB and other etext publishing formats.

Of course, this two-step process is a bit of a nuisance, it exposes your text to a third party, and the conversion may still be far from perfect, particularly where OCR is used ... but it's usually faster and easier than converting PDF to EPUB manually.


The answer is that Calibre is going to give you the best results on converting a PDF to an ePub with the minimum of pain, and then you can use the editor in Calibre to clean up any issues. Trying to start from scratch with the base text extracted from the PDF is going to involve a LOT of cleaning things up manually that Calibre can often do on its own.

That said, PDF is the worst of all eText formats because it is, as @drmishe-pippik said, a PAGE format, not a DOCUMENT format. PDF is great when you want to distribute something that is going to end up on a physical piece of paper, assuming you make the PDF to match the physical site of the paper someone will print on (Look up dealing with US Letter v A4 for lots more "Fun With PDFs!”), but it is not at all a good format for producing an ebook that allows changing the font size, margins, width, styling, etc.

Not the answer you're looking for? Browse other questions tagged or ask your own question.