Answers.Body: <p>There's a much simpler way. The culprit is in the <code>height</code> tag, which needs to be removed. Once removed, with only the <code>width</code> tag, browser computes the proper aspect ratio.</p>
  <p>To do this, add a rule in &quot;Look &amp; Feel/Transform HTML&quot; section which reads:</p>
  <ul>
  <li>if tag is img
  <ul>
  <li>remove attribute &quot;height&quot;</li>
  </ul>
  </li>
  </ul>
  <p><a href="https://i.sstatic.net/jSxV2.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/jSxV2.png" alt="enter image description here" /></a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-12-21T01:47:21.313Z
Answers.Text: This works perfectly for me in Calibre 6.26. Thank you very much!
Answers.UserDisplayName: Balthier
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-08T01:23:05.440Z
Answers.LastActivityDate: 2023-11-08T01:23:05.440Z
Answers.UserDisplayName: Yuriy Gettya
Answers.Body: <p>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:</p>
  
  <p>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. </p>
  
  <p>Try decompiling the mobi file (go to mobileread to find a tool that can do so). </p>
  
  <p>Possibly there is a setting in Calibre to preserve the image ratios. But really, this is asking calibre to do the impossible. </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-30T02:16:37.460Z
Answers.Text: Thanks. Converting from EPUB to PDF give me the same result; and there is no exact settings in Calibre (I only find `image cover ratio`, but it can't handle images for every other images)
Answers.UserDisplayName: ZK Zhao
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-01T12:22:15.397Z
Answers.Text: Rename the file extension of the epub file from .epub to .zip and then unzip the files. Find the image file and verify that it's dimensions are the correct ratios. Assuming that is so, then the problem is with the  css. (I provide some mobi friendly CSS for images here: http://www.imaginaryplanet.net/weblogs/idiotprogrammer/2019/06/random-publishing-tips-by-myself/
Answers.UserDisplayName: idiotprogrammer
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-01T12:24:21.100Z
Answers.Text: Formatting images for Kindle is REALLY HARD!  It sounds as though the original mobi used css which was suitable for one display width, but not for another. One of the problems is that mobi css does not support the max-width property..
Answers.UserDisplayName: idiotprogrammer
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-04T16:32:17.693Z
Answers.Text: This seems to me to be a common problem - have the same exact problem when converting from EPUB to PDF via Calibre. All images are stretched vertically and their proportion is never maintained, even if two settings are set: 1) `PDF Output` -> `Preserve cover ratio` (useless; only intended to keep same aspect ratio in the output file); 2) `Page setup` -> `Output profile`: "Tablet" (whose description states "does no resizing of images". Nothing works; images are always resized.
Answers.UserDisplayName: alelom
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-29T22:41:21.680Z
Answers.LastActivityDate: 2019-10-29T22:41:21.680Z
Answers.UserDisplayName: idiotprogrammer
Answers.Body: <p><strong>I have achieved a workaround</strong> 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. <strong>Here are my steps. YMMV</strong></p>
  <hr />
  <p>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.</p>
  <blockquote>
  <p>Note: The random file names are actually named along the lines of xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.extension</p>
  </blockquote>
  <ol>
  <li>Duplicate Book.epub to BookCopy.epub</li>
  <li>Rename BookCopy.epub to BookCopy.zip
  <ul>
  <li>(NOT BookCopy.epub.zip)</li>
  </ul>
  </li>
  <li>Unzip BookCopy.zip to folder BookCopy/
  <ul>
  <li>I use keka as my file archive tool but this probably isn’t important.</li>
  <li>Folder structure of BookCopy/ follows:</li>
  </ul>
  </li>
  </ol>
  <pre><code>        - BookCopy/
              - OEBPS/
                  - Styles/
                      - Style00.css
                      - Style01.css
                      - etc
                  - Images/
                      - randomImageName1.png
                      - randomImageName2.jpg
                      - etc
                  - content.opf
                  - cover.xhtml
                  - toc.ncx
                  - toc.xhtml
                  - randomHtmlName1.xhtml
                  - randomHtmlName2.xhtml
                  - etc
              - META-INF/
                  - container.xml
                  - calibre_bookmarks.txt
              - mimetype (no extension)
  </code></pre>
  <ol start="4">
  <li>Figure out what is causing the weird aspect ratios
  <ol>
  <li>Find a page in BookCopy.pdf that has an image with an incorrect aspect ratio</li>
  <li>Note the header that precedes this image. In my case this matches the title of that section in the PDF outline.</li>
  <li>Find the xhtml file within OEBPS/ that matches this section
  <ul>
  <li>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.</li>
  </ul>
  </li>
  <li>Open this randomHtmlName.xhtml in Chrome
  <ul>
  <li>For me Chrome would only open these files if I dragged them from Finder into the Chrome window</li>
  </ul>
  </li>
  <li>In Chrome, right click on the image and select Inspect</li>
  <li>Play around with the HTML until the image has the correct aspect ratio
  <ol>
  <li>For me, this was as simple as editing the style attribute.
  <ul>
  <li>I changed this from <code>style=&quot;width:150.00em;height:98.00em;&quot;</code> to <code>style=&quot;width:150.00em;&quot;</code></li>
  <li>I did not need to change the separate width and height attributes</li>
  <li>I’m not sure if this is the same issue that is causing everyone else’s aspect ratio problems</li>
  </ul>
  </li>
  <li>I checked another image and found that the style attribute had different width and height numbers
  <ul>
  <li>I need a way to find and replace all text that follows the same pattern as style=&quot;width:XX.XXem;height:XX.XXem;&quot;</li>
  </ul>
  </li>
  </ol>
  </li>
  </ol>
  </li>
  <li>Use a <a href="https://apple.stackexchange.com/a/82778">tool such as TextMate</a> to run a regex find and replace across all the randomHtmlName.xhtml files
  <ol>
  <li>In the Find window I set the following:
  <ul>
  <li>Find: <code>(width:\d+\.\d+em;)(height:\d+\.\d+em;)</code></li>
  <li>Replace: <code>$1</code></li>
  <li>Check the Regular Expression box</li>
  <li>In Other Folder &gt; Navegate to OEBPS</li>
  <li>Matching <code>*.xhtml</code></li>
  </ul>
  </li>
  <li>Click Find All to make sure it finds the patterns</li>
  <li>Click Replace All to replace the patterns</li>
  </ol>
  </li>
  <li>Drag a randomHtmlName.xhtml file to Chrome to see if it changed the aspect ratio of images to be correct
  <ul>
  <li>If you previously had that file open in Chrome you may need to close the tab before reopening the file</li>
  </ul>
  </li>
  <li>Open Keka and set the compression method to Store / No compression.
  <ul>
  <li>Not sure if this is necessary but it’s what I did</li>
  </ul>
  </li>
  <li>Rename folder BookCopy/ to BookCopyFixed/</li>
  <li>Using Keka compress BookCopyFixed/ to BookCopyFixed.zip</li>
  <li>Rename BookCopyFixed.zip to BookCopyFixed.epub</li>
  <li>Fix metadata
  <ol>
  <li>In Calibre, right click on Book and select Open containing folder</li>
  <li>In the folder, select cover.jpg and metadata.opf and copy them</li>
  <li>Drag BookCopyFixed.epub into Calibre</li>
  <li>In Calibre, right click on BookCopyFixed and select Open containing folder</li>
  <li>In this new folder, delete metadata.opf and then paste
  <ul>
  <li>There should now be the correct cover.jpg and metadata.opf in this new folder</li>
  </ul>
  </li>
  <li>In Calibre, right click on Book and select Edit meta &gt; Copy metadata</li>
  <li>In Calibre, right click on BookCopyFixed and select Edit meta &gt; Paste metadata
  <ul>
  <li>The title will now match the original so remember which is the new one!</li>
  </ul>
  </li>
  </ol>
  </li>
  <li>In Calibre, select the new Book and convert to PDF</li>
  <li><strong>Enjoy!</strong></li>
  </ol>
  <hr />
  <blockquote>
  <p>Other notes I learned while working on this that others may find
  useful:</p>
  <ul>
  <li><a href="https://github.com/Helias/EPUB-to-PDF" rel="nofollow noreferrer">EpubToPdf</a> is an alternative to using Calibre for EPUB &gt; PDF conversion</li>
  <li>If you get the error [Errno 24] Too many open files when converting you can <a href="https://stackoverflow.com/a/40716814">increase the ulimit to resolve
  it</a>. Remember to set it back
  when you’re done!</li>
  </ul>
  </blockquote>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-05-28T08:34:54.930Z
Answers.LastActivityDate: 2021-06-16T22:35:15.773Z
Answers.LastEditDate: 2021-06-16T22:35:15.773Z
Answers.UserDisplayName: evn
Body: <p>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,</p>
  
  <h3>How image shows in Kindle reader (Android app)</h3>
  
  <p><a href="https://i.sstatic.net/yYPBk.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/yYPBk.png" alt="enter image description here"></a></p>
  
  <h3>How image shows after conversion in PDF (w/ Calibre)</h3>
  
  <p><a href="https://i.sstatic.net/4eKWU.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/4eKWU.png" alt="enter image description here"></a></p>
  
  <p>How can I keep the image not distorted when converted to PDF? </p>
  
  <p>Thanks!</p>
  
Tags: <epub><calibre><mobi>
Title: How to convert epub/mobi to PDF without image distortion?
UserDisplayName: ZK Zhao
ThreadText: # How to convert epub/mobi to PDF without image distortion?
  
  (Asked by: username_0 on 2019-10-27)
  
  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)
  
  [![enter image description here](https://i.sstatic.net/yYPBk.png)](https://i.sstatic.net/yYPBk.png)
  
  ### How image shows after conversion in PDF (w/ Calibre)
  
  [![enter image description here](https://i.sstatic.net/4eKWU.png)](https://i.sstatic.net/4eKWU.png)
  
  How can I keep the image not distorted when converted to PDF?
  
  Thanks!
  
  **Tags:** epub, calibre, mobi
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2023-11-08. Score: 2
  
  There's a much simpler way. The culprit is in the `height` tag, which needs to be removed. Once removed, with only the `width` tag, browser computes the proper aspect ratio.
  
  To do this, add a rule in "Look & Feel/Transform HTML" section which reads:
  
  * if tag is img
    + remove attribute "height"
  
  [![enter image description here](https://i.sstatic.net/jSxV2.png)](https://i.sstatic.net/jSxV2.png)
  
  > **Comments:**
  > **username_2**: This works perfectly for me in Calibre 6.26. Thank you very much!  
  
  ---
  
  ### Answer by username_3 on 2019-10-29. Score: 1
  
  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.
  
  > **Comments:**
  > **username_0**: Thanks. Converting from EPUB to PDF give me the same result; and there is no exact settings in Calibre (I only find `image cover ratio`, but it can't handle images for every other images)  
  > **username_3**: Rename the file extension of the epub file from .epub to .zip and then unzip the files. Find the image file and verify that it's dimensions are the correct ratios. Assuming that is so, then the problem is with the  css. (I provide some mobi friendly CSS for images here: http://www.imaginaryplanet.net/weblogs/username_3/2019/06/random-publishing-tips-by-myself/  
  > **username_3**: Formatting images for Kindle is REALLY HARD!  It sounds as though the original mobi used css which was suitable for one display width, but not for another. One of the problems is that mobi css does not support the max-width property..  
  > **username_4**: This seems to me to be a common problem - have the same exact problem when converting from EPUB to PDF via Calibre. All images are stretched vertically and their proportion is never maintained, even if two settings are set: 1) `PDF Output` -> `Preserve cover ratio` (useless; only intended to keep same aspect ratio in the output file); 2) `Page setup` -> `Output profile`: "Tablet" (whose description states "does no resizing of images". Nothing works; images are always resized.  
  
  ---
  
  ### Answer by username_5 on 2021-05-28. Score: 1
  
  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
  
  (NOT BookCopy.epub.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:
  
  
  
          - BookCopy/
              - OEBPS/
                  - Styles/
                      - Style00.css
                      - Style01.css
                      - etc
                  - Images/
                      - randomImageName1.png
                      - randomImageName2.jpg
                      - etc
                  - content.opf
                  - cover.xhtml
                  - toc.ncx
                  - toc.xhtml
                  - randomHtmlName1.xhtml
                  - randomHtmlName2.xhtml
                  - etc
              - META-INF/
                  - container.xml
                  - calibre_bookmarks.txt
              - 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 style="width:150.00em;height:98.00em;" to style="width:150.00em;"
  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;"
  
  
  
  
  
  
  Use a 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:
  
  Find: (width:\d+\.\d+em;)(height:\d+\.\d+em;)
  Replace: $1
  Check the Regular Expression box
  In Other Folder > Navegate to OEBPS
  Matching *.xhtml
  
  
  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
  Fix metadata
  
  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
  Enjoy!
  
  
  
  Other notes I learned while working on this that others may find
  useful:
  
  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!
  
  
  ---
  
  