Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Formats > Kindle Formats

Notices

Reply
 
Thread Tools Search this Thread
Old 10-30-2013, 03:37 PM   #1
Iznogood
Guru
Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.
 
Iznogood's Avatar
 
Posts: 932
Karma: 15752887
Join Date: Mar 2011
Location: Norway
Device: Ipad, kindle paperwhite
The evasive apnx

Hi everyone. I just received my PW2 (that's supposed to be able to show the page numbers that corresponds to the printed edition), and wanted to test out this feature. I ran one of my favorite books through finereader, saved the page as one HTML file per book page and made a script to merge these files together adding
Code:
<a class="pagebreak" id="pageNNN"></a>
at the beginning of every page and repaired the broken paragraphs.

I now have a book with a lot of markup that shows where the printed pagebreaks were. I wrote a script that auto-generated a PageList to the ncx file and a separate page-map.xml. So now I have an (almost) valid epub that shows the page numbers.

Is there a way I can convert this epub to azw3 with page numbers? I have tried kindlegen to convert it to something amazon-compatible but it didn't generate any apnx-file. I tried converting it with calibre, but calibre generated its own page numbers and removed my own. Kovids documentation of the APNX specifications are not something I want to dive into if I can void it; it contains both asin numbers (something which this book doesn't have) and other stuff regarding amazon-specific knowledge about the amazon-formats that I know next to nothing about.

Is there a tool I can use to generate the apnx-file for me? Perhaps a tool that I can incorporate into my linux bash-scripts? Once I have a correct apnx file I can transfer it to the kindle myself. Can I use calibre to keep the apnx together with the azw3 file, or do I have to handle the apnx file manually? Any hints on how to fix this will be greatly appreciated
Iznogood is offline   Reply With Quote
Old 11-08-2013, 09:51 PM   #2
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,999
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Creating an apnx file is pretty trivial, just look at apnx.py in calibre's source code. calibre will automatically create apnx files when sending books to kindle devices (e-ink kindle devices, not tablets using kindle apps). However the page numbers in those are automatically generated.
kovidgoyal is offline   Reply With Quote
Old 11-12-2013, 12:28 PM   #3
Iznogood
Guru
Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.
 
Iznogood's Avatar
 
Posts: 932
Karma: 15752887
Join Date: Mar 2011
Location: Norway
Device: Ipad, kindle paperwhite
Thanks for pointing me in the direction of an already existing script. I shall see what I can do to modify it; it's been years since I last wrote code for python. Do you think that generating an apnx file can be done in bash or is python the easiest language to do this in?
Iznogood is offline   Reply With Quote
Old 11-12-2013, 03:32 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,999
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
I never program in bash, of the languages I do program in, (C/C++/Coffeescript/python), python is far and away the best.
kovidgoyal is offline   Reply With Quote
Old 11-12-2013, 04:03 PM   #5
DaleDe
Grand Sorcerer
DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.
 
DaleDe's Avatar
 
Posts: 11,470
Karma: 13095790
Join Date: Aug 2007
Location: Grass Valley, CA
Device: EB 1150, EZ Reader, Literati, iPad 2 & Air 2, iPhone 7
Quote:
Originally Posted by kovidgoyal View Post
I never program in bash, of the languages I do program in, (C/C++/Coffeescript/python), python is far and away the best.
Certainly Bash is not the correct tool. It is a shell using shell scripting. It would not even begin without a lot of Unix tools like grep, awk, sed, etc. Python is certainly capable and easier that C and its variants.

Dale
DaleDe is offline   Reply With Quote
Old 11-21-2013, 12:56 PM   #6
Iznogood
Guru
Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.
 
Iznogood's Avatar
 
Posts: 932
Karma: 15752887
Join Date: Mar 2011
Location: Norway
Device: Ipad, kindle paperwhite
I do a lot of my work in linux and am used to the linux terminal, but not so familiar with python and its way of invocation, that's why I wondered whether this was possible from within bash.

But OK, it looks like I will have to do this with python, and it will be a good exercise for me. I haven't used python for years, and never needed to invoke a python script and passing a file as a reference to it. I therefore put forward a few more questions before I dive into this.

