![]() |
#1 |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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? |
![]() |
![]() |
![]() |
#2 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
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?
|
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
![]() |
#4 |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 30,274
Karma: 57979022
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 |
![]() |
![]() |
![]() |
#5 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 230
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 |
![]() |
![]() |
Advert | |
|
![]() |
#6 | |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 30,274
Karma: 57979022
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
I have a K4NT. Wasting expensive screen area always struck me as dumb. There is a cheap Bezel to create a border ![]() |
|
![]() |
![]() |
![]() |
#7 |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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!
|
![]() |
![]() |
![]() |
#8 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 230
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 Additionall batch file renazw3.bat needed for renaming: Code:
set str=%1 rename %1 %str:mobi8-=% 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 Code:
epub2azw3 book.epub 8 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. |
![]() |
![]() |
![]() |
#9 |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
![]() |
#10 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 230
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).
|
![]() |
![]() |
![]() |
#11 |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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!
|
![]() |
![]() |
![]() |
#12 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 230
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. |
![]() |
![]() |
![]() |
#13 | |
Member
![]() ![]() Posts: 22
Karma: 116
Join Date: Jul 2010
Device: none
|
Quote:
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; } |
|
![]() |
![]() |
![]() |
#14 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 230
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. |
![]() |
![]() |
![]() |
#15 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 |
![]() |
![]() |
![]() |
|
![]() |
||||
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 |