forked from openlp/openlp
Introduce PyMuPDF as additional PDF controller
This commit is contained in:
parent
5455778f33
commit
a610133919
@ -34,6 +34,12 @@ from openlp.plugins.presentations.lib.presentationcontroller import Presentation
|
|||||||
if is_win():
|
if is_win():
|
||||||
from subprocess import STARTUPINFO, STARTF_USESHOWWINDOW
|
from subprocess import STARTUPINFO, STARTF_USESHOWWINDOW
|
||||||
|
|
||||||
|
try:
|
||||||
|
import fitz
|
||||||
|
PYMUPDF_AVAILABLE = True
|
||||||
|
except ImportError:
|
||||||
|
PYMUPDF_AVAILABLE = False
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
PDF_CONTROLLER_FILETYPES = ['pdf', 'xps', 'oxps']
|
PDF_CONTROLLER_FILETYPES = ['pdf', 'xps', 'oxps']
|
||||||
@ -151,7 +157,9 @@ class PdfController(PresentationController):
|
|||||||
return True
|
return True
|
||||||
elif self.gsbin:
|
elif self.gsbin:
|
||||||
return True
|
return True
|
||||||
else:
|
elif PYMUPDF_AVAILABLE:
|
||||||
|
self.also_supports = ['xps', 'oxps']
|
||||||
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def kill(self):
|
def kill(self):
|
||||||
@ -276,6 +284,16 @@ class PdfDocument(PresentationDocument):
|
|||||||
'-r{res}'.format(res=resolution), '-dTextAlphaBits=4', '-dGraphicsAlphaBits=4',
|
'-r{res}'.format(res=resolution), '-dTextAlphaBits=4', '-dGraphicsAlphaBits=4',
|
||||||
'-sOutputFile={output}'.format(output=temp_dir_path / 'mainslide%03d.png'),
|
'-sOutputFile={output}'.format(output=temp_dir_path / 'mainslide%03d.png'),
|
||||||
str(self.file_path)], startupinfo=self.startupinfo)
|
str(self.file_path)], startupinfo=self.startupinfo)
|
||||||
|
elif PYMUPDF_AVAILABLE:
|
||||||
|
log.debug('loading presentation using PyMuPDF')
|
||||||
|
pdf = fitz.open(str(self.file_path))
|
||||||
|
for i, page in enumerate(pdf, start=1):
|
||||||
|
src_size = page.bound().round()
|
||||||
|
# keep aspect ratio
|
||||||
|
scale = min(size.width() / src_size.width, size.height() / src_size.height)
|
||||||
|
m = fitz.Matrix(scale, scale)
|
||||||
|
page.getPixmap(matrix=m, alpha=False).writeImage(str(temp_dir_path / 'mainslide{:03d}.png'.format(i)))
|
||||||
|
pdf.close()
|
||||||
created_files = sorted(temp_dir_path.glob('*'))
|
created_files = sorted(temp_dir_path.glob('*'))
|
||||||
for image_path in created_files:
|
for image_path in created_files:
|
||||||
if image_path.is_file():
|
if image_path.is_file():
|
||||||
|
1
setup.py
1
setup.py
@ -187,6 +187,7 @@ using a computer and a data projector.""",
|
|||||||
'websockets'
|
'websockets'
|
||||||
],
|
],
|
||||||
extras_require={
|
extras_require={
|
||||||
|
'agpl-pdf': ['PyMuPDF'],
|
||||||
'darkstyle': ['QDarkStyle'],
|
'darkstyle': ['QDarkStyle'],
|
||||||
'mysql': ['mysql-connector-python'],
|
'mysql': ['mysql-connector-python'],
|
||||||
'odbc': ['pyodbc'],
|
'odbc': ['pyodbc'],
|
||||||
|
Loading…
Reference in New Issue
Block a user