pdfsize.sh 633 B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/env bash
  2. # File: pdfsize.sh
  3. # Name: D.Saravanan
  4. # Date: 22/02/2024
  5. # Script to print the page size of a pdf file
  6. # Usage: ./pdfsize.sh input.pdf
  7. if [ -z "$(which pdfinfo)" ]; then
  8. echo "requires the pdfinfo utility provided by the poppler-utils package"
  9. exit 1
  10. fi
  11. # requires the pdfinfo utility provided by the poppler-utils package
  12. pdfsize() {
  13. pdfinfo "$1" | grep 'Page size' |
  14. awk '{printf "Page size: %.2f x %.2f mm\n", $3*25.4/72, $5*25.4/72}'
  15. }
  16. # check if the parameter is a valid PDF file
  17. if [[ -f "$1" && "$1" == *.pdf ]]; then
  18. pdfsize "$1"
  19. else
  20. echo "Please provide a valid PDF file as a parameter."
  21. fi