PDF Output: Add an option to shift text horizontally on odd/even pages. Fixes #1853155 [PDF Output with even/odd page margins](https://bugs.launchpad.net/calibre/+bug/1853155)

This commit is contained in:
Kovid Goyal 2019-11-22 09:56:23 +05:30
parent 6ce63fcec9
commit 8d07d6bf55
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
5 changed files with 53 additions and 4 deletions

View File

@ -304,7 +304,7 @@ OPTIONS = {
'pdf_footer_template', 'pdf_header_template', 'pdf_add_toc',
'toc_title', 'pdf_page_margin_left', 'pdf_page_margin_top',
'pdf_page_margin_right', 'pdf_page_margin_bottom',
'pdf_use_document_margins', 'pdf_page_number_map',),
'pdf_use_document_margins', 'pdf_page_number_map', 'pdf_odd_even_offset'),
'pml': ('inline_toc', 'full_image_depth', 'pml_output_encoding'),

View File

@ -130,6 +130,18 @@ class PDFOutput(OutputFormatPlugin):
recommended_value=False, help=_(
'Generate an uncompressed PDF, useful for debugging.')
),
OptionRecommendation(name='pdf_odd_even_offset', recommended_value=0.0,
level=OptionRecommendation.LOW,
help=_(
'Shift the text horizontally by the specified offset (in pts).'
' On odd numbered pages, it is shifted to the right and on even'
' numbered pages to the left. Use negative numbers for the opposite'
' effect. Note that this setting is ignored on pages where the margins'
' are smaller than the specified offset. Shifting is done by setting'
' the PDF CropBox, not all software respects the CropBox.'
)
),
}
def specialize_options(self, log, opts, input_fmt):

View File

@ -1213,6 +1213,16 @@ def convert(opf_path, opts, metadata=None, output_path=None, log=default_log, co
if num_removed:
log('Removed', num_removed, 'duplicate images')
if opts.pdf_odd_even_offset:
for i in range(1, pdf_doc.page_count()):
margins = page_margins_map[i]
mult = -1 if i % 2 else 1
val = opts.pdf_odd_even_offset
if abs(val) < min(margins.left, margins.right):
box = list(pdf_doc.get_page_box("CropBox", i))
box[0] += val * mult
pdf_doc.set_page_box("CropBox", i, *box)
if cover_data:
add_cover(pdf_doc, cover_data, page_layout, opts)

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>638</width>
<height>634</height>
<height>665</height>
</rect>
</property>
<property name="windowTitle">
@ -210,14 +210,14 @@
<item row="16" column="1">
<widget class="QLineEdit" name="opt_pdf_page_number_map"/>
</item>
<item row="17" column="0" colspan="2">
<item row="18" column="0" colspan="2">
<widget class="QGroupBox" name="page_margins_box">
<property name="title">
<string>Page margins</string>
</property>
</widget>
</item>
<item row="18" column="0" colspan="2">
<item row="19" column="0" colspan="2">
<widget class="QGroupBox" name="template_box">
<property name="title">
<string>Page headers and footers</string>
@ -272,6 +272,32 @@
</property>
</widget>
</item>
<item row="17" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Odd/even &amp;offset:</string>
</property>
<property name="buddy">
<cstring>opt_pdf_odd_even_offset</cstring>
</property>
</widget>
</item>
<item row="17" column="1">
<widget class="QDoubleSpinBox" name="opt_pdf_odd_even_offset">
<property name="suffix">
<string> pt</string>
</property>
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>

View File

@ -664,6 +664,7 @@ def pdf_output(container):
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(float_spin('pdf_odd_even_offset', indent + _('Odd/event offset'), unit='pt', min=-500, max=500))
g.appendChild(lineedit('pdf_header_template', _('&Header template:')))
g.appendChild(lineedit('pdf_footer_template', _('&Footer template:')))
# }}}