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 04-08-2014, 03:26 AM   #1
snoeki
Connoisseur
snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.
 
Posts: 62
Karma: 2030818
Join Date: Jan 2010
Device: Kindle paperwhite 2 & Kobo glo hd
Conversion epub-->azw3 with negative margins

I am looking for an option to convert my epub collection to azw3 and I would like to get negative margins for my kindle paperwhite 1.

I do this now manually and I change the css to this :

p {
margin-left: -40px;
margin-right: -40px;
margin-top: 0;
margin-bottom: 0;
text-indent: 1.2em
}

The margin-left and margin-right to -40px. I am looking for a way to do this when I convert the books to azw3 without having to change the css files manually.

The problems I get is that not all the css files are the same. Sometimes people use the p option and somtimes the div options or they put the margins in the body.

Is there a way to get this right while converting without doing anything manually?
snoeki is offline   Reply With Quote
Old 04-08-2014, 12:55 PM   #2
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Why don't you try putting the margins in the body?
eschwartz is offline   Reply With Quote
Old 04-09-2014, 07:44 AM   #3
snoeki
Connoisseur
snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.
 
Posts: 62
Karma: 2030818
Join Date: Jan 2010
Device: Kindle paperwhite 2 & Kobo glo hd
That's a good idea, but I don't seem to manage to get this automated. If I insert this in the extra css option while I convert I get second or third css file with this info and it will not work.

Perhaps I can create a feature request that would let you add extra CSS where the classes you have the extra CSS overwrite the same classes in the main CSS. Or does anyone here see an option I overlook?

Last edited by snoeki; 04-09-2014 at 08:20 AM.
snoeki is offline   Reply With Quote
Old 04-09-2014, 05:12 PM   #4
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 29,809
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Rather than do this, you might want to do a tiny hack on your kindle.

1) your computer needs to be able to show Hidden SYSTEM files

