0

Frustrated college math prof here hoping for a little holiday relief.

Summary of the problem:

I have files downloaded from Blackboard LMS for my class of >100 students. Some students submit multiple files and sometimes in non-pdf format. I'd like to combine each student's submitted files into a single pdf for that student. Currently I am doing this manually with Acrobat. It's very tedious.

I'm hoping somebody can direct me to or help me concoct a bash script which can combine these files more auto-magically?

Full details

I have 130 students this semester. Their final written assignment has been submitted through my college's Blackboard LMS.

Unlike Canvas, Blackboard does not allow professors to specify/limit allowed file types or limit the number of files submitted. Blackboard does NOT offer an option to automatically combine files into a pdf. Why not? I don't know.

The files come together in a zip file and when I unzip, the files are in the following format in a single folder:

<AssignmentName>_<Student1ID>_attempt_<datestamp>.txt
<AssignmentName>_<Student1ID>_attempt_<datestamp>_<SubmittedFile1>.jpg
<AssignmentName>_<Student1ID>_attempt_<datestamp>_<SubmittedFile2>.jpg
...
<AssignmentName>_<Student2ID>_attempt_<datestamp>.txt
<AssignmentName>_<Student2ID>_attempt_<datestamp>_<SubmittedFile1>.jpeg
<AssignmentName>_<Student2ID>_attempt_<datestamp>_<SubmittedFile2>.jpeg
...
etc.

The .txt file contains general information about the student's submission.

Example

WrittenAssignment2_40012345_attempt_2021-12-13-20-36-46.txt
WrittenAssignment2_40012345_attempt_2021-12-13-20-36-46_IMG3047.jpg
WrittenAssignment2_40012345_attempt_2021-12-13-20-36-46_IMG3048.jpg
WrittenAssignment2_40012345_attempt_2021-12-13-20-36-46_IMG3049.jpg
WrittenAssignment2_40067890_attempt_2021-12-14-16-22-39.txt
WrittenAssignment2_40067890_attempt_2021-12-14-16-22-39_AssignmentDoc.pdf
WrittenAssignment2_40098765_attempt_2021-12-12-20-08-52.txt
WrittenAssignment2_40098765_attempt_2021-12-12-20-08-52_MyUploadPg1.pdf
WrittenAssignment2_40098765_attempt_2021-12-12-20-08-52_MyUploadPg2.pdf
WrittenAssignment2_40098765_attempt_2021-12-12-20-08-52_MyUploadPg3.pdf
...

Many students do successfully submit single pdfs, but many do not. I have tried various social engineering techniques to get them to submit single multi-page pdfs, including instructions on submitting single pdfs, or giving a mark of 0 for non-compliance, but this just generates MORE headache.

What I would like is to read the list of .txt files, then combine each group of related pdf or jpgs into a single pdf and put the output as

<AssignmentName>_<Student1ID>_attempt_<datestamp>_COMBINED.pdf

So that I have only a single file to mark for each student. Thanks so much.

6
  • why don't you specify the submission requirement in the course description, something like "non pdf submissions will not be accepted"
    – jsotola
    Dec 16, 2021 at 19:29
  • Hi @jsotola thanks. I have done this but then if I give a zero I spend a substantial amount of time dealing with argumentative students. Some courses have multiple submissions so I can build up their understanding over a few assignments. In this case this semester, only this final written assignment is submitted in this format, grades are due next Tuesday and it's not a huge percentage of students who submitted multiple files, but grade challenges after the semester are a SUPER PAIN. I'd very much like to build a script that I can use when the need arises. I'm manually combining as I type.
    – d-tour
    Dec 16, 2021 at 20:41
  • there may be a program that does it ... ask at softwarerecs.stackexchange.com
    – jsotola
    Dec 16, 2021 at 21:10
  • the simplest way may be to print all of the files to pdf, then use another program to stitch the pages together
    – jsotola
    Dec 16, 2021 at 21:12
  • @jsotola thanks for the softwarerecs reference. I will ask there.
    – d-tour
    Dec 17, 2021 at 14:24

1 Answer 1

1

OK. I hate it when people post their own answers but I spent about 2 hours working on it this morning and here's what I came up with. It's ugly but it kind of works. Anyone out there Teaching on Blackboard with some other tips? Thanks.

#!/bin/bash

search_dir='./TestFiles'
n=1
for entry in "$search_dir"/*.txt
do
  echo $n " Merging"

  f="$(basename "$entry" .txt)"
  for subfile in "$search_dir"/"$f"_*
  do
        echo $n " $subfile"
  done

## First usd pdftk to combine any pdfs into a merged PDF
if compgen -G "${search_dir}/${f}_*.pdf" > /dev/null; then
    echo "pattern exists!"

  pdftk "$search_dir"/"$f"_*.pdf cat output "$search_dir"/"$f"__MERGED.pdf

  echo "Merged PDFs"
fi


##If jpg or jpeg exists then combine to PDF using img2pdf
if compgen -G "${search_dir}/${f}_*.jp*" > /dev/null; then
    echo "pattern exists!"

  img2pdf "$search_dir"/"$f"_*.jp* --output "$search_dir"/"$f"__MERGED.pdf

  echo "Merged JPGs"
fi

  ((n++))

done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .