Skip to content

Commit

Permalink
Update Python_Lib.py
Browse files Browse the repository at this point in the history
improve internal code
  • Loading branch information
overcrash66 committed Sep 13, 2023
1 parent e793cbd commit 46e12fd
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions Python_Lib.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
import os, sys
import os
import sys
from pdf2image import convert_from_path
import tempfile
import platform
Expand All @@ -8,28 +9,27 @@
from datetime import datetime
import time

#os.system("mode con cols=40 lines=40")
#os.system('color 02')
def convert_to_jpeg(pdf_to_jpeg_path):
try:
output = str(os.path.dirname(pdf_to_jpeg_path))
tempdir = Path("/tmp" if platform.system() == "Darwin" else tempfile.gettempdir())
pages = convert_from_path(pdf_to_jpeg_path, output_folder=tempdir, fmt="jpeg")
print("Processing...Please Wait...")
for index, page in enumerate(pages):
now = datetime.now()
dt_string = now.strftime("%d-%m-%Y_%H-%M-%S-%f")
page.save(f"Converted-PDF-page{dt_string}.jpeg", "JPEG")
easygui.msgbox("PDF file converted Successfully \nAll Images available in main folder \n\n\n\n--PDF TO Image TOOL--\n--POWERED BY PYTHON--\n--Created By WAEL SAHLI--\n 2021", title="Done")
except Exception as e:
easygui.msgbox(f"Sorry An Error Occured !\n{str(e)}", title="Error")

def ConvertToJpeg(PDFtoJPEG_path):
try:
output= str(os.path.dirname(PDFtoJPEG_path))
tempdir = Path("/tmp" if platform.system() == "Darwin" else tempfile.gettempdir())
pages = convert_from_path(PDFtoJPEG_path, output_folder=tempdir, fmt="jpeg")
print("Processing...Please Wait...")
for page in pages:
now = datetime.now()
dt_string = now.strftime("%d-%m-%Y_%H-%M-%S-%f")
#page.save("%s-page%d.jpeg" % (output,pages.index(page)), "JPEG")
page.save("Converted-PDF-page"+dt_string+".jpeg", "JPEG")
easygui.msgbox("PDF file converted Successfully \nAll Images available in main folder \n\n\n\n--PDF TO Image TOOL--\n--POWERED BY PYTHON--\n--Created By WAEL SAHLI--\n 2021", title="Done")
except Exception as e:
easygui.msgbox("Sorry An Error Occured !\n"+str(e), title="Error")
#os.system('pause')

my_parser = argparse.ArgumentParser(description='List the content')
my_parser.add_argument('PDFtoJPEG_path',metavar='PDFtoJPEG_path',type=str,help='PDFtoJPEG_path')
args = my_parser.parse_args()
PDFtoJPEG_path = args.PDFtoJPEG_path
ConvertToJpeg(PDFtoJPEG_path)
def main():
parser = argparse.ArgumentParser(description='List the content')
parser.add_argument('PDFtoJPEG_path',metavar='PDFtoJPEG_path',type=str,help='PDFtoJPEG_path')
args = parser.parse_args()
pdf_to_jpeg_path = args.PDFtoJPEG_path
convert_to_jpeg(pdf_to_jpeg_path)

if __name__ == "__main__":
main()

0 comments on commit 46e12fd

Please sign in to comment.