I made a huge .pdf

Let's write something in english.

Why

Yesterday the librarian of my school came in Atilla (kind of a student hackerspace in EISTI Cergy) with a problem : 40 students homework in 40 subfolders of a huge .zip dumped in her mailbox by the school platform.

She had to go, couldn't print it for some reason : (some students didn't put their names on their documents, and the title of the documents isn't printed on every page in our school. Moreover she would have to put all the 40 files in the same folder to select everything and click 'print'.)

She needed to read and correct the printed version of these homeworks elsewhere. I managed to make a big .pdf with the students names on each corresponding page.

How

I converted all the .docx and .odt to pdfs using libreoffice command line utility, soffice :

#docx
for i in */*.docx;
do
  fd=${i%/*};         # folder 
  fn=${i##*/};        # filename
  nf=${fn/docx/pdf};  # new file name
  echo $fd $fn $nf;   # 
  soffice --headless --convert-to pdf $i; # generate a .pdf
  mv $nf ${fd}/$nf;   # move the .pdf in the right folder
done
# odt
for i in */*.odt;
do
  fd=${i%/*};         # folder 
  fn=${i##*/};        # filename
  nf=${fn/odt/pdf};   # new file name
  echo $fd $fn $nf;   # 
  soffice --headless --convert-to pdf $i; # generate a .pdf
  mv $nf ${fd}/$nf;   # move the .pdf in the right folder
done

I generated blank A4 pdfs with their folder name in the upper corner, *-stamp.pdf

for i in `ls */. -d`; # for each folder
do
  # ghostscript did everything.
  gs -o ${i}/${i%*/.}-stamp.pdf -sDEVICE=pdfwrite -c "/Courier findfont 12 scalefont setfont 5 800 moveto (${i%*/.}) show showpage" ;
done

I stamped this page to all the students pdf pages in a new pdf, *-final.pdf

for i in `ls */. -d`;
do
  folder=${i%/.};                                 # folder name
  stamp=${folder}/${i%/.}-stamp.pdf;              # stamp file name
  nostamp=`ls ${folder}/*.pdf | grep -v stamp`;   # document name
  outdoc=${stamp/stamp/final}                     # output name, replacing stamp by final
  # pdftk has a 'background' stamping feature :
  pdftk $nostamp background $stamp output ${outdoc};
done

I merged all the pdfs with the 'cat' feature :

pdftk */*final.pdf cat output yolo.pdf

Done. I won some food. I hope this will allow you to eat again.

blogroll

social