Added the ability to merge pdfs into a single file.
This commit is contained in:
parent
920bb30e89
commit
71c5ad5e01
41
main.py
41
main.py
@ -81,6 +81,8 @@ while numberOfPages <= 0:
|
||||
|
||||
finalCommand = ""
|
||||
|
||||
documentName = mainCategory + "-" + subCategory
|
||||
|
||||
def putCommandTogether(pageNumber=int()):
|
||||
|
||||
#Final command looks like this: hp-scan -d escl:https://192.168.0.XX:443 -o <mainCategory>-<subCategory>-pg<pageNumber>.jpg -mcolor; magick convert <mainCategory>-<subCategory>-<pageNumber>.jpg img.pdf
|
||||
@ -88,7 +90,7 @@ def putCommandTogether(pageNumber=int()):
|
||||
|
||||
#More Convienient
|
||||
|
||||
documentName = mainCategory + "-" + subCategory + "-pg" + str(pageNumber)
|
||||
documentName = "scan"
|
||||
|
||||
|
||||
|
||||
@ -97,36 +99,57 @@ def putCommandTogether(pageNumber=int()):
|
||||
|
||||
|
||||
|
||||
finalCommand = finalCommand + "-o " + documentName + ".jpg -mcolor; magick convert " + documentName + ".jpg " + documentName + ".pdf"
|
||||
finalCommand = finalCommand + "-o \"" + documentName + ".jpg\" -mcolor; magick convert \"" + documentName + ".jpg\" \"" + documentName + ".pdf\""
|
||||
|
||||
documentName = mainCategory + "-" + subCategory
|
||||
|
||||
finalCommand = finalCommand + ";pdftk \"" + documentName + ".pdf\"" + " scan.pdf cat output \"" + documentName + "-work.pdf\""
|
||||
return finalCommand
|
||||
|
||||
#Make folders needed
|
||||
|
||||
os.system("mkdir " + mainCategory)
|
||||
os.system("mkdir \"" + mainCategory +"\"")
|
||||
|
||||
os.chdir(mainCategory)
|
||||
|
||||
os.system("mkdir " + subCategory)
|
||||
os.system("mkdir \"" + subCategory + "\"")
|
||||
|
||||
os.chdir(subCategory)
|
||||
|
||||
curPage = 0
|
||||
|
||||
#Cleanup
|
||||
|
||||
os.system("rm scan.pdf")
|
||||
|
||||
while numberOfPages > curPage:
|
||||
|
||||
finalCommand = putCommandTogether(numberOfPages)
|
||||
curPage += 1
|
||||
|
||||
finalCommand = putCommandTogether(curPage)
|
||||
|
||||
os.system(finalCommand)
|
||||
|
||||
curPage += 1
|
||||
|
||||
|
||||
if curPage != numberOfPages:
|
||||
|
||||
print("Waiting 5 seconds for next page...")
|
||||
print("Waiting 7 seconds for next page...")
|
||||
|
||||
time.sleep(5)
|
||||
time.sleep(7)
|
||||
|
||||
#Move PDF if it's the first page
|
||||
|
||||
if curPage == 1:
|
||||
os.system("mv scan.pdf \"" + documentName + ".pdf" + "\"")
|
||||
|
||||
#Cleanup
|
||||
|
||||
os.system("rm *.jpg")
|
||||
|
||||
# Grumble grumble, file locking, grumble grumble...
|
||||
|
||||
os.system("mv \"" + documentName + "-work.pdf\" " + "\"" + documentName + ".pdf" + "\"")
|
||||
|
||||
for i in range((numberOfPages -1)):
|
||||
# final command looks like this : pdftk 1.pdf 2.pdf cat output out.pdf
|
||||
exit()
|
||||
|
Loading…
x
Reference in New Issue
Block a user