2016-04-15 21:58:09 +12:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# --!-- coding: utf8 --!--
|
2016-04-15 23:45:53 +12:00
|
|
|
import random
|
2016-04-16 00:04:07 +12:00
|
|
|
import shutil
|
2016-04-15 23:45:53 +12:00
|
|
|
|
2016-04-15 21:58:09 +12:00
|
|
|
from PyQt5.QtCore import QUrl
|
|
|
|
from PyQt5.QtWidgets import qApp
|
|
|
|
|
|
|
|
from manuskript.exporter.pandoc.abstractOutput import abstractOutput
|
2016-04-15 23:45:53 +12:00
|
|
|
from manuskript.functions import tempFile
|
|
|
|
from manuskript.ui.views.PDFViewer import PDFViewer
|
2016-04-15 21:58:09 +12:00
|
|
|
|
|
|
|
|
|
|
|
class PDF(abstractOutput):
|
2018-01-07 06:48:40 +13:00
|
|
|
"""PDF Viewer using PDF.js. Cf. https://github.com/mozilla/pdf.js/wiki/Setup-PDF.js-in-a-website"""
|
2016-04-15 23:45:53 +12:00
|
|
|
|
2016-04-15 21:58:09 +12:00
|
|
|
name = "PDF"
|
2018-02-13 06:39:16 +13:00
|
|
|
description = qApp.translate("Export", "Needs LaTeX to be installed.")
|
|
|
|
InvalidBecause = qApp.translate("Export", """a valid LaTeX installation. Pandoc recommendations can be found on:
|
|
|
|
<a href="https://pandoc.org/installing.html">pandoc.org/installing.html</a>. If you want Unicode support, you need XeLaTeX.""")
|
2016-04-15 21:58:09 +12:00
|
|
|
icon = "application-pdf"
|
|
|
|
|
|
|
|
exportVarName = "lastPandocPDF"
|
|
|
|
toFormat = "pdf"
|
|
|
|
exportFilter = "PDF files (*.pdf);; Any files (*)"
|
|
|
|
requires = {
|
|
|
|
"Settings": True,
|
|
|
|
"Preview": True,
|
|
|
|
}
|
|
|
|
|
2016-04-16 00:04:07 +12:00
|
|
|
def isValid(self):
|
2017-06-16 00:37:55 +12:00
|
|
|
path = shutil.which("pdflatex") or shutil.which("xelatex")
|
2016-04-16 00:04:07 +12:00
|
|
|
return path is not None
|
|
|
|
|
2016-04-15 21:58:09 +12:00
|
|
|
def output(self, settingsWidget, outputfile=None):
|
|
|
|
args = settingsWidget.runnableSettings()
|
|
|
|
args.remove("--to=pdf")
|
|
|
|
args.append("--to=latex")
|
|
|
|
src = self.src(settingsWidget)
|
|
|
|
return self.exporter.convert(src, args, outputfile)
|
|
|
|
|
|
|
|
def previewWidget(self):
|
2016-04-15 23:45:53 +12:00
|
|
|
return PDFViewer()
|
2016-04-15 21:58:09 +12:00
|
|
|
|
|
|
|
def preview(self, settingsWidget, previewWidget):
|
2016-04-15 23:45:53 +12:00
|
|
|
filename = tempFile("msk_pdfpreview.pdf")
|
|
|
|
|
|
|
|
settingsWidget.writeSettings()
|
2016-04-15 21:58:09 +12:00
|
|
|
content = self.output(settingsWidget, outputfile=filename)
|
|
|
|
|
2017-06-16 00:37:55 +12:00
|
|
|
previewWidget.loadPDF(filename)
|