How to convert purchased Amazon eBooks to PDF format:
This is a hard problem. However, I have a solution, but Linux users (including myself) aren't going to like it.
First off, let me say: DON'T STEAL BOOKS OR ANYTHING ELSE! BUY THEM! PAY AUTHORS FOR THE THOUSANDS OF HOURS THEY PUT INTO THEIR CRAFT AND THEN WRITING ABOUT IT. I'm going to explain how to do some things but DON'T STEAL BOOKS. This assumes you have PURCHASED AN EBOOK and are just PISSED OFF THAT WITH THAT PURCHASE YOU DON'T HAVE THE FREEDOM TO READ IT AS A PDF (A FREEDOM WHICH I THINK YOU SHOULD HAVE).
Also, there are possibly other paths to accomplish what I'm about to describe. If I see a possible alternate path I'll mark it with the word "clue", so watch for those and head down those paths to write your own improved answer if you wish.
1) Get the eBook from Amazon onto your PC for "offline reading"
What you need is the Kindle App "for PC & Mac": https://www.amazon.com/kindle-dbs/fd/kcp. However, don't use this link to download it, because the current version as of 5 Mar. 2018 is 1.21 Build 48017, and all versions after Kindle for PC 1.17 use a new "KFX format" which is currently uncrackable.
Clue: go crack the KFX format. We will all thank you for it.
Now, turn off your Ubuntu computer and boot into Windows.
Clue: You may be able to do this using Wine or by installing Windows 10 for free into a virtual machine inside Ubuntu instead.
So, go download an old version of the "Kindle for PC" app here:
https://kindle-for-pc.en.uptodown.com/windows/old. You must use version 1.17 or earlier for this to work. I used 1.16 Build 44025.
Install the App. Log in with your Amazon account, right-click the ebook you want, and go to "Download."
This will save it on your PC for offline viewing. You'll now find your downloaded book as a ".azw" file in "C:\Users\MY_USERNAME\Documents\My Kindle Content". For ex: "C:\Users\MY_USERNAME\Documents\My Kindle Content\B08137WHQ_EBOK.azw".
Clue: later versions of the Kindle for PC app will give you a folder with that name containing several other files instead, such as ".azw", ".azw.md", and ".azw.res". Apparently this is the new, uncrackable "KFX" format. Go crack it!
Clue: There is also a Chrome App called "Kindle Cloud Reader." You can install it and download your book for offline viewing too, but it uses a different format too. See comments under my question. On Windows you can find its offline book contents under the hidden folder "C:\Users\MY_USERNAME\AppData\Local\Google\Chrome\User Data\Default\databases\https_read.amazon.com_0". It contains, for example, two files named "85" and "86", with no file extension, but one is clearly the book since it's a few MB, while the other is 44KB or so. On Linux you can do a find in your home directory to find this location with
sudo find . -iname \*amazon\*. I found the folder in: "~/.config/google-chrome/Profile 1/databases/https_read.amazon.com_0".
2) Remove the "Digital Rights Management" (DRM) from the .azw file so you can read the eBook using non-Amazon software.
In short: DRM sucks. If you're an author, don't do that crap! Just sell digital PDFs on Gumroad instead (Update: LeanPub may be a better option instead!).
Download it from GitHub here: https://github.com/apprenticeharper/DeDRM_tools/releases. Notice that the release notes state: "This release does not include any support for the KFX format Kindle ebooks that are often downloaded when using Kindle for PC/Mac 1.19 or later."
Click the GitHub link to download "DeDRM_tools_6.5.5.zip", then extract the zip file so you can find the "DeDRM_calibre_plugin" folder it contains.
Now go install the Calibre ebook reader for Windows 64-bit:
https://calibre-ebook.com/download. I'm using "calibre-64bit-3.18.0.msi".
Clue: I'm actually using this in Windows, but maybe you can get it to work in Linux, since Calibre has a Linux installation page too. DeDRM also contains some good notes you are about to need to help you out if you want to pursue this. See the readme you just extracted above here: "DeDRM_calibre_plugin\DeDRM_plugin_ReadMe.txt". It contains a rather confusing section (for me at least) titled "Linux Systems Only".
Install the DeDRM plugin:
Once Calibre is installed, open it up. Then go to "Preferences" --> "Advanced" section --> Plugins. Choose "Load plugin from file" then find your DeDRM .zip file in the unzipped folder from above. You're looking for "DeDRM_calibre_plugin\DeDRM_plugin.zip". Choose this plugin then click "Open" and "Apply."
Now click "Add books" in Calibre and go find the .azw file we previously downloaded using Kindle for PC 1.16 (1.17 or earlier). It will import it and automatically use DeDRM to remove the DRM crap!
You should now be able to open the eBook in Calibre for reading. Double click the book in Calibre to verify it opens up properly and is readable. It it works, all is well so far.
Clue: If in Windows this works flawlessly. If in Linux you may have to fight it with the readme file above, to get Wine and Python and stuff to all work right--I couldn't figure it out in Linux.
3) Convert the de-DRM'ed eBook to PDF!
Select the book in Calibre and click "Convert books" at the top. Choose "PDF" in the "Output format" drop-down box at the top-right of the window that pops up. You may now click "Ok" to do the conversion, OR (optionally) change a few quick settings first--as described below!
- Select "Page setup" first and make sure "Input profile" is set to "Default Input Profile" and "Output profile" is set to "Default Output Profile".
- Select "Structure detection" and delete all text from the "Insert page breaks before (XPath expression)" box if you'd like the PDF to take up fewer pages by not forcing page breaks between every section and sub-section in the ebook.
Click "Ok" to convert the ebook to PDF! This took ~2 min for me on an eBook ~100 pages in length and 3 MB in size.
Done! Your ebook PDF is now located in your "Calibre Library" folder here: "C:\Users\YOUR_USERNAME\Documents\Calibre Library\EBOOK_AUTHOR\EBOOK_TITLE\EBOOK_TITLE.pdf".
You'll also find a nice (de-DRMed I think) ".azw3" file in the same location as well, in case you want to use Calibre or other generic eBook readers to read the book instead!
Copy the PDF or .azw3 file to your Ubuntu machine, as desired, and voila!--use your favorite ebook reader (ex: Calibre) or PDF viewer (ex: FoxitReader) to view your ebook as a PDF!
Get Foxit Reader for taking notes inside digital PDFs:
Foxit Reader (click here then go to "Free Foxit Reader Download") is great because it has awesome highlighting and comment tools to underline things, highlight, or take notes, and it is cross-platform (Windows, Mac, Linux, & others) and free as in "no-cost" (but not free as in open source!).
AND REMEMBER: DON'T STEAL! Buy the book and give the authors their hard-earned money! Encourage authors to sell PDFs (ex: via Gumroad like I do) (Update: LeanPub may be a better option instead!) instead of DRMed garbage.
But if you steal you are ruining the system. DRM might suck, but you don't have to suck too!