|
@@ -0,0 +1,23 @@
|
|
|
+import img2pdf
|
|
|
+from Image2PDF.config import SOURCE_DIR_PATH, TARGET_DIR_PATH
|
|
|
+import os
|
|
|
+
|
|
|
+def imgs_from_dir2pdf(source_dir_path, target_dir_path):
|
|
|
+ # convert all files ending in .jpg inside a directory
|
|
|
+ dirname = source_dir_path
|
|
|
+ imgs = []
|
|
|
+ for fname in os.listdir(dirname):
|
|
|
+ if not fname.endswith(".jpg" or ".png"):
|
|
|
+ continue
|
|
|
+ path = os.path.join(dirname, fname)
|
|
|
+ if os.path.isdir(path):
|
|
|
+ continue
|
|
|
+ imgs.append(path)
|
|
|
+ for count,each_img in enumerate(imgs):
|
|
|
+ with open(target_dir_path+r"\Img{}.pdf".format(count), "wb") as f:
|
|
|
+ f.write(img2pdf.convert(each_img))
|
|
|
+
|
|
|
+
|
|
|
+if __name__=='__main__':
|
|
|
+ imgs_from_dir2pdf(SOURCE_DIR_PATH, TARGET_DIR_PATH)
|
|
|
+
|