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 = ""
|
finalCommand = ""
|
||||||
|
|
||||||
|
documentName = mainCategory + "-" + subCategory
|
||||||
|
|
||||||
def putCommandTogether(pageNumber=int()):
|
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
|
#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
|
#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
|
return finalCommand
|
||||||
|
|
||||||
#Make folders needed
|
#Make folders needed
|
||||||
|
|
||||||
os.system("mkdir " + mainCategory)
|
os.system("mkdir \"" + mainCategory +"\"")
|
||||||
|
|
||||||
os.chdir(mainCategory)
|
os.chdir(mainCategory)
|
||||||
|
|
||||||
os.system("mkdir " + subCategory)
|
os.system("mkdir \"" + subCategory + "\"")
|
||||||
|
|
||||||
os.chdir(subCategory)
|
os.chdir(subCategory)
|
||||||
|
|
||||||
curPage = 0
|
curPage = 0
|
||||||
|
|
||||||
|
#Cleanup
|
||||||
|
|
||||||
|
os.system("rm scan.pdf")
|
||||||
|
|
||||||
while numberOfPages > curPage:
|
while numberOfPages > curPage:
|
||||||
|
curPage += 1
|
||||||
finalCommand = putCommandTogether(numberOfPages)
|
|
||||||
|
finalCommand = putCommandTogether(curPage)
|
||||||
|
|
||||||
os.system(finalCommand)
|
os.system(finalCommand)
|
||||||
|
|
||||||
curPage += 1
|
|
||||||
|
|
||||||
if curPage != numberOfPages:
|
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
|
#Cleanup
|
||||||
|
|
||||||
os.system("rm *.jpg")
|
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