Skip to content
Snippets Groups Projects

I173 print help doc in pdf

Merged Lan Dam requested to merge i173_print_help_doc_in_pdf into develop
All threads resolved!
Files
2
@@ -108,7 +108,11 @@ class HelpBrowser(QtWidgets.QWidget):
"""
self.search_results_path: Path = self.docdir_path.joinpath(
'Search Results.md')
"""
default_pdf_file_name: the default name for pdf file when the current
help document is saved
"""
self.default_pdf_file_name: str = ''
# Get screen dimensions
geom = QtGui.QGuiApplication.screens()[0].availableGeometry()
self.setGeometry(10, 10,
@@ -373,10 +377,20 @@ class HelpBrowser(QtWidgets.QWidget):
Load file from file_path to help_view
:param file_path: absolute path to a document
:type file_path: str
"""
url = QtCore.QUrl.fromLocalFile(file_path)
self.help_view.setSource(url)
self._set_default_pdf_file_name(file_path)
def _set_default_pdf_file_name(self, file_path: str) -> str:
"""
Set the default_pdf_file_name for the current help document
:param file_path: absolute path to a document
"""
file_name = file_path.split(' _ ')[1]
file_name = "SOHViewer Help - " + file_name
self.default_pdf_file_name = file_name.replace('.help.md', '')
@QtCore.Slot()
def on_tree_view_item_clicked(self, index: QtCore.QModelIndex):
@@ -541,15 +555,22 @@ class HelpBrowser(QtWidgets.QWidget):
def save_to_pdf(self):
"""
Save the current document to pdf file.
A3 size is selected because the current font look well in that. After
the document is saved, user can print it in the size they want. The
size of A3 is 11.7 x 16.5. So the width of pictures in the document
will be cut off if greater than (11.7 - margins).
Note: the pictures' width in the document must be smaller than 11 in/
1584px or its content will be cut off.
"""
home_path = Path.home()
doc_path = home_path.joinpath("Documents")
save_file = QtWidgets.QFileDialog.getSaveFileName(self, 'Save to PDF',
doc_path.as_posix())
if save_file:
filename = save_file[0]
file_path = doc_path.joinpath(self.default_pdf_file_name)
save_file = QtWidgets.QFileDialog.getSaveFileName(
self, 'Save to PDF', file_path.as_posix())[0]
if save_file != "":
filename = save_file
if not filename.endswith('.pdf'):
filename = filename + '.pdf'
printer = QPrinter(
@@ -560,6 +581,8 @@ class HelpBrowser(QtWidgets.QWidget):
printer.setOutputFormat(QPrinter.OutputFormat.PdfFormat)
printer.setOutputFileName(filename)
self.help_view.document().print_(printer)
msg = f"The current help document has been saved at {filename}"
QtWidgets.QMessageBox.information(self, "Document Saved", msg)
def main():
Loading