3

I have, in the same directory, several odt files.

I'd like to have in one PDF document the first page of these odt files, sorted alphabetically based on their filename.

For example, if I have these files:

  • a.odt
  • b.odt
  • c.odt

I would have a resulting PDF that has 3 pages: the first one of a.odt, then the first one of b.odt and then the first one of c.pdf.

Does any one of you think about a command to do that?

5
#!/bin/bash
for i in *.odt; do
  echo "Converting [ $i ]"
  unoconv -f pdf "$i"
  echo "Extracting 1st page of [ $i ]"
  i="${i%odt}pdf"
  pdftk P="$i" cat P1-1 output "$i".1
done
echo "Merging pdfs"
pdftk *.1 cat output result.pdf
rm *.1

You have to install unoconv and pdftk.

Ubuntu: sudo apt-get install unoconv pdftk

  • 1
    You should probably use pdftk to merge the PDFs, not convert. convert will rasterize all the pages, so the fonts and any vector artwork will be converted to bitmaps, increasing the size of the PDF and reducing its quality. – Alan Shutko Jun 24 '14 at 13:00
  • One downside to pdftk is that it doesn't preserve bookmarks and metadata. You can create a dump of all metadata but importing it has never worked properly for me. If preserving this data is important to you, you can always use an alternative like sejda or cpdf. – Glutanimate Jun 24 '14 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.