datatracker/ietf/utils/pdf.py
Henrik Levkowetz 618d6021b0 Read pdf files as binary.
- Legacy-Id: 16510
2019-07-17 16:05:19 +00:00

22 lines
473 B
Python

# Copyright The IETF Trust 2015-2019, All Rights Reserved
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
import io
import re
def pdf_pages(filename):
"""Return number of pages in PDF."""
try:
infile = io.open(filename, "rb")
except IOError:
return 0
for line in infile:
m = re.match(br'\] /Count ([0-9]+)',line)
if m:
return int(m.group(1))
return 0