Add PDF orientation detection. Closes GitLab issue #387.
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
@@ -214,6 +214,10 @@ class ConverterBase(object):
|
||||
except InvalidOfficeFormat as exception:
|
||||
logger.debug('Is not an office format document; %s', exception)
|
||||
|
||||
def detect_orientation(self, page_number):
|
||||
# Must be overrided by subclass
|
||||
pass
|
||||
|
||||
|
||||
class BaseTransformation(object):
|
||||
"""
|
||||
|
||||
@@ -102,3 +102,11 @@ class TransformationManager(models.Manager):
|
||||
return result
|
||||
else:
|
||||
return transformations
|
||||
|
||||
def add_for_model(self, obj, transformation, arguments=None):
|
||||
content_type = ContentType.objects.get_for_model(obj)
|
||||
|
||||
self.create(
|
||||
content_type=content_type, object_id=obj.pk,
|
||||
name=transformation.name, arguments=arguments
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user