Python PDF 拆分页面到特定路径

Python PDF split pages to specific path

我已经为 PDF 页面拆分器创建了一个函数。我可以选择一个 PDF 文件,将路径保存到 pdfOne,然后我可以选择要拆分的页面。问题在于拆分页面与原始 PDF 的路径相同。我不想这样,我想将拆分页面发送到不同的文件夹路径。

def onFindPage(self, event):

    pdfOne = self.pdfOne.GetValue()
    spgcf=int(self.spgcfrom.GetValue())
    spgcu=int(self.spgcuntil.GetValue())

    inputpdfpdfOne = pyPdf.PdfFileReader(file(pdfOne, "rb"))

    for i in xrange((spgcf-1),spgcu):

        output = PdfFileWriter()            
        output.addPage(inputpdfpdfOne.getPage(i))
        with open("page%s.pdf" % i,"wb") as outputStream:
           output.write(outputStream)

使用os.path.join构建目标文件的路径:

import os.path

[...]

outputFilename = os.path.join(destination_directory, "page%s.pdf" % i)
with open (outputFilename, "wb") as outputStream:
    output.write(outputStream)

父目录可以使用..,根目录可以使用/