Replace printer with Qt's PDF writer
This commit is contained in:
@@ -29,10 +29,9 @@ from pathlib import Path
|
|||||||
|
|
||||||
from PyQt5.QtCore import QMarginsF, QSizeF
|
from PyQt5.QtCore import QMarginsF, QSizeF
|
||||||
from PyQt5.QtGui import (
|
from PyQt5.QtGui import (
|
||||||
QColor, QFont, QFontMetricsF, QPageSize, QTextBlockFormat, QTextCharFormat,
|
QColor, QFont, QFontMetricsF, QPageLayout, QPageSize, QPdfWriter,
|
||||||
QTextCursor, QTextDocument
|
QTextBlockFormat, QTextCharFormat, QTextCursor, QTextDocument
|
||||||
)
|
)
|
||||||
from PyQt5.QtPrintSupport import QPrinter
|
|
||||||
|
|
||||||
from novelwriter.constants import nwStyles, nwUnicode
|
from novelwriter.constants import nwStyles, nwUnicode
|
||||||
from novelwriter.core.project import NWProject
|
from novelwriter.core.project import NWProject
|
||||||
@@ -67,7 +66,7 @@ class ToQTextDocument(Tokenizer):
|
|||||||
super().__init__(project)
|
super().__init__(project)
|
||||||
self._document = QTextDocument()
|
self._document = QTextDocument()
|
||||||
self._document.setUndoRedoEnabled(False)
|
self._document.setUndoRedoEnabled(False)
|
||||||
self._document.setDocumentMargin(0)
|
self._document.setDocumentMargin(0.0)
|
||||||
|
|
||||||
self._usedNotes: dict[str, int] = {}
|
self._usedNotes: dict[str, int] = {}
|
||||||
self._usedFields: list[tuple[int, str]] = []
|
self._usedFields: list[tuple[int, str]] = []
|
||||||
@@ -241,17 +240,14 @@ class ToQTextDocument(Tokenizer):
|
|||||||
|
|
||||||
def saveDocument(self, path: Path) -> None:
|
def saveDocument(self, path: Path) -> None:
|
||||||
"""Save the document as a PDF file."""
|
"""Save the document as a PDF file."""
|
||||||
m = self._pageMargins
|
writer = QPdfWriter(str(path))
|
||||||
|
writer.setTitle(self._project.data.name)
|
||||||
printer = QPrinter(QPrinter.PrinterMode.PrinterResolution)
|
writer.setPageSize(self._pageSize)
|
||||||
printer.setOutputFormat(QPrinter.OutputFormat.PdfFormat)
|
writer.setPageMargins(self._pageMargins, QPageLayout.Unit.Millimeter)
|
||||||
printer.setPageSize(self._pageSize)
|
writer.setResolution(1200)
|
||||||
printer.setPageMargins(m.left(), m.top(), m.right(), m.bottom(), QPrinter.Unit.Millimeter)
|
self._document.setDocumentMargin(0.0)
|
||||||
printer.setOutputFileName(str(path))
|
self._document.setPageSize(QSizeF(writer.pageLayout().paintRectPoints().size())*16/12)
|
||||||
|
self._document.print(writer)
|
||||||
self._document.setPageSize(self._pageSize.size(QPageSize.Unit.Point))
|
|
||||||
self._document.print(printer)
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def closeDocument(self) -> None:
|
def closeDocument(self) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user