Skip to content

Commit

Permalink
Merge pull request #50 from kylemacfarlane/includepdf
Browse files Browse the repository at this point in the history
Fix includePdfPages inserting a blank page when it's the first flowable in a PDF
  • Loading branch information
strichter committed Jan 8, 2017
2 parents bcf26cf + 8b13ece commit eb99667
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/z3c/rml/pdfinclude.py
Expand Up @@ -167,17 +167,24 @@ def process(self, inputFile1):

class IncludePdfPagesFlowable(flowables.Flowable):

def __init__(self, pdf_file, pages, concatprocessor):
def __init__(self, pdf_file, pages, concatprocessor,
included_on_first_page):
flowables.Flowable.__init__(self)
self.pdf_file = pdf_file
self.proc = concatprocessor
self.pages = pages
self.included_on_first_page = included_on_first_page

self.width = 10<<32
self.height = 10<<32
if self.included_on_first_page:
self.width = 0
self.height = 0
else:
self.width = 10<<32
self.height = 10<<32

def draw():
return NotImplementedError('PDFPages shall be drawn not me')
def draw(self):
if self.included_on_first_page:
self.split(None, None)

def split(self, availWidth, availheight):
pages = self.pages
Expand All @@ -188,6 +195,8 @@ def split(self, availWidth, availheight):
num_pages = sum(pr[1]-pr[0] for pr in pages)

start_page = self.canv.getPageNumber()
if self.included_on_first_page:
start_page -= 1
self.proc.operations.append(
(start_page, self.pdf_file, pages, num_pages))

Expand Down Expand Up @@ -242,7 +251,9 @@ def process(self):
args = dict(self.getAttributeValues())
proc = self.getProcessor()
self.parent.flow.append(
IncludePdfPagesFlowable(args['filename'], args.get('pages'), proc))
IncludePdfPagesFlowable(
args['filename'], args.get('pages'), proc, not self.parent.flow
))


flowable.Flow.factories['includePdfPages'] = IncludePdfPages
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit eb99667

Please sign in to comment.