Improve office documents page number detection

This commit is contained in:
Roberto Rosario
2011-11-22 05:51:02 -04:00
parent ba7016b0bc
commit da4457b258

View File

@@ -15,6 +15,7 @@ from converter.literals import DIMENSION_SEPARATOR
from converter.literals import FILE_FORMATS
from converter.utils import cleanup
from converter.runtime import office_converter
from converter.exceptions import OfficeConversionError
HASH_FUNCTION = lambda x: hashlib.sha256(x).hexdigest()
@@ -61,7 +62,7 @@ def convert(input_filepath, output_filepath=None, cleanup_files=False, mimetype=
# Recycle the already detected mimetype
mimetype = office_converter.mimetype
except OfficeConverter:
except OfficeConversionError:
raise UnknownFileFormat('office converter exception')
if size:
@@ -98,14 +99,15 @@ def convert(input_filepath, output_filepath=None, cleanup_files=False, mimetype=
def get_page_count(input_filepath):
office_converter = OfficeConverter()
office_converter.convert(input_filepath)
if office_converter:
try:
input_filepath = office_converter.output_filepath
except OfficeConverter:
raise UnknownFileFormat('office converter exception')
office_converter.convert(input_filepath)
if office_converter.exists:
input_filepath = office_converter.output_filepath
except OfficeConversionError:
raise UnknownFileFormat('office converter exception')
return backend.get_page_count(input_filepath)