diff --git a/src/calibre/ebooks/conversion/plugins/pdf_output.py b/src/calibre/ebooks/conversion/plugins/pdf_output.py index cb0b88c7f3..be9a69fd42 100644 --- a/src/calibre/ebooks/conversion/plugins/pdf_output.py +++ b/src/calibre/ebooks/conversion/plugins/pdf_output.py @@ -51,8 +51,9 @@ class PDFOutput(OutputFormatPlugin): author = 'Kovid Goyal' file_type = 'pdf' commit_name = 'pdf_output' + ui_data = {'paper_sizes': PAPER_SIZES, 'units': UNITS, 'font_types': ['serif', 'sans', 'mono']} - options = set([ + options = { OptionRecommendation(name='use_profile_size', recommended_value=False, help=_('Instead of using the paper size specified in the PDF Output options,' ' use a paper size corresponding to the current output profile.' @@ -85,8 +86,7 @@ class PDFOutput(OutputFormatPlugin): OptionRecommendation(name='pdf_mono_family', recommended_value='Liberation Mono', help=_( 'The font family used to render monospace fonts')), - OptionRecommendation(name='pdf_standard_font', choices=['serif', - 'sans', 'mono'], + OptionRecommendation(name='pdf_standard_font', choices=ui_data['font_types'], recommended_value='serif', help=_( 'The font family used to render monospace fonts')), OptionRecommendation(name='pdf_default_font_size', @@ -148,7 +148,7 @@ class PDFOutput(OutputFormatPlugin): ' This will cause the margins specified in the conversion settings to be ignored.' ' If the document does not specify page margins, the conversion settings will be used as a fallback.') ), - ]) + } def specialize_options(self, log, opts, input_fmt): if opts.pdf_use_document_margins: diff --git a/src/calibre/gui2/convert/pdf_output.py b/src/calibre/gui2/convert/pdf_output.py index 72c3d64b8b..1192307358 100644 --- a/src/calibre/gui2/convert/pdf_output.py +++ b/src/calibre/gui2/convert/pdf_output.py @@ -43,6 +43,13 @@ class PluginWidget(Widget, Ui_Form): self.layout().setFieldGrowthPolicy(self.layout().ExpandingFieldsGrow) self.template_box.layout().setFieldGrowthPolicy(self.layout().AllNonFixedFieldsGrow) self.toggle_margins() + self.profile_size_toggled() + + def profile_size_toggled(self): + enabled = not self.opt_use_profile_size.isChecked() + self.opt_paper_size.setEnabled(enabled) + self.opt_custom_size.setEnabled(enabled) + self.opt_unit.setEnabled(enabled) def toggle_margins(self): enabled = not self.opt_pdf_use_document_margins.isChecked() @@ -71,3 +78,4 @@ class PluginWidget(Widget, Ui_Form): l.addRow(_('&Right:'), margin('right')) r.addRow(_('&Top:'), margin('top')) r.addRow(_('&Bottom:'), margin('bottom')) + self.opt_use_profile_size.toggled.connect(self.profile_size_toggled) diff --git a/src/pyj/book_list/conversion_widgets.pyj b/src/pyj/book_list/conversion_widgets.pyj index 3a09605b4f..8bc18625cf 100644 --- a/src/pyj/book_list/conversion_widgets.pyj +++ b/src/pyj/book_list/conversion_widgets.pyj @@ -627,6 +627,46 @@ def pdb_output(container): g.appendChild(checkbox('inline_toc', _('&Inline TOC'))) # }}} +# PDF Output {{{ +@ep +def pdf_output(container): + add_listener('use_profile_size', def (name): + disabled = get('use_profile_size') + for dname in 'paper_size', 'custom_size', 'unit': + set_disabled(dname, disabled) + ) + add_listener('pdf_use_document_margins', def (name): + disabled = get('pdf_use_document_margins') + for dname in 'left', 'top', 'right', 'bottom': + set_disabled(f'pdf_page_margin_{dname}', disabled) + ) + + g = E.div(class_='simple-group') + container.appendChild(g) + g.appendChild(checkbox('use_profile_size', _('&Use the paper size set in output profile'))) + g.appendChild(choices('paper_size', indent + _('&Paper size:'), ui_data.paper_sizes)) + g.appendChild(lineedit('custom_size', indent + _('&Custom size:'))) + g.appendChild(choices('unit', indent + _('Custom size unit:'), ui_data.units)) + g.appendChild(checkbox('preserve_cover_aspect_ratio', _('Preserve &aspect ratio of cover'))) + g.appendChild(checkbox('pdf_page_numbers', _('Add page &numbers to the bottom of every page'))) + g.appendChild(checkbox('pdf_hyphenate', _('&Break long words at the end of lines'))) + g.appendChild(checkbox('pdf_add_toc', _('Add a printable &Table of Contents at the end'))) + g.appendChild(lineedit('toc_title', indent + _('&Title for ToC:'))) + g.appendChild(lineedit('pdf_serif_family', _('Serif famil&y:'))) + g.appendChild(lineedit('pdf_sans_family', _('Sans fami&ly:'))) + g.appendChild(lineedit('pdf_mono_family', _('&Monospace family:'))) + g.appendChild(choices('pdf_standard_font', _('S&tandard font:'), ui_data.font_types)) + g.appendChild(int_spin('pdf_default_font_size', _('Default font si&ze:'), unit='px')) + g.appendChild(int_spin('pdf_mono_font_size', _('Default font si&ze:'), unit='px')) + g.appendChild(checkbox('pdf_use_document_margins', _('Use page margins from the &document being converted'))) + g.appendChild(float_spin('pdf_page_margin_left', indent + _('Left page margin'), unit='pt', min=-100, max=500)) + g.appendChild(float_spin('pdf_page_margin_top', indent + _('Top page margin'), unit='pt', min=-100, max=500)) + g.appendChild(float_spin('pdf_page_margin_right', indent + _('Right page margin'), unit='pt', min=-100, max=500)) + g.appendChild(float_spin('pdf_page_margin_bottom', indent + _('Bottom page margin'), unit='pt', min=-100, max=500)) + g.appendChild(lineedit('pdf_header_template', _('&Header template:'))) + g.appendChild(lineedit('pdf_footer_template', _('&Footer template:'))) +# }}} + def restore_defaults(): for setting in registry: set(setting, get_option_default_value(setting))