-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtejocr_windows_bootstrap.ps1
More file actions
100 lines (84 loc) · 2.88 KB
/
tejocr_windows_bootstrap.ps1
File metadata and controls
100 lines (84 loc) · 2.88 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# TejOCR Windows bootstrap helper for LibreOffice Python
#
# Usage examples:
# powershell -ExecutionPolicy Bypass -File .\scripts\tejocr_windows_bootstrap.ps1
# powershell -ExecutionPolicy Bypass -File .\scripts\tejocr_windows_bootstrap.ps1 -InstallPdfFallback
# powershell -ExecutionPolicy Bypass -File .\scripts\tejocr_windows_bootstrap.ps1 -InstallPdfFallback -InstallCompatExtras
param(
[string]$LibreOfficePython = "C:\Program Files\LibreOffice\program\python.exe",
[switch]$InstallPdfFallback,
[switch]$InstallCompatExtras
)
$ErrorActionPreference = "Stop"
function Write-Step {
param([string]$Message)
Write-Host ""
Write-Host "==> $Message" -ForegroundColor Cyan
}
function Ensure-LibreOfficePython {
if (-not (Test-Path $LibreOfficePython)) {
throw "LibreOffice Python not found at: $LibreOfficePython"
}
}
function Test-PipAvailable {
try {
& $LibreOfficePython -m pip --version *> $null
return $true
}
catch {
return $false
}
}
function Ensure-Pip {
if (Test-PipAvailable) {
Write-Host "pip is already available in LibreOffice Python." -ForegroundColor Green
return
}
Write-Step "Bootstrapping pip in LibreOffice Python"
$programDir = Split-Path -Parent $LibreOfficePython
Push-Location $programDir
try {
(Invoke-WebRequest -Uri https://bootstrap.pypa.io/get-pip.py -UseBasicParsing).Content | & $LibreOfficePython -
}
finally {
Pop-Location
}
}
function Install-Packages {
param([string[]]$Packages)
if (-not $Packages -or $Packages.Count -eq 0) {
return
}
Write-Step ("Installing LibreOffice Python packages: " + ($Packages -join ", "))
& $LibreOfficePython -m pip install @Packages
}
function Show-BinaryStatus {
param(
[string]$Name,
[string]$Hint
)
$command = Get-Command $Name -ErrorAction SilentlyContinue
if ($command) {
Write-Host "$Name: found at $($command.Source)" -ForegroundColor Green
}
else {
Write-Host "$Name: not found. $Hint" -ForegroundColor Yellow
}
}
Write-Step "Checking LibreOffice Python"
Ensure-LibreOfficePython
Write-Host "LibreOffice Python: $LibreOfficePython" -ForegroundColor Green
Ensure-Pip
Install-Packages -Packages @("pillow")
if ($InstallPdfFallback) {
Install-Packages -Packages @("pdf2image")
}
if ($InstallCompatExtras) {
Install-Packages -Packages @("numpy", "pytesseract")
}
Write-Step "Checking OCR runtime tools"
Show-BinaryStatus -Name "tesseract" -Hint "Install Tesseract from UB Mannheim or Chocolatey."
Show-BinaryStatus -Name "pdftoppm" -Hint "Install Poppler if you want PDF OCR support."
Show-BinaryStatus -Name "mutool" -Hint "Install MuPDF tools if you want an alternative PDF renderer."
Write-Step "Done"
Write-Host "Restart LibreOffice or use Validate / Refresh in TejOCR Setup & Diagnostics." -ForegroundColor Green