|
|
Thread Tools | Search this Thread |
08-02-2018, 07:16 PM | #1 |
Junior Member
Posts: 6
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; }" Code:
@page, html, body, div, p, blockquote { margin-right: 0; margin-left: 0; } 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 |
08-02-2018, 07:57 PM | #2 |
Bibliophagist
Posts: 35,393
Karma: 145435140
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Forma, Clara HD, Lenovo M8 FHD, Paperwhite 4, 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; } |
08-02-2018, 09:08 PM | #3 |
Junior Member
Posts: 6
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> |
08-02-2018, 10:35 PM | #4 |
creator of calibre
Posts: 43,856
Karma: 22666666
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) |
08-02-2018, 10:37 PM | #5 |
creator of calibre
Posts: 43,856
Karma: 22666666
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.
|
08-04-2018, 11:18 PM | #6 |
Junior Member
Posts: 6
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!
|
08-18-2018, 10:51 PM | #7 |
Junior Member
Posts: 6
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! |
08-21-2018, 02:23 PM | #8 | |
Wizard
Posts: 3,032
Karma: 52740263
Join Date: Feb 2012
Location: New England
Device: PW 1, 2, 3, Voyage, Oasis 2 & 3, Fires, Aura HD, iPad
|
Quote:
What error are you getting when you try to send it? Shari |
|
08-21-2018, 11:21 PM | #9 | |
Junior Member
Posts: 6
Karma: 10
Join Date: Aug 2018
Device: None
|
It's an email with the subject "There was a problem with the document(s) you sent to Kindle." It says:
Quote:
|
|
08-21-2018, 11:25 PM | #10 |
creator of calibre
Posts: 43,856
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
You cannot send new style MOBI via send to kindle. You can send either old style MOBI or joint MOBI.
|
08-21-2018, 11:36 PM | #11 |
Junior Member
Posts: 6
Karma: 10
Join Date: Aug 2018
Device: None
|
When I said new style MOBI, I meant the ones generated with --mobi-file-type=both, as described in a previous message. That's what gave the error I posted.
Sorry for the confusion! |
08-22-2018, 01:20 PM | #12 | |
Wizard
Posts: 3,032
Karma: 52740263
Join Date: Feb 2012
Location: New England
Device: PW 1, 2, 3, Voyage, Oasis 2 & 3, Fires, Aura HD, iPad
|
Quote:
Shari |
|
|
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 |