How to download multiple PDF files generated by Flask?

problem description

write a Flask app, home page to display a form, then enter the conditions, submit, get N eligible news headlines from a fixed site, and then use pdfkit"s from_url to convert these pages into PDF. What I"m thinking about now is how to generate these pdf in memory and package them into a file for download?

related codes

/ / Please paste the code text below (do not replace the code with pictures)

txt = "./1.html"
with open(txt, "w", encoding="utf-8") as f:
    f.write(responseRes.text)

file1 = open("1.html", "r", encoding="utf-8")
soup = BeautifulSoup(file1, "lxml")
memory_file = BytesIO()
with zipfile.ZipFile(memory_file, "w", zipfile.ZIP_DEFLATED) as zf:
     for i in soup.find_all("a", class_="black"):
         zf = pdfkit.from_url(["http://XXX.XXX.XXX" + i["href"]], False)
     memory_file.seek(0)

     rv = send_file(zf, as_attachment=True, attachment_filename="filename.zip")
     return rv

what result do you expect? What is the error message actually seen?

expect the browser to download a zip file directly, but the browser returns a zip file of 0kb. How to implement it?

Aug.20,2021

@app.route('/test', methods=['GET'])
def testdownload():
    dir_path = os.path.join(r"D:\PycharmProjects\un",'upload')
    file_name = "bb.zip"
    return send_from_directory(dir_path, file_name, as_attachment=True)

this idea should be divided into two steps:
the first step is to first use pdfkit's from_url to convert these web pages into a single PDF file, and then use zipfile to package all generated pdf files into a zip file. The second step of
is to generate a url, using send_from_directory (dir_path, file_name, as_attachment=True) provided by @ wt1187982580 and then set a button on the web page and link to the url.

Menu