Skip to content

Commit

Permalink
add option to combine pdfs with pdftk
Browse files Browse the repository at this point in the history
  • Loading branch information
olibia committed Mar 26, 2019
1 parent 79bcd38 commit 528dbf9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions multipage_export.inx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<param name="options-title" type="description" appearance="header">Options</param>
<param name="replace" type="boolean" gui-text="Replace existing files">false</param>
<param name="autoname" type="boolean" gui-text="Name files from object IDs">false</param>
<param name="combine" type="boolean" gui-text="Combine into single PDF">false</param>

<effect needs-live-preview="false">
<object-type>all</object-type>
Expand Down
16 changes: 16 additions & 0 deletions multipage_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(self):
self.OptionParser.add_option('-f', '--format', action='store', type='string', dest='format', help='File format')
self.OptionParser.add_option('-a', '--autoname', action='store', type='string', dest='autoname', help='Use IDs for names')
self.OptionParser.add_option('-r', '--replace', action='store', type='string', dest='replace', help='Replace existing files')
self.OptionParser.add_option('-c', '--combine', action='store', type='string', dest='combine', help='Combine into single PDF')

def run_command(self, args):
try:
Expand Down Expand Up @@ -123,11 +124,21 @@ def export(self, oid, fformat, output, tmpfile):
else:
self.rsvg_export(oid, fformat, output, tmpfile)

def pdftk_combine(self, output, file_paths):
output = self.file_path("%s-%s" % (output, 'All'), 'pdf')
command = ['pdftk']

command.extend(file_paths)
command.extend(['cat', 'output', output])

self.run_command(command)

def export_files(self):
tmpfile = self.write_tempfile()
fformat = self.options.format
fname = self.options.name
findex = 0
fpaths = []

for oid in self.options.ids:
findex = findex + 1
Expand All @@ -137,12 +148,17 @@ def export_files(self):
else:
output = self.file_path("%s-%s" % (fname, findex), fformat)

fpaths.append(output)

if self.options.replace == 'false' and os.path.exists(output):
continue

self.export(oid, fformat, output, tmpfile)
self.remove_pt(output, fformat)

if self.options.combine == 'true' and fformat == 'pdf':
self.pdftk_combine(fname, fpaths)

def effect(self):
if self.options.name is None:
inkex.errormsg('Please enter the folder name.')
Expand Down

0 comments on commit 528dbf9

Please sign in to comment.