Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

It's easy to find the page count of a PDF document from the command line:

pdfinfo sample.pdf | grep ^Pages:

... but I haven't been able to find a similar method for odt files and other office documents.

Is there a way to programmatically determine the page count of these documents?

share|improve this question
add comment

3 Answers 3

I didn't find a way to extract odt file info as pdfinfo does, but you can create a fast script to use pdfinfo with the odt files, converting each odt file to PDF and later deleting the converted file if you are not going to use it:

libreoffice --headless --invisible --convert-to pdf sample.odt
pdfinfo sample.pdf | grep ^Pages:
rm sample.pdf

Hope that this helped you.

share|improve this answer
add comment
unzip -p document.odt meta.xml | grep -o 'page-count="[0-9]*"'

See here for more reference.

share|improve this answer
    
Thank you for the link! that was a very interesting read. I would have accepted your answer but I found a few other nifty commands for other office docs and compiled them in an answer of my own. I hope you don't mind. –  Glutanimate Jun 8 '13 at 16:16
add comment
up vote 3 down vote accepted

Thanks for all the answers, everyone. With your help I was able to compile a list of commands that can extract the page count from almost all relevant office documents:

DOCX/PPTX

unzip -p 'sample.docx' docProps/app.xml | grep -oP '(?<=\<Pages\>).*(?=\</Pages\>)'

unzip -p 'sample.pptx' docProps/app.xml | grep -oP '(?<=\<Slides\>).*(?=\</Slides\>)'

Note: unzip can be installed with sudo apt-get install unzip.

DOC/PPT

wvSummary sample.doc | grep -oP '(?<=of Pages = )[ A-Za-z0-9]*'

wvSummary sample.ppt | grep -oP '(?<=of Slides = )[ A-Za-z0-9]*'

Note: wvSummary (case-sensitive!) is part of the wv package. Install it with sudo apt-get install wv.

ODT

unzip -p sample.odt meta.xml | grep -oP '(?<=page-count=")[ A-Za-z0-9]*'

PDF

pdfinfo sample.pdf | grep -oP '(?<=Pages:          )[ A-Za-z0-9]*'

Note: pdfinfo is part of poppler-utils and should come preinstalled on Ubuntu.

DJVU

djvused -e "n" sample.djvu

Note: djvused is part of the djvulibre-bin package and may be installed with sudo apt-get install djvulibre-bin.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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