View Single Post
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: 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
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