您的代码假定
p.mediaBox.lowerLeft为(0,0),但实际上为(0,497)
这适用于您提供的文件:
#!/usr/bin/env pythonimport copy, sysfrom pyPdf import PdfFileWriter, PdfFileReaderinput = PdfFileReader(sys.stdin)output = PdfFileWriter()for i in range(input.getNumPages()): p = input.getPage(i) q = copy.copy(p) bl = p.mediaBox.lowerLeft ur = p.mediaBox.upperRight print >> sys.stderr, 'splitting page',i print >> sys.stderr, 'tlowerLeft:',p.mediaBox.lowerLeft print >> sys.stderr, 'tupperRight:',p.mediaBox.upperRight p.mediaBox.upperRight = (ur[0], (bl[1]+ur[1])/2) p.mediaBox.lowerLeft = bl q.mediaBox.upperRight = ur q.mediaBox.lowerLeft = (bl[0], (bl[1]+ur[1])/2) if i%2==0: output.addPage(q) output.addPage(p) else: output.addPage(p) output.addPage(q)output.write(sys.stdout)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)