Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-64431

Layers missing from PDFs in grading view



    • Bug
    • Status: Waiting for integration review
    • Critical
    • Resolution: Unresolved
    • 3.4.6, 3.5.5, 3.5.6, 3.9.3, 3.10, 3.11
    • None
    • Assignment
    • 5


      When grading an assignment submitted as a PDF, some layers of the PDF may be missing.

      SETUP (Create a course where you are both instructor and student):

      1. Navigate to a course.
      2. Navigate to the Participants list.
      3. Enrol yourself as both a teacher or admin (so that you can edit the course) and as a student (so that you can submit assignments). Save.
      4. Go back to the course page and turn editing on.
      5. Add an activity or resource: Assignment
      6. Set the following, then Save & Display:
      • General/Assignment name: (arbitrary)
      • Submission types/Submission types: File submissions
      • Submission settings/Attempts reopened: Manually
      • Submission settings/Maximum attempts: Unlimited

      STEPS TO REPRODUCE (submit attached file, and grade it):

      1. In the file-submission assignment you created...
      2. Click "Add submission"
      3. Drag and drop the attached file "sample.pdf"
      4. Click "Save Changes" to return to the assignment main page.
      5. Click "View all submissions"
      6. You should see your own submission, with status "Submitted for grading", or "Draft (not submitted)". Click "Grade" beside your submission.
      7. In the default layout, wait until you see an image of the pdf submitted where you can add annotations.

      This view should match the submitted pdf, as seen when you download the pdf by clicking the 'sample.pdf' filename link in the grade panel on the right.

      The grading view does not show the parts of the pdf. Namely, the coloured annotations are missing. When downloaded and viewed in the browser or a system viewer, all layers of the pdf are visible (indicating that the pdf is stored correctly by Moodle).

      The most alarming part of this is that there is no error message, and the file may appear to be complete, even though significant content is missing.


      The annotations in the attached file were added using "PDF Expert", though other tools have been reported by our users to give similar results. I have seen the error with both pdf version 1.4 and version 1.7 documents. This is possibly related to https://tracker.moodle.org/browse/MDL-44426, however the issue here is not with Ghostscript. (I have seen the error on systems running Ghostscript version 9.06 and 9.10, and am currently testing with 9.18.) When viewed with Ghostscript from the command line, the pdf is displayed correctly. Furthermore, when "flattened" using Ghostscript

      $ gs -sDEVICE=pdfwrite -o flattened.pdf sample.pdf

      , the file can be resubmitted to the assignment, and then all parts appear.

      The issue may be with the FDPI library. When I upload the attached file to https://www.setasign.com/products/fpdi-pdf-parser/details/, the parser displays only the black layer, not the annotations. Per the FPDI Manual at https://manuals.setasign.com/fpdi-manual/v2/limitations/, "Dynamic content like link annotations, form fields or any other page annotations cannot be attached to a form XObject because they are related to the coordinates of the origin page. So FPDI is not able to import this kind of content."

      Since we are already using Ghostscript, would it be possible to flatten the file before it is processed with FPDI?


        1. 2022-09-24_19-12.png
          35 kB
        2. currentresult.png
          194 kB
        3. FontTest.pdf
          130 kB
        4. image-2021-11-30-12-02-57-436.png
          0.3 kB
        5. mcb_pdf_issue_no_annotations.png
          125 kB
        6. mcb_pdf_issue_w_annotations.jpg
          35 kB
        7. mcb_pdf_issue_w_annotations.pdf
          156 kB
        8. MDL-64431.jpg
          49 kB
        9. sample.pdf
          181 kB
        10. sample flattened.pdf
          452 kB

        Issue Links