Fix #1478515 [print to pdf filename uses illegal path characters](https://bugs.launchpad.net/calibre/+bug/1478515)

This commit is contained in:
Kovid Goyal 2015-07-27 17:39:23 +05:30
parent 4699aaaf56
commit 24b71ed3e0

View File

@ -13,6 +13,7 @@ from PyQt5.Qt import (
QFormLayout, QLineEdit, QToolButton, QHBoxLayout, QLabel, QIcon, QPrinter,
QPageSize, QComboBox, QDoubleSpinBox, QCheckBox, QProgressDialog, QTimer)
from calibre import sanitize_file_name2
from calibre.ptempfile import PersistentTemporaryFile
from calibre.ebooks.conversion.plugins.pdf_output import PAPER_SIZES
from calibre.gui2 import elided_text, error_dialog, choose_save_file, Application, open_local_file, dynamic
@ -28,7 +29,7 @@ class PrintDialog(Dialog):
def __init__(self, book_title, parent=None, prefs=vprefs):
self.book_title = book_title
self.default_file_name = book_title[:75] + '.pdf'
self.default_file_name = sanitize_file_name2(book_title[:75] + '.pdf')
self.paper_size_map = {a:getattr(QPageSize, a.capitalize()) for a in PAPER_SIZES}
Dialog.__init__(self, _('Print to PDF'), 'print-to-pdf', prefs=prefs, parent=parent)
@ -86,8 +87,14 @@ class PrintDialog(Dialog):
@property
def data(self):
fpath = self.file_name.text().strip()
head, tail = os.path.split(fpath)
tail = sanitize_file_name2(tail)
fpath = tail
if head:
fpath = os.path.join(head, tail)
ans = {
'output': self.file_name.text().strip(),
'output': fpath,
'paper_size': self.paper_size.currentText().lower(),
'page_numbers':self.pnum.isChecked(),
'show_file':self.show_file.isChecked(),