Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Conversion

Notices

Reply
 
Thread Tools Search this Thread
Old 08-02-2018, 07:16 PM   #1
otw-adt
Junior Member
otw-adt began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Aug 2018
Device: None
HTML to MOBI via command line: Can't remove left and right page margins

Hello! I'm part of the Archive of Our Own development team, and we'd like to use Calibre's command line interface to offer MOBI downloads of our users' stories. Our users strongly prefer MOBI files with no left or right margins at all, but we're having trouble achieving that. If it's relevant, you can see our planned implementation of Calibre in this pull request. The process amounts to the following:

First, we create an HTML file. Here's a Gist with an example HTML file.

Then we convert that HTML file to MOBI using the following command:

Code:
ebook-convert input_file output_file --input-encoding="utf-8" --use-auto-toc --title="story title" --authors="authors" --comments="story summary" --tags="tag" --pubdate="date" --chapter="//h:body/h:div[@id='chapters']/h:h2[@class='toc-heading'] | //h:body/h:div[@id='chapters']/h:div[@class='meta group']/h:h2[@class='heading'] | //h:body/h:div[@id='preface' or @id='afterword']/h:h2[@class='toc-heading']" --mobi-ignore-margins --remove-paragraph-spacing --extra-css=".meta dt { font-weight: bold; }"
We've tried adding the following CSS to the HTML file's stylesheet without any luck:

Code:
@page, html, body, div, p, blockquote { margin-right: 0; margin-left: 0; }
We tried specifying 0pt as well, since we know Calibre uses pts for margins.

We also tried including the above CSS with the --extra-css option, removing the --mobi-ignore-margins option, and using --margin-left="0" and --margin-right="0".

We even tried completely removing the CSS that's in the HTML file, just in case one of our styles was to blame.

Finally, I used the KindleImport plugin for Sigil to compare a MOBI file that didn't have margins with the MOBI file we were generating using Calibre. The file without margins had margin attributes (leftmargin="0" bottommargin="0" topmargin="0" rightmargin="0") added to the body tag, so I added those to our HTML file's template. Unfortunately, it didn't help, and when I examined the resultant MOBI file using Sigil, the margin attributes had been removed from the body element.

For reference, I've attached a MOBI file without margins (without_margins.mobi), which we produced using our old system, and one with margins that we produced using Calibre (with_margins.mobi). We've tried versions 3.27.1 and 3.28.0 of Calibre, but we just can't seem to make the margins go away.

We'd be very grateful for any help you can provide!

Thanks,
Sarken
Attached Files
File Type: mobi with_margins.mobi (17.5 KB, 16 views)
File Type: mobi without_margins.mobi (8.1 KB, 18 views)
otw-adt is offline   Reply With Quote
Old 08-02-2018, 07:57 PM   #2
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 4,828
Karma: 21644938
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Aura One, Aura H2O, Aura HD, Nexus 7 HD, iPad Air, Tolino epos
I've done conversions to mobi from the GUI not from the command line but I ended up using the following in extra.css.

Code:
body, p, div, .calibre1, .calibre2, .calibre3, .calibre4, .calibre5, .calibre6, .calibre7 {
    margin-left: 0;
    margin-right: 0;
}
Not sure how much use this will be to you but good luck.
DNSB is offline   Reply With Quote
Old 08-02-2018, 09:08 PM   #3
otw-adt
Junior Member
otw-adt began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Aug 2018
Device: None
Thank you for the suggestion! Unfortunately, it didn't seem to have any effect.

I have another bit of information to add, though, in case it's helpful. If I use the --extract-to option, the pretty.html file that is extracted has height and width attributes on each paragraph and blockquote tag, like so:

