Add PDF orientation detection. Closes GitLab issue #387.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2017-06-16 22:29:36 -04:00
parent 86a351e826
commit 4150fea2ad
7 changed files with 49 additions and 0 deletions

View File

@@ -10,6 +10,7 @@ except ImportError:
from StringIO import StringIO
from PIL import Image
import PyPDF2
from pdfminer.pdfpage import PDFPage
import sh
@@ -67,6 +68,19 @@ class Python(ConverterBase):
finally:
fs_cleanup(input_filepath)
def detect_orientation(self, page_number):
# Use different ways depending on the file type
if self.mime_type == 'application/pdf':
pdf = PyPDF2.PdfFileReader(self.file_object)
result = pdf.getPage(page_number - 1).get('/Rotate')
self.file_object.seek(0)
return result
# Default rotation: 0 degrees
return 0
def get_page_count(self):
super(Python, self).get_page_count()