3

I'm trying to take a set of PDFs (that I'll have already separated into one page files) that I want to combine into multiple PDFs. As a teacher, I want to be able to scan a stack of tests into one big PDF file, split that into single pages (I already have the Automator service for that), and then combine the results into a separate file for each student. So if I had 10 students and a 4 page test, I'd want to be able to combine those 40 files into 10 separate PDFs, ideally labeled by student name (if there was a way for me to input that list of names into Automator). Worst case scenario, I just run a combinePDF service for each individual student, but I didn't know if there was a way I could do that all in one fell swoop?

Thanks for your help!

  • I'd use the third-party commandline tool, cpdf , and script the entire process. Have a look at: Coherent PDF Command Line Tools Community Release – user3439894 Apr 7 at 17:31
  • That does look like it might do what I want, but it costs $379 so I'm guessing that's more high-powered than I ultimately need. Thank you though! – David Apr 7 at 18:45
  • Did you read the linked page in my first comment? The Community Release of cpdf is free! – user3439894 Apr 7 at 19:27
  • 1
    @bmike, I've added an answer. – user3439894 May 12 at 15:19
  • 1
    @jmh, David was using Automator to split the PDF document, which has no options for the split and only creates individual files, one for each page, and why he was looking for a way to combine four at a time and named for each student. If you have read my answer you'd see he doesn't need to first split the scanned PDF document, it's a totally unnecessary step using the tool I suggested along with the shell script. It creates a new PDF document named for each student directly from the original scanned PDF document. No muss no fuss! – user3439894 May 12 at 22:31
1

I'd use the third-party command line tool, cpdf, and script the process of creating the separate PDF documents for each student.

Have a look at: Coherent PDF Command Line Tools Community Release

  • Download pre-built cpdf tool (This is a direct download link. Building from source is available from link on main page linked above.)
  • A comprehensive user manual for the PDF tools can be found as a PDF document, or browsable online.
  • Note: the Community Release version of Coherent PDF Command Line Tools is free.

There is no need to first extract the the scanned PDF document into individual files to then combine them as the following example shell script code extracts the pages from the scanned PDF document four pages at a time while naming each new PDF document for each student:

#!/bin/bash

    # Replace e.g. "Student 01", etc. with the students name
    # in the order required as scanned in the PDF document.

my_students=("Student 01" "Student 02" "Student 03" "Student 04" "Student 05" "Student 06" "Student 07" "Student 08" "Student 09" "Student 10")

    # Replace "/path/to/scanned.pdf" with the 
    # actual pathname of the scanned document.

scanned_document="/path/to/scanned.pdf"

    # NOTE: If cpdf is not in your PATH, then use its fully
    #       qualified pathname, e.g: /use/local/bin/cpdf

x=1
y=4
for this_student in "${my_students[@]}"; do
    cpdf "${scanned_document}" $x-$y -o "${this_student}.pdf"
    x=$(( x + 4 ))
    y=$(( y + 4 ))
done

To use this shell script in Terminal, first run the following compound command:

f="processpdf"; touch "$f"; open -e "$f"; chmod u+x "$f"

Then in the document that opens, TextEdit by default, copy and paste the example shell script code into it, make the appropriate edits, and then save it.

It can now be used in Terminal using e.g. ./processpdf or /path/to/processpdf or if placed in a location that's within the PATH, then simply, e.g.: processpdf

Note: As coded the new PDF documents are created in the PWD in Terminal. You can add e.g. /path/to/ to "${this_student}.pdf", e.g., "/path/to/${this_student}.pdf" if you want.

If you need/want to apply this to a Run Shell Script action in Automator, instead of regular shell script usage, let me know an I can update the answer.

In either case, if you want to pass the script a file with the names of the students, instead of using an array, as presently coded, that is doable too.


Note: The example shell script code is just that and does not contain any error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. As an example, as presently coded, the new PDF documents will overwrite existing documents of the same name without warning.

| improve this answer | |
1

You could skip that first step where you split the large PDF into one page to one file. Then take your large PDF and split it after every four pages into 10 different files. This basically undoes what you did first. The app PDFsam will split a PDF into files after every x pages. PDFSam stands for PDF Split and Merge.

| improve this answer | |

You must log in to answer this question.

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