LoginSignup
3
3

More than 5 years have passed since last update.

PDF のサイズ、回転を表示 (Python3)

Posted at

コマンドで表示

$ pdfinfo sample01.pdf 
Producer:       PyPDF2
Tagged:         no
UserProperties: no
Suspects:       no
Form:           none
JavaScript:     no
Pages:          1
Encrypted:      no
Page size:      1190.55 x 841.89 pts
Page rot:       90
File size:      49884 bytes
Optimized:      no
PDF version:    1.3

Python で表示

pdf_spec.py
#! /usr/bin/python
# -*- coding: utf-8 -*-
#
#   pdf_spec.py
#
#                       Jan/11/2019
#
# ------------------------------------------------------------------
import  sys
#
import  PyPDF2
# ------------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")
#
file_in = sys.argv[1]
#
sys.stderr.write(file_in + "\n")
#
pdf_first = open(file_in,'rb')
pdf_reader = PyPDF2.PdfFileReader(pdf_first)
page_a = pdf_reader.getPage(0)
print(page_a.mediaBox.lowerLeft)
print(page_a.mediaBox.upperRight)
print(page_a.get('/Rotate'))
#
pdf_first.close()
#
sys.stderr.write("*** 終了 ***\n")
# ------------------------------------------------------------------

実行例

$ ./pdf_spec.py sample01.pdf 
*** 開始 ***
sample01.pdf
(0, 0)
(1190.551, 841.8898)
90
*** 終了 ***
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3