Register Guidelines E-Books Today's Posts Search

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: 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; }"
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, 115 views)
File Type: mobi without_margins.mobi (8.1 KB, 121 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: 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;
}
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: 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>
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: 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)
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: 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.
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: 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!
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: 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!
otw-adt is offline   Reply With Quote
Old 08-21-2018, 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: 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:
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
Old 08-21-2018, 11:21 PM   #9
otw-adt
Junior Member
otw-adt began at the beginning.
 
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:
The following document, sent at 06:47 AM on Sat, Aug 18, 2018 GMT could not be delivered to the Kindle you specified:
* the pier in santa monica.mobi


The Kindle Personal Document Service can convert and deliver the following types of documents:
  • Microsoft Word (.doc, .docx)
  • Rich Text Format (.rtf)
  • HTML (.htm, .html)
  • Text (.txt) documents
  • Archived documents (zip , x-zip) and compressed archived documents
  • Mobi book

Images that are of type JPEGs (.jpg), GIFs (.gif), Bitmaps (.bmp), and PNG images (.png).
Adobe PDF (.pdf) documents are delivered without conversion to Kindle DX, Second Generation and Latest Generation Kindles.

Adobe PDF (.pdf) can be converted to Kindle format and delivered on an experimental basis.

If the document that failed belonged to one of the above document types, please ensure the document is not password protected or encrypted. Note that the Latest Generation Kindles support password protected PDFs.

Helpful tips for personal document attachments:
  • The file size of each attached personal document should be less than 50MB (before compression in a ZIP file)
  • The email submitted should not contain more than 25 attached personal documents
This doesn't seem to be entirely new. We currently use an entirely different, non-Calibre system to create old format MOBI files, and users have reported that converting them to the newer MOBI format in Calibre and using Send to Kindle fails with the same message. I'd thought that might get fixed when we changed the HTML file we generate MOBIs from, but that doesn't seem to be the case.
otw-adt is offline   Reply With Quote
Old 08-21-2018, 11:25 PM   #10
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: 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.
kovidgoyal is offline   Reply With Quote
Old 08-21-2018, 11:36 PM   #11
otw-adt
Junior Member
otw-adt began at the beginning.
 
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!
otw-adt is offline   Reply With Quote
Old 08-22-2018, 01:20 PM   #12
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: 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:
Originally Posted by otw-adt View Post
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!
That's exactly what I send, and sent yesterday using the Send to Kindle app, and then I sent a different one of the same type via email. Both came through just fine.

Shari
shalym is offline   Reply With Quote
Reply


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 06:46 PM.


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