momijizukamori / bookbinder-js

A JS application to format PDFs for bookbinding.
Mozilla Public License 2.0
139 stars 31 forks source link

Does not handle PageMediaRotation metadata correctly #124

Open paddatrapper opened 1 week ago

paddatrapper commented 1 week ago

A page with PageMediaRotation present is not correctly rotated in the output signatures. For example a PDF page with PageMediaRotation: 180 should be rotated and be 'upside-down' compared to the other page on the sheet, however this is not the case.

An example PDF is here, the first image should be rotated 180 degrees from the second example.pdf

Rotation metadata:

$ pdftk example.pdf dump_data
InfoBegin
InfoKey: ModDate
InfoValue: D:20240920151132+01'00'
InfoBegin
InfoKey: Creator
InfoValue: pdftk-java 3.3.2
InfoBegin
InfoKey: CreationDate
InfoValue: D:20240920151132+01'00'
InfoBegin
InfoKey: Producer
InfoValue: itext-paulo-155 (itextpdf.sf.net - lowagie.com)
PdfID0: 3e9f715e2d911f184847747024ca4bc6
PdfID1: 80769e49515b507b26f9fe0dc2336d1e
NumberOfPages: 2
PageMediaBegin
PageMediaNumber: 1
PageMediaRotation: 180
PageMediaRect: 0 0 611.21 791.21
PageMediaDimensions: 611.21 791.21
PageMediaBegin
PageMediaNumber: 2
PageMediaRotation: 0
PageMediaRect: 0 0 611.21 791.21
PageMediaDimensions: 611.21 791.21
sithel commented 1 week ago

Interesting! Good to know... we're definitely not checking any PDF metadata on a per-page basis... not even sure how/if https://pdf-lib.js.org/ would have that info...?

paddatrapper commented 1 week ago

Looks like it has some concept of them - https://pdf-lib.js.org/docs/api/classes/pdfpage#getrotation