Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
193 views
in Technique[技术] by (71.8m points)

pandas - How open multiple encrypted PDF and save without password in Python

I am a newbee just started my first language as Python.

I am trying to write code to open multiple encrypted pdf files and save them without password.

All files are in a folder, I have a csv file filePassword.csv with columns filename and password.

But my code is not working. Please guide me on how to solve this error.

import pikepdf as pdf
import pandas as pd
df = pd.read_csv('filePassword.csv')
filename, password = df['filename'], df['password']
for file in filename:
    for code in password:
        file1 = pdf.open(file,code)
        file1.save('1_'+filename)

I get this error:

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

question from:https://stackoverflow.com/questions/65651182/how-open-multiple-encrypted-pdf-and-save-without-password-in-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can loop over the dataframe df using iterrows() and then access filename and password in following way. There is no need of nested loops.

import pikepdf as pdf
import pandas as pd
df = pd.read_csv('filePassword.csv')
for index, row in df.iterrows():
    file1 = pdf.open(row['filename'], row['password'])
    file1.save('1_'+row['filename'])

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...