kolibri
kolibri copied to clipboard
PDF renderer shows wrong page size
Observed behavior
http://35.227.71.104/learn/#/topics/c/c1b42abb8ee45d2596e79197c46cd4c6
Expected behavior
The PDF file was tested in several other PDF readers and page always renders fine (half width as expected).
User-facing consequences
The PDFs of this specific channel will be difficult to read.
Steps to reproduce
Try viewing http://35.227.71.104/learn/#/topics/c/c1b42abb8ee45d2596e79197c46cd4c6 in full screen mode
Context
This PDF in the above links was obtained from a double-width PDF which was then cropped.
Here is a link to the original PDF http://www.pointb.is/s/21CSGuide_English.pdf and this is the code that cuts each page into left and right halves: https://github.com/learningequality/sushi-chef-pointb-21csguide/blob/master/sushichef.py#L28-L62
Tested on latest: release-v0.12.x and 0.11.1
The PDF renderer appears to be reserving 2x the space for the right-side pages (with binding on the left). The renderer must be inferring this page width from something in the PDF file.
Is there anything different about these right-side pages when they're being cheffed? It's as if they are still using the same dual-page-width dimensions from the original PDF.
@jonboiser Yes, the original PDF is 2x sized, so the chef code performs a "crop" operation by setting the cropBox and trimBox to half size, see
https://github.com/learningequality/sushi-chef-pointb-21csguide/blob/master/sushichef.py#L51-L54 (and mediaBox too but not show in this code)
The PDF rendering in any other PDF reader is fine (shows half-page), but somehow PDF.js doesn't seem to respect the page crop info, hence filing the issue here.
See #sushi-chefs threads:
- https://learningequality.slack.com/archives/C6S90FCDT/p1567402734002400
- https://learningequality.slack.com/archives/C6S90FCDT/p1567587911006900
We can also use the PDF.js demo site here to validate the .pdf rendering: https://mozilla.github.io/pdf.js/web/viewer.html - just open the .pdf file you want to test.
Thx @cpauya ; the above screenshot confirm that a more recent version of PDF.js would fix this issue.
The Kolibri document_pdf_render is pinned to 1.9.x:
https://github.com/learningequality/kolibri/blob/develop/kolibri/plugins/document_pdf_render/package.json#L7 which is 2 years old according to npm https://www.npmjs.com/package/pdfjs-dist
I will let the Kolibri team investigate further—there might be API differences or other obstacles to updated, but definitely worth looking into.
I tried to upgrade PDF.js at one point and everything broke. We should do it, but it will not be straight forward.
It seems that even with an upgrade of PDFJS, this has not been resolved.
Fixed in #9888