Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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'])

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...