Register Guidelines E-Books Search Today's Posts Mark Forums Read

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
Member
snoeki began at the beginning.
 
Posts: 23
Karma: 10
Join Date: Jan 2010
Device: Kindle paperwhite 2 & Kobo Aura 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
Irrational Optimist
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.
 
Posts: 5,890
Karma: 9267276
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch (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
Member
snoeki began at the beginning.
 
Posts: 23
Karma: 10
Join Date: Jan 2010
Device: Kindle paperwhite 2 & Kobo Aura 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
Grand Sorcerer
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: 14,632
Karma: 5628865
Join Date: Aug 2009
Location: (The original) Silicon Valley, USA
Device: Galaxy Tab 2, Astak Pocket Pro, K4NT
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
Zealot
EbokJunkie began at the beginning.
 
Posts: 124
Karma: 16
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 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.

Last edited by EbokJunkie; 04-10-2014 at 03:15 AM. Reason: typo
EbokJunkie is offline   Reply With Quote
Old 04-10-2014, 05:19 AM   #6
theducks
Grand Sorcerer
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: 14,632
Karma: 5628865
Join Date: Aug 2009
Location: (The original) Silicon Valley, USA
Device: Galaxy Tab 2, Astak Pocket Pro, K4NT
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
Member
snoeki began at the beginning.
 
Posts: 23
Karma: 10
Join Date: Jan 2010
Device: Kindle paperwhite 2 & Kobo Aura 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
Zealot
EbokJunkie began at the beginning.
 
Posts: 124
Karma: 16
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.6.
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 margin (enter POSITIVE decimal value in pt). Default is 9
::
:: How to call:
::1.  epub2azw3 book.epub
::   Provides default negative margins of 9 pt
::2.  epub2azw3 book.epub negative_margin 
:: 
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 margind to vabsic test 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 "%~dp0embednm_no_class.py" -e "%~n1_embed.epub" -m %2 -c %class%
goto pass
:mdef
:: Parameter #2 is blank
python.exe "%~dp0embednm_no_class.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; 04-23-2014 at 07:09 PM.
EbokJunkie is offline   Reply With Quote
Old 04-18-2014, 04:13 AM   #9
snoeki
Member
snoeki began at the beginning.
 
Posts: 23
Karma: 10
Join Date: Jan 2010
Device: Kindle paperwhite 2 & Kobo Aura 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
Zealot
EbokJunkie began at the beginning.
 
Posts: 124
Karma: 16
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
Member
snoeki began at the beginning.
 
Posts: 23
Karma: 10
Join Date: Jan 2010
Device: Kindle paperwhite 2 & Kobo Aura 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
Zealot
EbokJunkie began at the beginning.
 
Posts: 124
Karma: 16
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
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 08:04 PM.


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