Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Readers > Amazon Kindle > Kindle Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 09-27-2023, 04:49 PM   #1
tomsem
Grand Sorcerer
tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.
 
Posts: 6,478
Karma: 26425959
Join Date: Apr 2009
Location: USA
Device: iPhone 15PM, Kindle Scribe, iPad mini 6, PocketBook InkPad Color 3
Prevent Send To Kindle from converting to Print Replica

Since the launch of Scribe, Send to Kindle service has converted PDFs to Print Replica for Scribe. And sometime in the last week or so, the Kindle apps also get Print Replica.

For the most part this is a totally good thing: Print Replica backs up annotations, and syncs between devices. But what if you want to have the service deliver PDF instead?

For example, navigation in landscape orientation for Print Replica on Scribe does not work as well as for PDF. For PDF, tap advances the next section of page on screen, and then advances to the next page. They forgot to implement this for Print Replica, so you have to resort to precise drag gestures.

Well, it turns out that conversion fails if there are more than 1000 PDF bookmarks, and it will deliver PDF instead for the lifetime of that personal document (or until the limit changes).

This script will take a PDF and output one with 1001 bookmarks added to it (all of these will navigate to page 1).

Code:
from os import path
import sys
import fitz

'''
Creates 1000 bookmarks to prevent PDF from being converted to Print Replica
by Send To Kindle service.py
'''

try:
    pdf = sys.argv[1]
    if not path.isfile(pdf):
        raise FileNotFoundError

except (IndexError, FileNotFoundError):
    print('Please specify the path to an existing PDF file, e.g.:\n    > python bookmark_hack.py [pdf_path]')
    exit(1)

doc = fitz.Document(pdf)
toc = doc.get_toc()

dummy_toc = [[1, 'Dummy TOC', 1]]
for b_num in range(1, 1000):
    dummy_toc.append([2, f'Dummy TOC entry {b_num}', 1])

toc += dummy_toc
doc.set_toc(toc)

doc.save(f'{path.splitext(pdf)[0]}_hacked.pdf')
This has a dependency on PyMuPDF, so some setup required. Python 3 recommended. E.g.:

Code:
python3 -m venv venv
source venv/bin/activate
python3 -m pip install -U pymupdf
Attached Files
File Type: zip bookmark_hack.py.zip (615 Bytes, 39 views)

Last edited by tomsem; 09-27-2023 at 04:58 PM.
tomsem is offline   Reply With Quote
Old 09-28-2023, 08:11 AM   #2
Quoth
the rook, bossing Never.
Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.
 
Quoth's Avatar
 
Posts: 11,164
Karma: 85874891
Join Date: Jun 2017
Location: Ireland
Device: All 4 Kinds: epub eink, Kindle, android eink, NxtPaper11
Use USB. Simple.
Quoth is offline   Reply With Quote
Advert
Old 09-28-2023, 01:11 PM   #3
tomsem
Grand Sorcerer
tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.
 
Posts: 6,478
Karma: 26425959
Join Date: Apr 2009
Location: USA
Device: iPhone 15PM, Kindle Scribe, iPad mini 6, PocketBook InkPad Color 3
Quote:
Originally Posted by Quoth View Post
Use USB. Simple.
Hey, I had some fun writing this. I didn't claim it was that useful.
tomsem is offline   Reply With Quote
Old 09-28-2023, 01:49 PM   #4
j.p.s
Grand Sorcerer
j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.j.p.s ought to be getting tired of karma fortunes by now.
 
Posts: 5,285
Karma: 98804578
Join Date: Apr 2011
Device: pb360
Quote:
Originally Posted by tomsem View Post
Hey, I had some fun writing this. I didn't claim it was that useful.
I think it was informative, and I am getting tired of people effectively disparaging the dissemination of information.

I do have some questions. Over time you have frequently mentioned PDF bookmarks.

Is that some internal Adobe term?

Are they somehow different from TOC entries? (you invoke functions get_toc and set_toc)
(I know that epub, amazon, and pdf have provisions for a "table of contents" that can be used by a reading device that is not displayed while paging through a document. Some documents have that or a TOC that is an inline part of the document or both)

If the above paragraph is not clear, please ask for clarification, or just try to sus it out, rather than attacking some nomenclatural deficiency. (Supplying corrections is of course welcome.)
j.p.s is offline   Reply With Quote
Old 09-28-2023, 07:58 PM   #5
tomsem
Grand Sorcerer
tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.
 
Posts: 6,478
Karma: 26425959
Join Date: Apr 2009
Location: USA
Device: iPhone 15PM, Kindle Scribe, iPad mini 6, PocketBook InkPad Color 3
Quote:
Originally Posted by j.p.s View Post
I think it was informative, and I am getting tired of people effectively disparaging the dissemination of information.

I do have some questions. Over time you have frequently mentioned PDF bookmarks.

Is that some internal Adobe term?

Are they somehow different from TOC entries? (you invoke functions get_toc and set_toc)
(I know that epub, amazon, and pdf have provisions for a "table of contents" that can be used by a reading device that is not displayed while paging through a document. Some documents have that or a TOC that is an inline part of the document or both)

If the above paragraph is not clear, please ask for clarification, or just try to sus it out, rather than attacking some nomenclatural deficiency. (Supplying corrections is of course welcome.)
Acrobat calls them Bookmarks (as do most PDF viewers/editors).

PyMuPDF's '_toc()' functions only work with PDF, but manipulate what Adobe calls Bookmarks.

PyMuPDF's '_bookmark()' functions are only for reflowable documents (ePub, mobi, FB2, CBZ, SVG, XPS).

I haven't used it for anything but PDF so far. It looks like it has some interesting capabilities for the other document types, and has an OCR API to integrate with Tesseract.

https://pymupdf.readthedocs.io/en/latest/about.html

I encounter many PDFs which lack any Bookmarks whatsoever, and/or have an inline Table of Contents that doesn't have page links to the respective chapters (to say nothing of linking footnotes or index entries).

I want to send these to my Scribe (and as of recently, the Kindle apps) and at least want to have a functional ToC in the converted Print Replica document (the default ToC is useless).

So next on my task list is to scan a PDF for chapter/section headings, and create Bookmarks that will get converted to the Print Replica ToC.

Last edited by tomsem; 09-28-2023 at 08:03 PM.
tomsem is offline   Reply With Quote
Advert
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help With Converting KPF Print Replica Files to ePub on Calibre AdamH9999 Conversion 5 06-14-2021 12:23 PM
Print replica books Waylander Amazon Kindle 2 07-02-2018 09:22 AM
Converting AZW4 print replica into PDF format. Akrite Conversion 12 07-09-2015 12:30 PM
Is no 'print-replica' a problem? calvin-c Conversion 2 01-21-2013 04:58 PM
Converting Kindle ebook to print? tinabryan410 Reading and Management 3 10-23-2012 03:07 PM


All times are GMT -4. The time now is 08:46 AM.


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