如何更改保存 PDF 的目录?

How to change the directory where PDFs are saved?

我正在开发一个应用程序来拆分 PDF 并挖掘互联网我设法做到了,但是,我想更改保存 PDF 的文件夹。你能帮帮我吗?

下面是代码:

from PyPDF2 import PdfFileWriter, PdfFileReader
from tkinter.filedialog import askopenfilename
from tkinter import messagebox


inputpdf = PdfFileReader(askopenfilename(), "rb")
print(inputpdf)

for i in range(inputpdf.numPages):
    output = PdfFileWriter()
    output.addPage(inputpdf.getPage(i))
    with open("document-page%s.pdf" % i, "wb") as outputStream:
        output.write(outputStream)
print("PDF Dividido com sucesso.")
messagebox.showinfo("System Message", "PDF successfully divided.")

当您执行 open("document-page.pdf") 时,您可以在 document-page.pdf 所在的位置插入路径名。例如~/Documents/Some_random_folder/new_file.pdf