Formatting pdf for kindle
Solution 1
I have had good results with K2pdfopt. With the command-line options -w (width) and -h (height) you can set the output size so that it matches exactly your Kindle's screen size.
Solution 2
I found the command
pdfinfo -box -f 1 -l 3 mypdf.pdf
particularly useful in finding information about a given PDF document. For the PDF that was being chopped at bottom when put it on the Kindle, the information showed:
Page 1 size: 421 x 595 pts (A5)
Page 1 MediaBox: 0.00 0.00 421.00 595.00
Page 1 CropBox: 0.00 0.00 421.00 595.00
Page 1 BleedBox: 0.00 0.00 421.00 595.00
Page 1 TrimBox: 0.00 0.00 421.00 595.00
Page 1 ArtBox: 0.00 0.00 421.00 595.00
.
.
.
consistent with how I created it using the command (which crops the A5 pages correctly)
gs \
-o left-sections.pdf \
-sDEVICE=pdfwrite \
-g4210x5950 \
-c "<</PageOffset [0 0]>> setpagedevice" \
-f double-page-input.pdf
The -gWxH
flag is setting the size in pixels at 720dpi
.
The 3rd Gen Kindle viewable screen size is 560x735 (pixels) @ 167dpi
(according to this and wiki), thus at 72dpi
(standard screen) the Kindle viewable screen size translates to (560/167)*72=241.43
by (735/167)*72=316.88
, so 241.43x316.88 @72dpi
. However pdfwrite
, used below, uses a dpi of 720dpi
, at this dpi the Kindle viewable is 2414x3168 @720dpi
. Clearly 4210x5950@720dpi
is too big.
Alternatively one can see this by the fact I had created a PDF with 4210x5950 pixels @ 720dpi
and at 167dpi
this would be 976.48x1380.07
, which is clearly larger than the 560x735
of the Kindle viewable area.
Thus I need to rescale to the Kindle bounds.
One can set the device size in points directly with -dDEVICEWIDTHPOINTS=w
and -dDEVICEHEIGHTPOINTS=h
. At 72dpi
a 1 point= 1 pixel
(as a point is defined as 1/72
of an inch), but at 167dpi
1 point ~ 2.31 pixels
. So if our display is 560x735 pixels @ 167dpi
then we would set -dDEVICEWIDTHPOINTS=241 -dDEVICEHEIGHTPOINTS=316
to fit the Kindle. The problem is this doesn't alter the values of MediaBox
etc, which as shown by pdfinfo
remain at 421x595 @72 dpi
so use the flag -dPDFFitPage
also to ignore these, or rather rescale them to fit the device.
gs -o out.pdf -sDEVICE=pdfwrite -dDEVICEWIDTHPOINTS=241 -dDEVICEHEIGHTPOINTS=317 -dPDFFitPage -f in.pdf
It seems now when out.pdf
is viewed using actual-size
option in Kindle it fits on the screen nicely.
I'm still not entirely clear why Kindle was chopping edges from a PDF that was too big for its screen rather than just rescaling (even if that meant very small text) in the fit-to-screen mode (I think that's what it normally does?).
Related videos on Youtube
fpghost
Updated on September 18, 2022Comments
-
fpghost almost 2 years
I started with a scan of a book which was a two-column PDF, I then used the
gs
methods outlined in this thread to put the PDF into single page format, which worked great. This looks good on the PC screen but when I transfer the PDF to my Kindle (3rd generation) thefit-to-screen
option chops off around 10-20% from the bottom of most pages, whereas theactual size
option is far to big for the screen.Is there a solution to this? should I be using different parameters than
-g4210x5950
when I do the original splitting withgs
? or can I just resize the PDF (or its margins) I have already generated such that it is a good size for the Kindle screen? If so, what is the size I need for a 3rd gen Kindle screen.I want to rescale the single page pdf to correct kindle size (perhaps with
gs
), not convert. Alternatively add margins/borders so kindle fit-to-screen works without chopping ends.(I should say I've tried Amazon's free converter etc, but ideally I would like to keep the PDF format rather than convert, as the document is technical and the conversion doesn't seem particularly reliable. I would rather just resize the PDF/PDFmargins and keep the existing formatting if possible).
-
Simon about 11 yearsPossible duplicate superuser.com/questions/385346/…
-
-
fpghost about 11 yearsThanks for the suggestion, but
k2pdfopt mypdf.pdf -w 560 -h 735
seems to have given similar results to the conversion services I tried (namely splitting pages across multiple pages and generally messing with the formatting). I would ideally like my pages to stay intact, just with a margin added and the main body scaled in such a way that the Kindle doesn't chop the edges. -
fpghost about 11 yearsshould be achievable with
gs
?