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-15 21:58:09 +12:00
|
|
|
from PyQt5.QtCore import QUrl
|
|
|
|
from PyQt5.QtWebKit import QWebSettings
|
|
|
|
from PyQt5.QtWebKitWidgets import QWebView
|
|
|
|
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):
|
2016-04-15 23:45:53 +12:00
|
|
|
"""PDF Viewer using PDS.js. Cf. https://github.com/mozilla/pdf.js/wiki/Setup-PDF.js-in-a-website"""
|
|
|
|
|
2016-04-15 21:58:09 +12:00
|
|
|
name = "PDF"
|
|
|
|
description = qApp.translate("Export", "Needs latex to be installed.")
|
|
|
|
icon = "application-pdf"
|
|
|
|
|
|
|
|
exportVarName = "lastPandocPDF"
|
|
|
|
toFormat = "pdf"
|
|
|
|
exportFilter = "PDF files (*.pdf);; Any files (*)"
|
|
|
|
requires = {
|
|
|
|
"Settings": True,
|
|
|
|
"Preview": True,
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2016-04-15 23:45:53 +12:00
|
|
|
previewWidget.loadPDF(filename)
|