How do you migrate ibooks from Books on iPad to Kindle?

Migrate from iPad to Kindle via MacOs Big Sur with iCloud Drive and Calibre

Caveats

  • I migrated via a Mac computer, running Big Sur. This uses Finder to sync with the iPad. Older versions of MacOS (IDK which ones) used iTunes, and this answer doesn't apply to those, or to Windows or other computers.
  • The process was long and arduous and I undoubtedly did not capture every step perfectly. If you find errors below, feel free to correct them or comment and I will.
  • Not all books migrated. Some had DRM, some had other issues. The process below does not document the errors, it only documents how to blindly migrate the books that migrate easily by following these steps and ignoring errors. If it's important to you to migrate every book (which may not even be possible) you'll have to pay close attention and read between the lines.
  • This focuses on epub files, and ignores PDFs and other things. Once you've completed this you'll know what to do with PDFs.
  • This assumes some working knowledge of settings in iPad and Kindle, good knowledge of Finder advanced features, and knowledge of how to get around the system in Terminal and run shell commands and simple scripts of 2 or 3 lines from the command line. Sorry, this is not for beginners.

Summary

The iPad stores books in ePub format, uncompressed and expanded into packages or folders. We’ll copy them to the Mac, retrieve them from the secret-double-hidden folder they are in, convert them into compressed single-file ePub format, convert those using third party software Calibre into to MOBI files that Kindle can read, and move those to the Kindle.

Step 1: Sync books from iPad to MacOs using iCloud Drive


 On the iPad enable iCloud Drive and enable it specifically for iBooks.  On the iPad I was working with this was already done so I can’t detail the steps, but they are in Settings. 
 Plug the iPad into the Mac and open Finder. Remember, this is for Big Sur and other recent versions of MacOs that don't use iTunes for this.  The iPad will appear in the LHS navigation bar.  Go there and make sure it works.  You will not see the Books folder there, but you should see some things just to confirm the iPad is connected.

If you've never done this, it will take a while for iCloud Drive to sync. Anywhere from seconds to half an hour. Wait. 
 Then in Terminal run both the following to open the iBooks locations:

open ~/Library/Mobile\ Documents/iCloud\~com\~apple\~iBooks/Documents
open ~/Library/Containers/com.apple.BKAgentService/Data/Documents/iBooks

You can find more details on this step in this Question 
 You'll see your books in one or both of the two windows that open.  You’ll need to repeat Step 2 below for each folder if there are books in both. I can't find any way other than the "open" command to get to these folders! You can't cd to them and can't navigate to them in Finder by clicking or using Go...

Step 2: Copy the synced books to an ordinary folder


 Create a folder for further work.  Here I'll use ~/Downloads/iBooks.

Go to each of the two folders you opened with “open” in the last step, select all files, Copy them to ~/Downloads/iBooks eg with Ctrl-A Ctrl-C Ctrl-V.

This will take some time.   Note, despite the time it took to sync iCloud Drive, these files were not synced to your computer! At this point the files are actually being copied from iCloud to your ordinary folder.  You’ll see each one update with a little timer.


 I'm not sure if you can eject the iPad at the end of Step 1, but you can definitely do it now. 


Step 3: Convert all the epub folders to compressed epub files



 Go to ~/Downloads/books. You’ll see your books as a bunch of epub files, but they aren’t files they are folders.  If you only have a few you can compress them by right-clicking in Finder, but I didn't do it that way. The following assumes you have a lot of books. 
 In Terminal go to the iBooks folder and create a new folder for the zipped epub files

cd ~/Downloads/iBooks
mkdir zipped


 Zip each epub folder into a file (following works in bash)

for f in *; do zip -r zipped/$f $f ; done

Step 4: Use Calibre to convert the epubs to mobis

  Download and install Calibre. During installation select the kind of Kindle you own.

Load your files: Run Calibre, click Add Books, navigate to the zipped folder you just created, select all your new epub files then click Open.

Convert them to Mobi: In the main Calibre window select all the books you just loaded, click Convert, click Ok. Watch the Jobs count in the bottom right corner, til it gets to zero. This might take a while.

Step 5: Collect all the mobi files

By default Calibre puts its converted files in ~/Calibre Library/Unknown. The last segment of that folder, “Unknown” may be different for you.  It’s the “book author” which for me was Unknown for every book I imported from iBooks. You'll need to explore the Calibre output folder to make sure of what's going on. The actual MOBI files for your books are scattered all over folders there so we'll collect them all in one place.

In Terminal:

cd ~/Calibre Library
cd Unknown (or wherever the books are)
find . -name \*.mobi -exec mv {} . \;
mkdir kindle
mv *.mobi kindle

Step 6: Copy the files to Kindle

Finally! Plug your kindle into your Mac. It’ll appear on the left in Finder. Open it, go to the Kindle's Documents folder then in Documents make a folder for all your migrated books called “iBooks” or whatever you want. You won't see the folder in the Kindle reader, you'll only see it here in Finder and it'll help you keep things organized.

Use finder to copy all the Mobi files from the kindle folder in step 5 to the iBooks folder you just created.

Eject the kindle with the Eject icon in Finder's LHS navigation bar.

The books will all appear in your Kindle Library. They will not have cover art and some other features may be missing. Calibre allows you to migrate cover art but I didn't do that. I didn't touch any Calibre settings or try any advanced features. There are other places you can read about doing those things. 



Happy reading!