1) I will re-use apnx.py from Calibre:
http://bazaar.launchpad.net/~kovid/c...kindle/apnx.py
How would I invoke this python script from the command line and passing the path of the mobi file for which I would like to generate an apnx file? The script provides these methods and classes:
class APNXBuilder(object)
def write_apnx(self, mobi_file_path, apnx_path, accurate=True, page_count=0)
def generate_apnx(self, pages, apnx_meta)
def get_pages_exact(self, mobi_file_path, page_count)
def get_pages_fast(self, mobi_file_path)
def get_pages_accurate(self, mobi_file_path)
but it has no body for importing and reading the file. I guess I shall have to create my own script for reading the path argument and pass that to the function
Code:
write_apnx
in one way or another. Am I on the right track?

2) Is apnx only for mobi files, or for azw3 files as well? I see calibre generates them for mobi files, but cannot find azw3 files in here?

3) Does calibre always create its own apnx file when sinding to device, even when there is an apnx present in the folder together with the mobi file?
Iznogood is offline   Reply With Quote
Old 11-21-2013, 05:11 PM   #7
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,606
Karma: 23165369
Join Date: Dec 2010
Device: Kindle PW2
I looked into the whole APNX generation a long time ago, and, AFAIK, apnx.py can only generate fake page numbers. The best it can do is take the total number of pages of the print edition and divide the file accordingly.

I.e. no matter what you do, it probably won't work for you, because the script apparently cannot identify the actual pageMap targets in the .mobi file and use them to write a proper .apnx file with the pre-defined page numbers.

Have you looked at John's APNX file format description?
Doitsu is offline   Reply With Quote
Old 11-21-2013, 06:29 PM   #8
Iznogood
Guru
Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.Iznogood ought to be getting tired of karma fortunes by now.
 
Iznogood's Avatar
 
Posts: 932
Karma: 15752887
Join Date: Mar 2011
Location: Norway
Device: Ipad, kindle paperwhite
Quote:
Originally Posted by Doitsu View Post
Yes, I have. And creating a file according to the specification shouldn't be much of a problem when I use the apnx generator from calibre as a template.

I don't want to use the pagination information from within the mobi file. My text contains anchors
Code:
<a class="pagebreak" id="pageNNN"></a>
for every pagebreak, and these anchors should survive the epub to mobi conversion. So I need to search for the position of these anchors, and add that instead of the fake positions generated by calibre, and that should suffice *knock on wood*
Iznogood is offline   Reply With Quote
Old 11-22-2013, 04:28 AM   #9
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,606
Karma: 23165369
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by Iznogood View Post
I don't want to use the pagination information from within the mobi file. My text contains anchors
Code:
<a class="pagebreak" id="pageNNN"></a>
for every pagebreak, and these anchors should survive the epub to mobi conversion.
When I referred to "pagination information from within the mobi" I actually meant the page number anchors. If the KindleUnpack output is anything to go by, the anchors in the KF8 part survive the compilation while the page anchors in the Mobi7 part are lumped together with other anchors as <a id="fileposXXXX" /> anchors. (KindleUnpack apparently also cannot restore NCX pageLists.)

AFAIK, KindleUnpack doesn't distinguish between pageNNN anchors and other anchors in the mobi7 part, which is not really surprising since the tool predates the introduction of "real page numbers."

Quote:
Originally Posted by Iznogood View Post
So I need to search for the position of these anchors, and add that instead of the fake positions generated by calibre, and that should suffice *knock on wood*
That seems to be the sticking point. If finding page number targets was that easy, the extremely talented guys who reverse-engineered the Mobi7/KF8 file format for Calibre probably would've already added code that detects pageNNN anchors in Mobi7 files and used them for generating .apnx files with real page numbers in them.

IMHO, it might be helpful to cross-post your question to the KindleUnpack thread, since the KindleUnpack developers are intimately familiar with the file format and might be able to give you some pointers. Maybe one of them might even like the challenge to be the first one to develop code that'll allow to generate an .apnx file with real page numbers, if at all possible.
Doitsu is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[GUI Plugin] APNX Generator user_none Plugins 92 10-25-2020 01:24 PM
Calibre not sending APNX file stelios313 Devices 1 06-12-2013 09:25 PM
apnx files to mobi on calibre westhee Conversion 2 04-12-2013 04:28 PM
AZW3 APNX EA PHL Kumabjorn Amazon Kindle 4 10-15-2012 07:13 PM
Kindle generated apnx files Cassandra Devices 3 05-11-2011 04:54 PM


All times are GMT -4. The time now is 09:58 PM.


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