Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:smarty12:Python
pdfposter
0002-Add-overlap-percent-option.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0002-Add-overlap-percent-option.patch of Package pdfposter
From f0462f69ad60871e659aa372d331b5ae71421b4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaus=20K=C3=A4mpf?= <kkaempf@suse.de> Date: Mon, 29 Feb 2016 13:04:00 +0100 Subject: [PATCH 2/4] Add --overlap-percent option --- pdfposter.rst | 10 +++++++++ pdftools/pdfposter/__init__.py | 51 ++++++++++++++++++++++++++++++++---------- pdftools/pdfposter/cmd.py | 6 ++++- 3 files changed, 54 insertions(+), 13 deletions(-) diff --git a/pdfposter.rst b/pdfposter.rst index 9b151b28905c..f38ba80fb137 100644 --- a/pdfposter.rst +++ b/pdfposter.rst @@ -71,6 +71,16 @@ General Options only optional in version 0.6.0dev.jw; older versions always trim their output pages. With -t, printers may center the pages (giving unpredictable margins). +-O, --overlap-percent NNN Specify scale factor for input document pages. + If this factor is positive, the input pages actually +overlap + (or often only their margins overlap harmlessly). A negative factor + increases margins. + The factor is given in percent of the input page size. Default 0. + + -O 5 or -O 10 is suggested to compensate for printers that leave white + margins instead of printing the entire images of the page. What is + technically an overlap, now closes the gap. + Defining Input diff --git a/pdftools/pdfposter/__init__.py b/pdftools/pdfposter/__init__.py index 9e22330cd4a2..34d6938ee613 100755 --- a/pdftools/pdfposter/__init__.py +++ b/pdftools/pdfposter/__init__.py @@ -33,6 +33,7 @@ from logging import log import math DEFAULT_MEDIASIZE = 'a4' +DEFAULT_OVERLAP_PERCENT = 0 mm = 72 / 25.4 @@ -138,8 +139,8 @@ def rotate2portrait(box, which): log(18, 'Rotating %s specs to portrait format', which) return True -def decide_num_pages(inbox, mediabox, posterbox, scale=None): - """decide on number of pages""" +def decide_num_pages(inbox, mediabox, posterbox, scale=None, overlap = 0.0, overlap_reduces_scale = True): + """decide on number of pages, also compute scale""" # avoid changing original posterbox when handling multiple pages # (if --scale, posterbox is None) posterbox = posterbox and posterbox.copy() @@ -180,9 +181,32 @@ def decide_num_pages(inbox, mediabox, posterbox, scale=None): posterbox['height'] / inbox_y) log(18, 'Calculated page scaling factor: %f', scale) + # Overlap and scale complement each other. + scale_with_overlap = scale + if overlap != 0.0: + log(18, "Overlap: %s", overlap) + + if overlap_reduces_scale: + # If the exact poster size is not needed, we can also make the + # poster a little smaller, and use the planned poster space + # for the printout including overlap. In that case, the + # resulting poster will be smaller by overlap percent, but we + # won't have small strips at the border of the poster, which + # would be needed to get to the exact desired output size. + scale = scale * (1 - overlap) + log(17, ' true page scaling factor, reduced by overlap: %f', scale) + else: + # If there is overlap, and we want exactly the desired poster + # size, we need to adjust the poster size, such that the + # *overlapped* outputs give the desired poster size. That + # usually results in a number of small strips on the right and + # lower border of the poster. + scale_with_overlap = scale / (1 - overlap) + log(17, ' overlap-adjusted page scaling factor: %f', scale_with_overlap) + # use round() to avoid floating point roundup errors - size_x = round(inbox_x*scale - whitemargin['x'], 4) - size_y = round(inbox_y*scale - whitemargin['y'], 4) + size_x = round(inbox_x*scale_with_overlap - whitemargin['x'], 4) + size_y = round(inbox_y*scale_with_overlap - whitemargin['y'], 4) log(17, 'output dimensions: %.2f %.2f (calculated)', size_x, size_y) # num pages without rotation @@ -192,8 +216,8 @@ def decide_num_pages(inbox, mediabox, posterbox, scale=None): nx1 = int(math.ceil( size_x / drawable_y)) ny1 = int(math.ceil( size_y / drawable_x)) - log(17, 'Pages w/o rotation %s x %s' , nx0, ny0) - log(17, 'Pages w/ rotation %s x %s' , nx1, ny1) + log(17, 'Pages w/o rotation %s x %s = %s' , nx0, ny0, nx0 * ny0) + log(17, 'Pages w/ rotation %s x %s = %s' , nx1, ny1, nx1 * ny1) # Decide for rotation to get the minimum page count. # (Rotation is considered as media versus input page, which is @@ -239,7 +263,7 @@ def _clip_pdf_page(page, x, y, width, height): def _scale_pdf_page(outpdf, page, factor): for boxname in PAGE_BOXES: - # skip if real box does not exits (avoid fallback to other boxes) + # skip if real box does not exist (avoid fallback to other boxes) if not page.get(boxname): continue box = getRectangle(page, boxname, None) @@ -256,11 +280,12 @@ def _scale_pdf_page(outpdf, page, factor): page[NameObject('/Contents')] = outpdf._addObject(content) -def posterize(outpdf, page, mediabox, posterbox, scale, use_ArtBox=False, trimpage=False): +def posterize(outpdf, page, mediabox, posterbox, scale, use_ArtBox=False, overlap=0.02, overlap_reduces_scale=True, trimpage=False): """ page: input page mediabox : size secs of the media to print on posterbox: size secs of the resulting poster + overlap: overlap of the media pages, if negative: downsize poster by the overlap scale: scale factor (to be used instead of posterbox) """ if use_ArtBox: @@ -270,8 +295,10 @@ def posterize(outpdf, page, mediabox, posterbox, scale, use_ArtBox=False, trimpa _clip_pdf_page(page, inbox['offset_x'], inbox['offset_y'], inbox['width'], inbox['height']) ncols, nrows, scale, rotate = decide_num_pages(inbox, mediabox, - posterbox, scale) + posterbox, scale, overlap, overlap_reduces_scale) mediabox = mediabox.copy() + # The overlap adds to the physical printout size, so after + # overlapping the pages you get the real poster size. _scale_pdf_page(outpdf, page, scale) if rotate: page.rotateClockwise(90) @@ -306,8 +333,8 @@ def posterize(outpdf, page, mediabox, posterbox, scale, use_ArtBox=False, trimpa newpage.trimBox = newpage.mediaBox newpage.artBox = newpage.trimBox outpdf.addPage(newpage) - v_pos -= v_step - h_pos += h_step + v_pos -= v_step*(1.0-overlap) + h_pos += h_step*(1.0-overlap) def password_hook(): import getpass @@ -344,7 +371,7 @@ def main(opts, infilename, outfilename, password_hook=password_hook): page = inpdf.getPage(i) log(19, '---- processing page %i -----', i+1) posterize(outpdf, page, opts.media_size, opts.poster_size, opts.scale, - opts.use_ArtBox, opts.trimpage) + opts.use_ArtBox, opts.overlap_percent*0.01, opts.overlap_reduces_scale, opts.trimpage) if not opts.dry_run: outpdf.write(open(outfilename, 'wb')) diff --git a/pdftools/pdfposter/cmd.py b/pdftools/pdfposter/cmd.py index 8588c9575906..6c2035b6c19d 100644 --- a/pdftools/pdfposter/cmd.py +++ b/pdftools/pdfposter/cmd.py @@ -23,7 +23,7 @@ __author__ = "Hartmut Goebel <h.goebel@crazy-compilers.com>" __copyright__ = "Copyright 2008-2013 by Hartmut Goebel <h.goebel@crazy-compilers.com>" __licence__ = "GNU General Public License version 3 (GPL v3)" -from . import main, __version__, DEFAULT_MEDIASIZE, papersizes, DecryptionError +from . import main, __version__, DEFAULT_MEDIASIZE, DEFAULT_OVERLAP_PERCENT, papersizes, DecryptionError import re import PyPDF2.utils @@ -109,6 +109,10 @@ def run(): help='Specify the poster size (defaults to media size). ') group.add_option('-s', '--scale', type=float, help='Specify a linear scaling factor to produce the poster.') + group.add_option('-O', '--overlap-percent', type=float, default = DEFAULT_OVERLAP_PERCENT, + help='Image overlap (default: %g).' % DEFAULT_OVERLAP_PERCENT) + group.add_option('-S', '--overlap-reduces-scale', action='store_true', default=False, + help='When Overlapping (-O), make the real poster overlap_percent smaller.') opts, args = parser.parse_args() -- 2.7.1
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor