Add portable PDF to DXF converter for BricsCAD workflows.
Includes vector/vectorize/raster modes, page review before convert, bundled OCR data, and a single-file AppData launcher build. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
commit
91625af67f
16 files changed
+3074
No files matched your search
+127
@@ -0,0 +1,127 @@
|
||||
# Build a single shareable EXE.
|
||||
# First run unpacks the app into %LOCALAPPDATA%\PDF_to_DXF\app\
|
||||
# Usage: .\build_exe.ps1
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$Root = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
Set-Location $Root
|
||||
|
||||
$VenvPython = Join-Path $Root ".venv\Scripts\python.exe"
|
||||
if (-not (Test-Path $VenvPython)) {
|
||||
Write-Host "Creating virtual environment..."
|
||||
python -m venv .venv
|
||||
}
|
||||
|
||||
Write-Host "Installing dependencies..."
|
||||
& $VenvPython -m pip install --upgrade pip
|
||||
& $VenvPython -m pip install -r requirements.txt
|
||||
|
||||
# Bundle Tesseract language data (OCR works without a separate Tesseract install)
|
||||
$TessDir = Join-Path $Root "vendor\tessdata"
|
||||
$EngData = Join-Path $TessDir "eng.traineddata"
|
||||
New-Item -ItemType Directory -Force -Path $TessDir | Out-Null
|
||||
if (-not (Test-Path $EngData)) {
|
||||
Write-Host "Downloading bundled OCR language data (eng.traineddata)..."
|
||||
$url = "https://github.com/tesseract-ocr/tessdata_fast/raw/main/eng.traineddata"
|
||||
Invoke-WebRequest -Uri $url -OutFile $EngData -UseBasicParsing
|
||||
}
|
||||
if (-not (Test-Path $EngData)) {
|
||||
throw "Missing vendor\tessdata\eng.traineddata"
|
||||
}
|
||||
|
||||
$AppDistName = "PDF_to_DXF_app"
|
||||
$AppDistDir = Join-Path $Root "dist\$AppDistName"
|
||||
$PayloadZip = Join-Path $Root "build\app_payload.zip"
|
||||
$SingleExeDir = Join-Path $Root "dist\PDF_to_DXF_single"
|
||||
|
||||
Write-Host "Building application (folder payload)..."
|
||||
& $VenvPython -m PyInstaller `
|
||||
--noconfirm `
|
||||
--clean `
|
||||
--windowed `
|
||||
--name $AppDistName `
|
||||
--distpath (Join-Path $Root "dist") `
|
||||
--workpath (Join-Path $Root "build\pyi_app") `
|
||||
--collect-all customtkinter `
|
||||
--collect-all ezdxf `
|
||||
--collect-all cv2 `
|
||||
--collect-all pymupdf `
|
||||
--add-data "$TessDir;tessdata" `
|
||||
--hidden-import PIL._tkinter_finder `
|
||||
--hidden-import app.raster_vectorize `
|
||||
--hidden-import app.converter `
|
||||
--hidden-import app.bricscad_export `
|
||||
--hidden-import app.pdf_preview `
|
||||
--hidden-import app.ocr_support `
|
||||
--hidden-import app.page_review `
|
||||
main.py
|
||||
|
||||
$AppExe = Join-Path $AppDistDir "$AppDistName.exe"
|
||||
if (-not (Test-Path $AppExe)) {
|
||||
throw "Build failed: $AppExe not found"
|
||||
}
|
||||
|
||||
# Rename inner exe to PDF_to_DXF.exe so AppData layout matches the launcher
|
||||
$FinalAppExe = Join-Path $AppDistDir "PDF_to_DXF.exe"
|
||||
if (Test-Path $FinalAppExe) {
|
||||
Remove-Item -Force $FinalAppExe
|
||||
}
|
||||
Rename-Item -Path $AppExe -NewName "PDF_to_DXF.exe"
|
||||
|
||||
Write-Host "Packaging AppData payload zip..."
|
||||
New-Item -ItemType Directory -Force -Path (Join-Path $Root "build") | Out-Null
|
||||
if (Test-Path $PayloadZip) {
|
||||
Remove-Item -Force $PayloadZip
|
||||
}
|
||||
# Prefer Python zipfile — Compress-Archive often locks on PyInstaller outputs
|
||||
& $VenvPython -c @"
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
src = Path(r'$AppDistDir')
|
||||
out = Path(r'$PayloadZip')
|
||||
with zipfile.ZipFile(out, 'w', compression=zipfile.ZIP_DEFLATED, compresslevel=6) as zf:
|
||||
for path in src.rglob('*'):
|
||||
if path.is_file():
|
||||
zf.write(path, path.relative_to(src).as_posix())
|
||||
print('payload bytes', out.stat().st_size)
|
||||
"@
|
||||
if (-not (Test-Path $PayloadZip)) {
|
||||
throw "Failed to create app_payload.zip"
|
||||
}
|
||||
|
||||
Write-Host "Building single-file launcher EXE..."
|
||||
& $VenvPython -m PyInstaller `
|
||||
--noconfirm `
|
||||
--clean `
|
||||
--windowed `
|
||||
--onefile `
|
||||
--name "PDF_to_DXF" `
|
||||
--distpath $SingleExeDir `
|
||||
--workpath (Join-Path $Root "build\pyi_launcher") `
|
||||
--add-data "$PayloadZip;." `
|
||||
launcher.py
|
||||
|
||||
$OutExe = Join-Path $SingleExeDir "PDF_to_DXF.exe"
|
||||
if (-not (Test-Path $OutExe)) {
|
||||
throw "Build failed: single-file EXE not found"
|
||||
}
|
||||
|
||||
# Convenience copy at dist\PDF_to_DXF.exe
|
||||
$DistRootExe = Join-Path $Root "dist\PDF_to_DXF.exe"
|
||||
Copy-Item -Force $OutExe $DistRootExe
|
||||
|
||||
# README next to the single EXE
|
||||
$ReadmeSrc = Join-Path $Root "packaging\PORTABLE_README.txt"
|
||||
Copy-Item -Force $ReadmeSrc (Join-Path $SingleExeDir "README.txt")
|
||||
|
||||
$ExeMb = [math]::Round(((Get-Item $OutExe).Length) / 1MB, 1)
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Single-file build ready."
|
||||
Write-Host (" Share this one file: dist\PDF_to_DXF.exe ({0} MB)" -f $ExeMb)
|
||||
Write-Host " Also at: dist\PDF_to_DXF_single\PDF_to_DXF.exe"
|
||||
Write-Host ""
|
||||
Write-Host "On first run it installs to:"
|
||||
Write-Host " %LOCALAPPDATA%\PDF_to_DXF\app\"
|
||||
Write-Host "No Python needed. OCR language data is bundled."
|
||||
Write-Host "Optional: BricsCAD for DWG export."
|
||||
Reference in new issue
Block a user