PermissionError:[Errno 13]权限被拒绝-reportlab pdf

时间:2019-04-19 10:26:20

标签: python reportlab

我遇到PermissionError:[Errno 13]权限被拒绝,并且无法使用reportlab库将pdf保存到所需的目录中。我也尝试过以管理员身份运行spyder,并且我正在使用Windows。以下是我的代码:

感谢您的时间分配和帮助。


#save dataframe as a CSV
df.to_csv ('D:/Course/roi report auto/sidebanner_datasheet ' + timestr+'.csv', index=False)
#reportlab part (tough one  )
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import A4
from reportlab.lib.pagesizes import portrait 
from reportlab.platypus import Image 

final_dataset = pd.read_csv('D:/Course/roi report auto/sidebanner_datasheet ' + timestr+'.csv')
def import_data(final_dataset):
    for row in final_dataset:
        Start_date = final_dataset.iloc[1,1] #start date
        End_date = final_dataset.iloc[6,1] #end date
        Total_cost = final_dataset.iloc[0,7]#price
        Total_impressions = final_dataset.iloc[0,5]#total impressions
        Total_clicks = final_dataset.iloc[0,6]#total clicks
        Effective_CPM = final_dataset.iloc[0,8]#cpm
        Title = final_dataset.iloc[0,0]
    pdf_file_name = 'testing.pdf'
    generate_pdf(Start_date, End_date, Total_cost, Total_impressions, Total_clicks, Effective_CPM, pdf_file_name)
def generate_pdf(Start_date, End_date, Total_cost, Total_impressions, Total_clicks, Effective_CPM, pdf_file_name):
    r = canvas.Canvas(pdf_file_name, pagesize=portrait(A4))

#header text
    r.setFont('Helvetica', 22, leading=None)
    r.drawCentredString(207, 200, "The Hello World")
    r.setFont('Helvetica', 12, leading=None)
    r.drawCentredString(207, 190, "Hello World")
    r.showPage()
    r.save()

0 个答案:

没有答案