def save_pdf_format(qgis_utils, settings_path, title, text): settings = QSettings() new_filename, filter = QFileDialog.getSaveFileName( None, QCoreApplication.translate('Asistente-LADM_COL', 'Export to PDF'), settings.value(settings_path, '.'), filter="PDF (*.pdf)") if new_filename: settings.setValue(settings_path, os.path.dirname(new_filename)) new_filename = new_filename if new_filename.lower().endswith( ".pdf") else "{}.pdf".format(new_filename) txt_log = QTextEdit() txt_log.setHtml("{}<br>{}".format(title, text)) printer = QPrinter() printer.setPageSize(QPrinter.Letter) printer.setOutputFormat(QPrinter.PdfFormat) printer.setOutputFileName(new_filename) txt_log.print(printer) msg = QCoreApplication.translate( "Asistente-LADM_COL", "Report successfully generated in folder <a href='file:///{normalized_path}'>{path}</a>!" ).format(normalized_path=normalize_local_url(new_filename), path=new_filename) qgis_utils.message_with_duration_emitted.emit(msg, Qgis.Success, 0)
def export_title_text_to_pdf(filepath, title, text): filepath = filepath if filepath.lower().endswith( ".pdf") else "{}.pdf".format(filepath) txt_log = QTextEdit() txt_log.setHtml("{}<br>{}".format(title, text)) printer = QPrinter() printer.setPageSize(QPrinter.Letter) printer.setOutputFormat(QPrinter.PdfFormat) printer.setOutputFileName(filepath) txt_log.print(printer)