kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

PDF renderer shows wrong page size

Open ivanistheone opened this issue 6 years ago • 6 comments

Observed behavior

Screen Shot 2019-09-04 at 9 19 54 AM

http://35.227.71.104/learn/#/topics/c/c1b42abb8ee45d2596e79197c46cd4c6

Expected behavior

expected

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

ivanistheone avatar Sep 04 '19 13:09 ivanistheone

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 avatar Sep 04 '19 18:09 jonboiser

@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

ivanistheone avatar Sep 04 '19 18:09 ivanistheone

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.

Screenshot 2019-09-05 09 54 46

cpauya avatar Sep 05 '19 01:09 cpauya

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.

ivanistheone avatar Sep 05 '19 03:09 ivanistheone

I tried to upgrade PDF.js at one point and everything broke. We should do it, but it will not be straight forward.

rtibbles avatar Sep 05 '19 15:09 rtibbles

It seems that even with an upgrade of PDFJS, this has not been resolved.

rtibbles avatar Aug 29 '22 23:08 rtibbles

Fixed in #9888

rtibbles avatar Dec 07 '22 17:12 rtibbles