diff --git a/LabelPrinter.spec b/LabelPrinter.spec
index fa23c0a..6481e88 100644
--- a/LabelPrinter.spec
+++ b/LabelPrinter.spec
@@ -5,8 +5,8 @@ a = Analysis(
['label_printer_gui.py'],
pathex=[],
binaries=[],
- datas=[],
- hiddenimports=['kivy', 'kivy.core.window', 'kivy.core.text', 'kivy.core.image', 'kivy.uix.boxlayout', 'kivy.uix.gridlayout', 'kivy.uix.label', 'kivy.uix.textinput', 'kivy.uix.button', 'kivy.uix.spinner', 'kivy.uix.scrollview', 'kivy.uix.popup', 'kivy.clock', 'kivy.graphics', 'PIL', 'barcode', 'reportlab', 'print_label', 'print_label_pdf', 'svglib', 'cairosvg', 'watchdog', 'watchdog.observers', 'watchdog.events', 'pystray', 'win32timezone'],
+ datas=[('conf\\SumatraPDF.exe', '.'), ('conf\\SumatraPDF-settings.txt', 'conf'), ('conf\\label_template_ok.svg', 'conf'), ('conf\\label_template_nok.svg', 'conf'), ('conf\\label_template.svg', 'conf')],
+ hiddenimports=['kivy', 'PIL', 'barcode', 'reportlab', 'print_label', 'print_label_pdf', 'svglib', 'cairosvg', 'watchdog', 'watchdog.observers', 'watchdog.events', 'pystray', 'win32timezone'],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
diff --git a/build_windows.bat b/build_windows.bat
index 492a380..96d08eb 100644
--- a/build_windows.bat
+++ b/build_windows.bat
@@ -48,6 +48,17 @@ if errorlevel 1 (
)
echo.
+REM Check that SumatraPDF.exe exists before building
+if not exist "conf\SumatraPDF.exe" (
+ echo ERROR: conf\SumatraPDF.exe not found!
+ echo Please download SumatraPDF portable exe and place it at conf\SumatraPDF.exe
+ echo Download from: https://www.sumatrapdfreader.org/download-free-pdf-viewer
+ pause
+ exit /b 1
+)
+echo conf\SumatraPDF.exe found - will be bundled into executable.
+echo.
+
REM Clean old build
echo [4/5] Cleaning old build artifacts...
if exist "dist" rmdir /s /q dist
@@ -79,6 +90,11 @@ pyinstaller label_printer_gui.py ^
--hidden-import=watchdog.events ^
--hidden-import=pystray ^
--hidden-import=win32timezone ^
+ --add-data "conf\SumatraPDF.exe;." ^
+ --add-data "conf\SumatraPDF-settings.txt;conf" ^
+ --add-data "conf\label_template_ok.svg;conf" ^
+ --add-data "conf\label_template_nok.svg;conf" ^
+ --add-data "conf\label_template.svg;conf" ^
-y
if errorlevel 1 (
@@ -94,12 +110,26 @@ echo ========================================================
echo BUILD SUCCESSFUL!
echo ========================================================
echo.
+echo Copying conf folder to dist\conf ...
+if exist dist\conf rmdir /s /q dist\conf
+xcopy /e /i /q conf dist\conf
+if errorlevel 1 (
+ echo WARNING: Could not copy conf folder to dist\conf
+ echo You must manually copy the conf folder next to LabelPrinter.exe before deployment.
+) else (
+ echo conf folder copied to dist\conf successfully.
+)
+echo.
echo Executable Location: dist\LabelPrinter.exe
echo.
+echo Deployment folder contents:
+dir dist
+echo.
echo Next steps:
-echo 1. Navigate to the dist folder
-echo 2. Double-click LabelPrinter.exe to run
-echo 3. You can copy LabelPrinter.exe to other machines
+echo 1. Copy the entire dist\ folder to the target machine
+echo (it contains LabelPrinter.exe AND the conf\ folder)
+echo 2. Run LabelPrinter.exe from the dist folder
+echo 3. Ensure conf\SumatraPDF.exe is present for printing to work
echo.
echo Note: First run may take a moment as Kivy initializes
echo.
diff --git a/conf/SumatraPDF-settings.txt b/conf/SumatraPDF-settings.txt
index 7787273..a8f6f8e 100644
--- a/conf/SumatraPDF-settings.txt
+++ b/conf/SumatraPDF-settings.txt
@@ -89,6 +89,6 @@ FileStates [
SessionData [
]
TimeOfLastUpdateCheck = 0 0
-OpenCountWeek = 788
+OpenCountWeek = 790
# Settings below are not recognized by the current version
diff --git a/conf/app.conf b/conf/app.conf
index 12cbb3f..a68db1d 100644
--- a/conf/app.conf
+++ b/conf/app.conf
@@ -1,4 +1,4 @@
[Settings]
file_path = C:\temp\check.txt
-printer = ZDesigner ZQ630 Plus
+printer = PDF
diff --git a/dist/LabelPrinter.exe b/dist/LabelPrinter.exe
index 9c76dc0..5761420 100644
Binary files a/dist/LabelPrinter.exe and b/dist/LabelPrinter.exe differ
diff --git a/dist/conf/SumatraPDF-settings.txt b/dist/conf/SumatraPDF-settings.txt
new file mode 100644
index 0000000..a8f6f8e
--- /dev/null
+++ b/dist/conf/SumatraPDF-settings.txt
@@ -0,0 +1,94 @@
+# For documentation, see https://www.sumatrapdfreader.org/settings/settings3-5-1.html
+Theme = Light
+FixedPageUI [
+ TextColor = #000000
+ BackgroundColor = #ffffff
+ SelectionColor = #f5fc0c
+ WindowMargin = 2 4 2 4
+ PageSpacing = 4 4
+ InvertColors = false
+ HideScrollbars = false
+]
+ComicBookUI [
+ WindowMargin = 0 0 0 0
+ PageSpacing = 4 4
+ CbxMangaMode = false
+]
+ChmUI [
+ UseFixedPageUI = false
+]
+
+SelectionHandlers [
+]
+ExternalViewers [
+]
+
+ZoomLevels = 8.33 12.5 18 25 33.33 50 66.67 75 100 125 150 200 300 400 600 800 1000 1200 1600 2000 2400 3200 4800 6400
+ZoomIncrement = 0
+
+PrinterDefaults [
+ PrintScale = noscale
+]
+ForwardSearch [
+ HighlightOffset = 0
+ HighlightWidth = 15
+ HighlightColor = #6581ff
+ HighlightPermanent = false
+]
+Annotations [
+ HighlightColor = #ffff00
+ UnderlineColor = #00ff00
+ SquigglyColor = #ff00ff
+ StrikeOutColor = #ff0000
+ FreeTextColor =
+ FreeTextSize = 12
+ FreeTextBorderWidth = 1
+ TextIconColor =
+ TextIconType =
+ DefaultAuthor =
+]
+
+RememberOpenedFiles = true
+RememberStatePerDocument = true
+RestoreSession = true
+UiLanguage = en
+EnableTeXEnhancements = false
+DefaultDisplayMode = automatic
+DefaultZoom = fit page
+Shortcuts [
+]
+EscToExit = false
+ReuseInstance = false
+ReloadModifiedDocuments = true
+
+MainWindowBackground = #80fff200
+FullPathInTitle = false
+ShowMenubar = true
+ShowToolbar = true
+ShowFavorites = false
+ShowToc = true
+NoHomeTab = false
+TocDy = 0
+SidebarDx = 0
+ToolbarSize = 18
+TabWidth = 300
+TreeFontSize = 0
+TreeFontWeightOffset = 0
+TreeFontName = automatic
+SmoothScroll = false
+ShowStartPage = false
+CheckForUpdates = true
+WindowState = 1
+WindowPos = 566 0 788 1020
+UseTabs = true
+UseSysColors = false
+CustomScreenDPI = 0
+
+FileStates [
+]
+SessionData [
+]
+TimeOfLastUpdateCheck = 0 0
+OpenCountWeek = 790
+
+# Settings below are not recognized by the current version
diff --git a/dist/conf/SumatraPDF.exe b/dist/conf/SumatraPDF.exe
new file mode 100644
index 0000000..f034e5e
Binary files /dev/null and b/dist/conf/SumatraPDF.exe differ
diff --git a/dist/conf/accepted.png b/dist/conf/accepted.png
new file mode 100644
index 0000000..d0d769d
Binary files /dev/null and b/dist/conf/accepted.png differ
diff --git a/dist/conf/app.conf b/dist/conf/app.conf
index 168c69a..a68db1d 100644
--- a/dist/conf/app.conf
+++ b/dist/conf/app.conf
@@ -1,4 +1,4 @@
[Settings]
-file_path = C:\Users\Public\Documents\check.txt
-printer = Microsoft Print to P
+file_path = C:\temp\check.txt
+printer = PDF
diff --git a/dist/conf/label_template.svg b/dist/conf/label_template.svg
index a1be348..1846eb1 100644
--- a/dist/conf/label_template.svg
+++ b/dist/conf/label_template.svg
@@ -1,16 +1,63 @@
-
diff --git a/dist/conf/refused.png b/dist/conf/refused.png
new file mode 100644
index 0000000..0270983
Binary files /dev/null and b/dist/conf/refused.png differ
diff --git a/print_label.py b/print_label.py
index 2aacbb9..e9482dd 100644
--- a/print_label.py
+++ b/print_label.py
@@ -394,10 +394,12 @@ def print_to_printer(printer_name, file_path):
bundled_sumatra = os.path.join(sys._MEIPASS, 'SumatraPDF.exe')
sumatra_paths.append(bundled_sumatra)
- # Also check app directory for external version
+ # Check app directory and conf subfolder for external version
app_dir = os.path.dirname(sys.executable)
sumatra_paths.append(os.path.join(app_dir, "SumatraPDF", "SumatraPDF.exe"))
sumatra_paths.append(os.path.join(app_dir, "SumatraPDF.exe"))
+ sumatra_paths.append(os.path.join(app_dir, "conf", "SumatraPDF.exe")) # conf subfolder next to exe
+ sumatra_paths.append(os.path.join(os.getcwd(), "conf", "SumatraPDF.exe")) # conf relative to cwd
else:
# Running as script - check local folders
app_dir = os.path.dirname(os.path.abspath(__file__))
@@ -411,26 +413,49 @@ def print_to_printer(printer_name, file_path):
r"C:\Program Files (x86)\SumatraPDF\SumatraPDF.exe",
])
+ # Set printer to highest quality / landscape before sending job
+ if WIN32_AVAILABLE:
+ try:
+ import win32print
+ hPrinter = win32print.OpenPrinter(printer_name)
+ try:
+ props = win32print.GetPrinter(hPrinter, 2)
+ dm = props['pDevMode']
+ if dm:
+ dm.Orientation = 2 # DMORIENT_LANDSCAPE
+ dm.PrintQuality = -4 # DMRES_HIGH (highest DPI)
+ dm.YResolution = -4 # also set Y res
+ win32print.SetPrinter(hPrinter, 2, props, 0)
+ print("Printer set to landscape + high quality")
+ finally:
+ win32print.ClosePrinter(hPrinter)
+ except Exception as qe:
+ print(f"Could not configure printer quality/orientation: {qe}")
+
for sumatra_path in sumatra_paths:
if os.path.exists(sumatra_path):
try:
- # Use noscale with paper size specification for thermal printers
- # Format: "noscale,paper=" where paper size matches PDF (35mm x 25mm)
- # SumatraPDF will use the PDF's page size when noscale is used
- subprocess.run([
+ print(f"Using SumatraPDF: {sumatra_path}")
+ print(f"Sending to printer: {printer_name}")
+ result = subprocess.run([
sumatra_path,
"-print-to",
printer_name,
file_path,
"-print-settings",
- "noscale", # Preserve exact PDF page dimensions
+ "noscale,landscape", # preserve dimensions + force landscape
"-silent",
"-exit-when-done"
- ], check=False, creationflags=subprocess.CREATE_NO_WINDOW)
- print(f"Label sent to printer via SumatraPDF: {printer_name}")
- print(f"Note: Printer '{printer_name}' should be configured for 35mm x 25mm labels")
- printed = True
- break
+ ], check=False, creationflags=subprocess.CREATE_NO_WINDOW,
+ capture_output=True, text=True, timeout=30)
+ if result.returncode != 0:
+ print(f"SumatraPDF returned code {result.returncode}")
+ if result.stderr:
+ print(f"SumatraPDF stderr: {result.stderr.strip()}")
+ else:
+ print(f"Label sent to printer via SumatraPDF: {printer_name}")
+ printed = True
+ break
except Exception as e:
print(f"SumatraPDF error: {e}")