Code:
<p height="0pt" width="2em">Summary</p>
<blockquote height="2em"><blockquote width="2em"> <i>Cronut wayfarers shoreditch.</i> </blockquote></blockquote>
<pagebreak></pagebreak><p height="2em" width="2em"> </p>
<p height="0pt" width="2em">Lorem ipsum dolor amet iPhone cardigan iceland man braid sriracha, hashtag gentrify. Meditation street art shabby chic, yuccie photo booth kogi humblebrag venmo ugh. Art party freegan godard pickled echo park blog. Tofu gentrify four dollar toast, migas raclette 8-bit cornhole pour-over. Kogi neutra chartreuse post-ironic everyday carry readymade portland ennui franzen kickstarter umami thundercats. Vice literally fanny pack, cloud bread la croix succulents sriracha flexitarian typewriter. Hammock lo-fi live-edge single-origin coffee umami.</p>
Unfortunately, specifying a width in the CSS (e.g. p { width: 100% !important; }) doesn't change the appearance of the MOBI or the HTML in pretty.html.
otw-adt is offline   Reply With Quote
Old 08-02-2018, 10:35 PM   #4
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 33,219
Karma: 10205092
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Convert to azw3 not mobi and you will be fine. MOBI is an obsolete format does not have any support for CSS, so CSS gets mapped to custom HTML attributes. Only a very liited subset of CSS can be supported in this fashion.

kindlegen will for instance vreate mobi files that are actually azw3 files with an included mobi stub for older devies (you can do the same thing in calibre using --mobi-type=joint)
kovidgoyal is offline   Reply With Quote
Old 08-02-2018, 10:37 PM   #5
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 33,219
Karma: 10205092
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
And just FYI (IIRC) width and height in mobi tags refer to indent and margin respectively.
kovidgoyal is offline   Reply With Quote
Old 08-04-2018, 11:18 PM   #6
otw-adt
Junior Member
otw-adt began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Aug 2018
Device: None
We do need to continuing supporting the old mobi format, so it's disappointing we can't reproduce the existing margin-less behavior with Calibre, but thank you for the information!
otw-adt is offline   Reply With Quote
Old 08-18-2018, 10:51 PM   #7
otw-adt
Junior Member
otw-adt began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Aug 2018
Device: None
We considered making the switch to --mobi-file-type=both after all, and I just wanted to come back here and give a heads up for anyone who might come across this thread in the future: neither AZW3 nor the new or both MOBI formats will work with Amazon's Send to Kindle option, so if Send to Kindle support is important for your users, you'll have to stick with the old MOBI format and all of its limitations.

Hope this helps save someone else some time!
otw-adt is offline   Reply With Quote
Old Today, 02:23 PM   #8
shalym
Wizard
shalym ought to be getting tired of karma fortunes by now.shalym ought to be getting tired of karma fortunes by now.shalym ought to be getting tired of karma fortunes by now.shalym ought to be getting tired of karma fortunes by now.shalym ought to be getting tired of karma fortunes by now.shalym ought to be getting tired of karma fortunes by now.shalym ought to be getting tired of karma fortunes by now.shalym ought to be getting tired of karma fortunes by now.shalym ought to be getting tired of karma fortunes by now.shalym ought to be getting tired of karma fortunes by now.shalym ought to be getting tired of karma fortunes by now.
 
shalym's Avatar
 
Posts: 2,180
Karma: 22538140
Join Date: Feb 2012
Location: New England
Device: KPW 1, 2, and 3, Voyage, Oasis 2, Kindle Fire, Kobo Aura HD, Onyx Lynx
Quote:
Originally Posted by otw-adt View Post
We considered making the switch to --mobi-file-type=both after all, and I just wanted to come back here and give a heads up for anyone who might come across this thread in the future: neither AZW3 nor the new or both MOBI formats will work with Amazon's Send to Kindle option, so if Send to Kindle support is important for your users, you'll have to stick with the old MOBI format and all of its limitations.

Hope this helps save someone else some time!
Hmm...I send dual (new) mobis using Send to Kindle all the time. I did it again just now, to make sure that it was still working for me. I also tried emailing a dual mobi to my Kindle archive, and that worked as well.

What error are you getting when you try to send it?

Shari
shalym is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to completely remove the right and left margins? tiramisù Amazon Kindle 103 05-04-2015 12:22 AM
HTML to MOBI command line convert not generating default cover? DarkAbsynthe Conversion 3 10-19-2013 11:53 PM
EPub>Mobi>Kindle 3 large left margins Zenthor Calibre 14 11-02-2010 08:37 AM
Mobi Creator and the command line Ortep Kindle Formats 1 06-11-2009 09:00 AM


All times are GMT -4. The time now is 09:12 PM.


MobileRead.com is a privately owned, operated and funded community.