Stack Exchange Network
Stack Exchange network consists of 181 Q&A communities including
Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack Exchange
Ebooks Stack Exchange is a question and answer site for ebook publishers and readers. It only takes a minute to sign up.
Sign up to join this community
Anybody can ask a question
The best answers are voted up and rise to the top
3 years, 7 months ago
I've used Calibre to convert Mobi/Epub to PDF. The overall output is good, however, the image is always not in good shape. For example,
How image shows in Kindle reader (Android app)
How image shows after conversion in PDF (w/ Calibre)
How can I keep the image not distorted when converted to PDF?
Oct 27, 2019 at 0:55
ZK Zhao ZK Zhao
121 1 1 silver badge 3 3 bronze badges
Converting from mobi to pdf is almost always going to be a problem. Both are rendered formats. The problem could come from anywhere. Two ideas:
First, try to obtain an epub copy instead of a mobi file. It's easier to convert from epub to pdf than from mobi to pdf.
Try decompiling the mobi file (go to mobileread to find a tool that can do so).
Possibly there is a setting in Calibre to preserve the image ratios. But really, this is asking calibre to do the impossible.
Oct 29, 2019 at 22:41
I have achieved a workaround to make images have correct aspect ratio in the output pdf!! I did this on MacOS but I imagine it would work on other platforms. It also leaves extra blank space and sometimes whole blank pages where there used to be a stretched image. Here are my steps. YMMV
I have a file Book.epub I want to convert to pdf using Calibre, but no matter what I try in Calibre settings, some of the images in Book.pdf have super weird aspect ratios.
Note: The random file names are actually named along the lines of xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.extension
Duplicate Book.epub to BookCopy.epub
Rename BookCopy.epub to BookCopy.zip
Unzip BookCopy.zip to folder BookCopy/
I use keka as my file archive tool but this probably isn’t important.
Folder structure of BookCopy/ follows:
- mimetype (no extension)
Figure out what is causing the weird aspect ratios
Find a page in BookCopy.pdf that has an image with an incorrect aspect ratio
Note the header that precedes this image. In my case this matches the title of that section in the PDF outline.
Find the xhtml file within OEBPS/ that matches this section
I skimmed through the randomHtmlName.xhtml files in Finder’s Column view and checked the header in the previews as I keyed through the files. These previews do not show the images, only text.
Open this randomHtmlName.xhtml in Chrome
For me Chrome would only open these files if I dragged them from Finder into the Chrome window
In Chrome, right click on the image and select Inspect
Play around with the HTML until the image has the correct aspect ratio
For me, this was as simple as editing the style attribute.
I changed this from
I did not need to change the separate width and height attributes
I’m not sure if this is the same issue that is causing everyone else’s aspect ratio problems
I checked another image and found that the style attribute had different width and height numbers
I need a way to find and replace all text that follows the same pattern as style="width:XX.XXem;height:XX.XXem;"
tool such as TextMate to run a regex find and replace across all the randomHtmlName.xhtml files
In the Find window I set the following:
Check the Regular Expression box
In Other Folder > Navegate to OEBPS
Click Find All to make sure it finds the patterns
Click Replace All to replace the patterns
Drag a randomHtmlName.xhtml file to Chrome to see if it changed the aspect ratio of images to be correct
If you previously had that file open in Chrome you may need to close the tab before reopening the file
Open Keka and set the compression method to Store / No compression.
Not sure if this is necessary but it’s what I did
Rename folder BookCopy/ to BookCopyFixed/
Using Keka compress BookCopyFixed/ to BookCopyFixed.zip
Rename BookCopyFixed.zip to BookCopyFixed.epub
In Calibre, right click on Book and select Open containing folder
In the folder, select cover.jpg and metadata.opf and copy them
Drag BookCopyFixed.epub into Calibre
In Calibre, right click on BookCopyFixed and select Open containing folder
In this new folder, delete metadata.opf and then paste
There should now be the correct cover.jpg and metadata.opf in this new folder
In Calibre, right click on Book and select Edit meta > Copy metadata
In Calibre, right click on BookCopyFixed and select Edit meta > Paste metadata
The title will now match the original so remember which is the new one!
In Calibre, select the new Book and convert to PDF
Other notes I learned while working on this that others may find
EpubToPdf is an alternative to using Calibre for EPUB > PDF conversion If you get the error [Errno 24] Too many open files when converting you can
increase the ulimit to resolve
it. Remember to set it back
when you’re done!
May 28, 2021 at 8:34
11 3 3 bronze badges
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our
Accept all cookies
Necessary cookies only