假设你必须加入一些编号为2,4和5的页面......(这些文件名为test_002.pdf,test_004.pdf和test_005.pdf),然后我们可以说缺少第3页。
我尝试做的是从这些命令得到结果:
pdfjam --nup 2 --papersize '{47cm,30cm}' --scale 1.0 test_002.pdf test_003.pdf --outfile joined_002-003.pdf
pdfjam --nup 2 --papersize '{47cm,30cm}' --scale 1.0 test_004.pdf test_005.pdf --outfile joined_004-005.pdf
将在一个唯一的页面中连接偶数和奇数页面,并使用空白页面(3)代替缺失的页面。
我想它应该:
我是对的吗?
使用Python的某些行可能吗? 或者有更简单的方法吗?
因为这就是我开始做的事情,让它像热门文件夹一样工作,但我真的完全迷失在偶数和奇怪的管理中并且缺少“文件/页面”:
#!/usr/bin/python
# -*- coding: UTF8 -*-
import os
import os.path
import re
import time
import datetime
CODEFILE = re.compile("^(TES|EXA).*\.pdf$")
WHERE = "/tmp/TEST/"
STORAGE = "/tmp/WORK/"
DBLSIZE = "{47cm,30cm}"
def time_stamp():
now = datetime.datetime.now()
return now.strftime("%Y-%m-%d %H:%M:%S")
print(time_stamp()+" : Starting.")
def files_list(path):
this_files = list()
root, dires, files = os.walk(path).next()
for f in files:
if CODEFILE.match(f):
this_files.append(os.path.join(root, f))
return this_files
def file_sizes(filename):
meta = os.lstat(filename)
return meta.st_size
def files_to_handle(path):
this_files = list()
ft1 = dict()
ft2 = dict()
for f in files_list(WHERE):
ft1[f] = file_sizes(f)
time.sleep(10)
for f in files_list(WHERE):
ft2[f] = file_sizes(f)
for f, t in ft2.items():
try:
if ft1[f] == t:
this_files.append(f)
except:
pass
return this_files
r = files_to_handle(WHERE)
print(time_stamp()+" : Files available :")
print(r)
for f in r:
rc = os.system("pdfjam --batch --nup 2 --papersize {1} --scale 1.0 --outfile . {2}".format(
DBLSIZE, f))
if rc != 0:
print(time_stamp()+" : an ERROR as occured with the file {0}.".format(f))
else:
print(time_stamp()+" : files {0} OK.".format(f))
os.system("mv {0} {1}".format(f, STORAGE))
print(time_stamp()+" : Stopping.")
提前致谢!