On your Kindle: Go to the system folder (if you can't see it, step 1 is not correct)
Inside is a folder: com.amazon.ebook.booklet.reader
inside the folder is: reader.pref,

Edit this with Notepad or similar TEXT only editor

Change this line to read: HORIZONTAL_MARGIN=10
(I tried 0, it is too close to the edges. this gives 5 on each side. the default is 40)


Save

Do NOT use the 'Words per line' Font setting or this will revert to the standard piggy values
theducks is offline   Reply With Quote
Old 04-10-2014, 03:12 AM   #5
EbokJunkie
Addict
EbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blue
 
Posts: 229
Karma: 13495
Join Date: Feb 2009
Location: SoCal
Device: Kindle 3, Kindle PW, Pocketbook 301+, Pocketbook Touch, Sony 950, 350
@theducks
This works for Kindle Keyboard but not for Paperwhite.
I have a solution for this and do negative margins for all my epub->azw3 conversions but this is not that simple.
Each epub is unique, developers give arbitrary names to classes that control paragraphs of book text. The only way to provide decreased margins is to insert line, say, margin: 0pt -8pt 0pt, into css class that controls bulk of text.
I wrote a small Python script that does that. This script runs from batch file (Windows) that provides prior call to Sigil. Sigil opens ePub, I browse the html code, pinpoint the name of target class, copy it and shut down Sigil. My batch prompts for enetring the class name, I paste it by mouse right click and batch passes this name to my script that embeds line with negative margins exactly into the named class section in css.
The secret is not to use Calibre for further conversion because Calibre messes with class names and our negative margins line will land into the wrong class that doesn't control all book test.
For conversion, batch runs kindlegen, generates mobi and uses kindleunpack to extract and rename azw3.
Actually, I do use Calibre at the start of aforementioned batch file, but this is for conversion epub->epub that provides font embedding, setting font size and other cosmetic changes.
If this is of interest I can post working version of batch file and Python script.

Last edited by EbokJunkie; 01-19-2015 at 01:32 PM. Reason: typo
EbokJunkie is offline   Reply With Quote
Old 04-10-2014, 05:19 AM   #6
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 29,809
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Quote:
Originally Posted by EbokJunkie View Post
@theducks
This works for Kindle Keyboard but not for Paperwhite.
I have a solutions and do negative margins for all my epub->azw3 conversions but this is not that simple.
Each epub is unique, developers give arbitrary names to classes that control paragraphs of book text. The only way to provide decreased margins is to insert line, say, margin: 0pt -8pt 0pt, into css class that controls bulk of text.
I wrote a small Python script that does that. This script runs from batch file (Windows) that provides prior call to Sigil. Sigil opens ePub, I browse the html code, pinpoint the name of target class, copy it and shut down Sigil. My batch prompts for enetring the class name, I paste it by mouse right click and batch passes this name to my script that embeds line with negative margins exactly into the named class section in css.
The secret is not to use Calibre for further conversion because Calibre messes with class names and our negative margins line will land into the wrong class that doesn't control all book test.
For conversion, batch runs kindlegen, generates mobi and uses kindleunpack to extract and rename azw3.
Actually, I do use Calibre at the start of aforementioned batch file, but this is for conversion epub->epub that provides font embedding, setting font size and other cosmetic changes.
If this is of interest I can post working version of batch file and Python script.
Thanks for your explanation.
I have a K4NT. Wasting expensive screen area always struck me as dumb. There is a cheap Bezel to create a border
theducks is offline   Reply With Quote
Old 04-11-2014, 03:51 AM   #7
snoeki
Connoisseur
snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.
 
Posts: 62
Karma: 2030818
Join Date: Jan 2010
Device: Kindle paperwhite 2 & Kobo glo hd
I am interested in the python script including the batch file. Thanks for sharing EbokJunkie!
snoeki is offline   Reply With Quote
Old 04-13-2014, 03:33 PM   #8
EbokJunkie
Addict
EbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blue
 
Posts: 229
Karma: 13495
Join Date: Feb 2009
Location: SoCal
Device: Kindle 3, Kindle PW, Pocketbook 301+, Pocketbook Touch, Sony 950, 350
Ok, here it is. Do the dollowing steps.
1. Install Python 2.7.
2. Install Calibre
3. Download KindleUnpack_v64.zip
4. Download Python script negmarg.py. Download page is in Russian, just click on a button with downward pointing arrow
5. Using text editor create epub2azw3.bat file with this content:
Code:
:: Parameter #1: epub file name
:: Parameter #2: negative side margin (enter POSITIVE decimal value in pt). Default is 9
::
:: How to call:
::1.  epub2azw3 book.epub
::   Provides default negative side margins of 9 pt
::2.  epub2azw3 book.epub negative_margin 
::   Provides  negative side margins equal to value of parameter "negative_margin" (value must be positive)

ebook-convert %1 "%~n1_embed.epub" --output-profile kindle_pw^
   --embed-font-family "Charis SIL ModifiedLarger" --subset-embedded-fonts --minimum-line-height 125^
   --base-font-size 17 --font-size-mapping 13,13,17,17,18,22,24^
   --remove-paragraph-spacing --change-justification justify --margin-top -1 --margin-bottom -1
:: run Sigil. Please find out the class that renders basic test and copy its name to clipboard
sigil "%~n1_embed.epub"
:: Paste class name by mouse right-click in responce to prompt
set /p class=Enter calibre class name:
:: call python applet that inserts negative side margin to paragraph class in css file
:: margin is in positive number of points and comes from second parameter of this batch file
:: IF SECOND PARAMETER IS MISSING/BLANK DEFAULT VALUE 9 IS ADOPTED
if [%2]==[] (goto mdef) else goto mspec
:mspec 
:: Parameter #2 is in place
python.exe "%~dp0negmarg.py" -e "%~n1_embed.epub" -m %2 -c %class%
goto pass
:mdef
:: Parameter #2 is blank
python.exe "%~dp0negmarg.py" -e "%~n1_embed.epub" -c %class%
:pass
:: convert epub to mobi
kindlegen "%~n1_embed.epub" -locale en -o "%~n1.mobi"
:: extract azw3
python.exe "%~dp0\lib\kindleunpack.py" -s "%~n1.mobi" "%~n1"
:: copy mobi8-*.azw3 file into current directory
copy ".\%~n1\*.azw?" ".\"
:: check if old  file *.azw3 exists and delete it
if exist "%~n1.azw3" del "%~n1.azw3"
:: rename mobi8-*.azw3 file
call renazw3 "mobi8-%~n1.azw3" 
:: remove intermediate file

del "%~n1_embed.epub"

del "%~n1.mobi"
:: remove directory with unpacked files
rmdir "%~n1" /s /q
This batch file uses some code from post #128 by Katsunami
Additionall batch file renazw3.bat needed for renaming:
Code:
set str=%1
rename %1 %str:mobi8-=%
Place it next to epub2azw3.bat.
6. Create some arbitrary folder, add path to this folder to environmental variable Path, and place Amazon's kindlegen.exe, script negmarg.py, and epub2azw3.bat into this folder.
7. Uncompress dowloaded KindleUnpack_v64.zip and copy entire folfer lib (as is) to created folder.

You're done. Place epub book (non-DRMed) into any folder, make that folder current and run either this command:
Code:
epub2azw3 book.epub
or this command
Code:
epub2azw3 book.epub 8
First command sets negative margin to 9 points (default).
Second command explicitely specifies negative margin of 8 points.

Both commands first embed font Charis SIL ModifiedLarger (you are free to replace this font name by the name of any font family installed on your Windows computer), provide certain font size (you can change it at your will), set full text justification, and try to minimize top and bottom margins.
All is done in Calibre command line.
After this Sigil is invoked. Set Sigil to view html code, click on various html file names at the left side panel and try to find out what CSS class is used for text paragraphs. If two classes are nested always use external (enclosing) one. Copy name of this class to clipboard and shut down Sigil.
You'll see on-screen prompt. Use mouse right click to paste class name.
Press enter. Execution will continue and resulting file book.azw3 will be created.
Scriipt is very simple, it doesn't check for any errors so user discretion is advised.
Somethimes kindlegen has problems with epub table of contents or with missing language setting.

Last edited by EbokJunkie; 01-29-2015 at 04:01 PM.
EbokJunkie is offline   Reply With Quote
Old 04-18-2014, 04:13 AM   #9
snoeki
Connoisseur
snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.
 
Posts: 62
Karma: 2030818
Join Date: Jan 2010
Device: Kindle paperwhite 2 & Kobo glo hd
Thanks so much!

I downloaded the files, I have some free days the next week and I will have time to enjoy your work

I used Charis SIL ModifiedLarger from Jwolf for some time now, so that's perfect. This will give me great joy.
snoeki is offline   Reply With Quote
Old 04-20-2014, 01:33 PM   #10
EbokJunkie
Addict
EbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blue
 
Posts: 229
Karma: 13495
Join Date: Feb 2009
Location: SoCal
Device: Kindle 3, Kindle PW, Pocketbook 301+, Pocketbook Touch, Sony 950, 350
Added small batch file renazw3.bat needed for renaming resulting azw3 (see my post above).
EbokJunkie is offline   Reply With Quote
Old 05-01-2014, 12:19 PM   #11
snoeki
Connoisseur
snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.snoeki ought to be getting tired of karma fortunes by now.
 
Posts: 62
Karma: 2030818
Join Date: Jan 2010
Device: Kindle paperwhite 2 & Kobo glo hd
Thanks EbokJunkie, it works great for me. I do a few books and I check them on my ereader, working really fine!
snoeki is offline   Reply With Quote
Old 05-01-2014, 09:36 PM   #12
EbokJunkie
Addict
EbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blue
 
Posts: 229
Karma: 13495
Join Date: Feb 2009
Location: SoCal
Device: Kindle 3, Kindle PW, Pocketbook 301+, Pocketbook Touch, Sony 950, 350
@snoeki
Glad you liked it. I do all my books this way, hate wide margins. Mine are about 3mm wide.
EbokJunkie is offline   Reply With Quote
Old 01-19-2015, 11:41 AM   #13
kentmatt
Member
kentmatt doesn't litterkentmatt doesn't litter
 
Posts: 22
Karma: 116
Join Date: Jul 2010
Device: none
Quote:
Originally Posted by EbokJunkie View Post
@theducks
This works for Kindle Keyboard but not for Paperwhite.
I have a solutions and do negative margins for all my epub->azw3 conversions
What version of firmware on the Paperwhite do you have? I've experimented with negative margins, and my FW 5.6 Paperwhite seems to completely ignore them.

I went so far as to create a simple html 'book' and convert it with Calibre, where I tweaked it. I started with just trying to do the body tag, but that didn't work - so I did everything - still no luck. The CSS looks like this:

@namespace h "http://www.w3.org/1999/xhtml";

//this the body
.calibre {
display: block;
font-size: 1em;
line-height: 1.2;
padding-left: 0;
padding-right: 0;
margin: 0 -20px;
}

//heading1
.calibre1 {
display: block;
font-size: 1.5em;
font-weight: bold;
line-height: 1.2;
text-align: center;
margin: 0.5em -20px;
}

//heading 4
.calibre2 {
display: block;
font-weight: bold;
text-align: center;
margin: 1em -20px 0.1em -20px;
}

//heading3
.calibre3 {
display: block;
font-size: 1.125em;
font-weight: bold;
line-height: 1.2;
text-align: center;
margin: 2em -20px;
}

//paragraphs
.calibre4 {
display: block;
text-align: left;
text-indent: 1.2em;
margin: 0, -20px;
}
kentmatt is offline   Reply With Quote
Old 01-19-2015, 01:26 PM   #14
EbokJunkie
Addict
EbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blue
 
Posts: 229
Karma: 13495
Join Date: Feb 2009
Location: SoCal
Device: Kindle 3, Kindle PW, Pocketbook 301+, Pocketbook Touch, Sony 950, 350
@kentmatt

Calibre reshuffles and renames all classes from the source file. That's why the batch file above first implements Calibre conversion epub->epub and the allows user to go thru the html code and determine what CSS class Calibre assigned to base text.
User pinpoints the correct class and sets margins in class definition.
After this we cannot allow Calibre to mess with the code; ones the negative margins are set for the correct class we call kindlegen for actual conversion to mobi (and extract azw3 from combo mobi after this).
Kindlegen doesn't mess with source classes as Calibre does.
Of course, you can just call kindlegen, feed it with html (properly referencing your css with negative margins) and you'll see expected result at any Kindle model.

BTW, it should suffice to apply negative margins to one (paragraph) class only.

Last edited by EbokJunkie; 01-19-2015 at 01:29 PM.
EbokJunkie is offline   Reply With Quote
Old 01-19-2015, 02:32 PM   #15
Section8
Addict
Section8 ought to be getting tired of karma fortunes by now.Section8 ought to be getting tired of karma fortunes by now.Section8 ought to be getting tired of karma fortunes by now.Section8 ought to be getting tired of karma fortunes by now.Section8 ought to be getting tired of karma fortunes by now.Section8 ought to be getting tired of karma fortunes by now.Section8 ought to be getting tired of karma fortunes by now.Section8 ought to be getting tired of karma fortunes by now.Section8 ought to be getting tired of karma fortunes by now.Section8 ought to be getting tired of karma fortunes by now.Section8 ought to be getting tired of karma fortunes by now.
 
Section8's Avatar
 
Posts: 254
Karma: 2092424
Join Date: Oct 2011
Location: Arlington, TX
Device: Kindle PW4, Moon+ Reader on a cheap Android tablet
I've also been experimenting with setting negative margins in epubs converted to azw3. This is the best I've been able to do, using the calibre ebook editor (which I use all the time to tweak css with anyway):

First in the calibre conversion settings, set the option to expand the "margin" css rules - so the css margins are set using margin-left, margin-right, etc instead of "margin:".

After conversion, open the converted azw3 in calibre's ebook editor. Open the css and use find/replace to delete all the "margin-left: 0;" and "margin-right: 0;" statements by replacing them with nothing (only in the css).

Then, add the negative margin to the css paragraph:

p {
margin-left: -30px;
margin-right: -30px;
}

That mostly just works. I had one book with a table this screwed up - the cells would overlay each other after doing this. I don't know of any easy way to figure out which classes are
Section8 is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Best settings for 1:1 ePub to AZW3 conversion? gers1978 Conversion 8 06-03-2013 10:50 PM
azw3 to epub conversion stuck on 1% krysk Conversion 2 04-21-2013 11:53 AM
AZW3 to EPUB Conversion Probs grizedale Conversion 4 04-16-2013 06:47 PM
Conversion from epub to azw3 Joy736 Conversion 12 01-01-2013 11:00 AM
Using negative margins Agama Conversion 0 03-03-2012 07:29 AM


All times are GMT -4. The time now is 11:56 PM.


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