try: outFile = input("生成的pdf文件名(默认2019-01-01.pdf):") if outFile == "": outFile = datetime.now().date().strftime('%Y-%m-%d')+".pdf" print(outFile) except EOFError: print("输入有误,默认为日期文件名") # windows os.system('pause')
try: for index in range(len(all_content)): packet = io.BytesIO() # create a new PDF with Reportlab can = canvas.Canvas(packet, pagesize=letter) # can.setFontSize(fontSize) can.setFont('song',fontSize) #设置字体字号 can.setFillColorRGB(1, 0, 0) # choose your font colour can.drawString(2, 200, all_content[index]) can.save()
# move to the beginning of the StringIO buffer packet.seek(0) new_pdf = PdfFileReader(packet)