View Single Post
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,491
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, 42 views)

Last edited by tomsem; 09-27-2023 at 04:58 PM.
tomsem is offline   Reply With Quote