Skip to content

Instantly share code, notes, and snippets.

@iwatchme
Created June 6, 2022 06:02
Show Gist options
  • Select an option

  • Save iwatchme/069044d438b56a11f3ab677f8eb8af70 to your computer and use it in GitHub Desktop.

Select an option

Save iwatchme/069044d438b56a11f3ab677f8eb8af70 to your computer and use it in GitHub Desktop.

Revisions

  1. iwatchme created this gist Jun 6, 2022.
    34 changes: 34 additions & 0 deletions img2pdf.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    from ast import main
    from cmath import e
    import os
    import img2pdf

    def convertImgsToPdf(dir_name, result_pdf):
    imgs =[]
    for fname in os.listdir(dir_name):
    if fname.lower().endswith(".png") and not fname.lower().startswith("._"):
    imgs.append(os.path.join(dir_name, fname))
    imgs = sorted(imgs)
    with open(result_pdf,"wb") as f:
    try:
    f.write(img2pdf.convert(imgs))
    except Exception as e:
    print(e)


    def findNotDirectory(rootDir):
    for root, dirs, files in os.walk(rootDir):
    if dirs:
    for dir in dirs:
    findNotDirectory(os.path.join(root, dir))
    else:
    print(os.path.join(root))
    convertImgsToPdf(root, root+".pdf")




    def main():
    root = "/Users/iwatchme/Desktop/2/20211009 很帅的合辑"
    findNotDirectory(root)
    main()