-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.ps1
42 lines (26 loc) · 1.11 KB
/
convert.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#Dependencies - imageMagick, GhostScript, tesseract
#Comment out the line below to see errors
$ErrorActionPreference= 'silentlycontinue'
$counter = 0;
#SET THIS FILEPATH
$filepath = "C:\Users\user\Desktop\folder"
$filetype = "*.pdf"
$file_count = [System.IO.Directory]::GetFiles("$filepath", "$filetype").Count
#SET THIS FILEPATH
Set-Location 'C:\Users\user\Desktop\folder'
Get-ChildItem -Filter '*.pdf' | ForEach-Object {
Write-Host "Currently Mogrifying..."
mogrify -density 300 -depth 8 -background white -alpha Off -format tiff $_.FullName
Write-Host "Done Mogrifying"
Get-ChildItem -Filter '*.tif' | ForEach-Object {
Write-Host "Converting PDF file..."
& 'C:\Program Files\Tesseract-OCR\tesseract.exe' -l eng $_.Name ($_.BaseName) pdf;
Write-Host "Deleting .tiff"
Remove-Item -Path $_.FullName
$counter++;
Write-Host "Finished Converting PDF file: $counter/$file_count" -ForegroundColor Yellow -BackgroundColor DarkGreen;
}
}
echo "`nAll done :)"
write-host "Press any key to continue..."
[void][System.Console]::ReadKey($true)