Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I change the save location of an altered PDF using PyPDF2

I need to change the location that the output file is saved. Currently the save location is wherever the application is located. I would like to change it to the user’s desktop.

Any help would be appreciated.

filename = askopenfilename() 
packet.seek(0)
new_pdf = PdfFileReader(packet)
existing_pdf = PdfFileReader(open(filename, "rb"))
output = PdfFileWriter()
page = existing_pdf.getPage(0)
page.mergePage(new_pdf.getPage(0))
output.addPage(page)
name = (os.path.basename(filename))
name = name[:-4]
outputStream = open(name + "-CARB.pdf", "wb")
output.write(outputStream)
outputStream.close()

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Change the name in your code to the path you want to save

Basically in below statement you can specify where you want to save the file.
For example:

outputStream = open("C:\\Users\\<<USERNAME>>\\Desktop\\" + "-CARB.pdf", "wb")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading