updated to silent print
This commit is contained in:
125
py_app/analyze_pdf_dimensions.py
Normal file
125
py_app/analyze_pdf_dimensions.py
Normal file
@@ -0,0 +1,125 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
PDF Label Dimension Analysis Tool
|
||||
Analyzes the generated PDF to verify exact dimensions and content positioning
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), 'app'))
|
||||
|
||||
from app.pdf_generator import LabelPDFGenerator, mm_to_points
|
||||
from reportlab.lib.units import mm
|
||||
|
||||
def analyze_pdf_dimensions():
|
||||
"""Analyze the PDF dimensions in detail"""
|
||||
print("=== PDF Label Dimension Analysis ===\n")
|
||||
|
||||
generator = LabelPDFGenerator()
|
||||
|
||||
# Label dimensions
|
||||
print("1. LABEL PHYSICAL DIMENSIONS:")
|
||||
print(f" Width: {generator.label_width/mm:.1f}mm ({generator.label_width:.2f} points)")
|
||||
print(f" Height: {generator.label_height/mm:.1f}mm ({generator.label_height:.2f} points)")
|
||||
print(f" ✓ Should be exactly 80.0mm × 110.0mm")
|
||||
|
||||
# Content area
|
||||
print(f"\n2. CONTENT AREA DIMENSIONS:")
|
||||
print(f" Content Width: {generator.content_width/mm:.1f}mm")
|
||||
print(f" Content Height: {generator.content_height/mm:.1f}mm")
|
||||
print(f" Left margin: {generator.content_x/mm:.1f}mm")
|
||||
print(f" Bottom margin: {generator.content_y/mm:.1f}mm")
|
||||
print(f" Right margin: {(generator.label_width - generator.content_x - generator.content_width)/mm:.1f}mm")
|
||||
print(f" Top margin: {(generator.label_height - generator.content_y - generator.content_height)/mm:.1f}mm")
|
||||
|
||||
# Row analysis
|
||||
print(f"\n3. ROW LAYOUT:")
|
||||
total_rows = 9
|
||||
standard_rows = 8 # 7 standard + 1 double
|
||||
double_rows = 1
|
||||
|
||||
standard_row_height_mm = generator.row_height/mm
|
||||
double_row_height_mm = generator.double_row_height/mm
|
||||
|
||||
total_content_used = (standard_rows * standard_row_height_mm + double_rows * double_row_height_mm)
|
||||
expected_content_height = generator.content_height/mm
|
||||
|
||||
print(f" Standard row height: {standard_row_height_mm:.1f}mm")
|
||||
print(f" Double row height: {double_row_height_mm:.1f}mm")
|
||||
print(f" Total rows: {total_rows} (8 standard + 1 double)")
|
||||
print(f" Content height used: {total_content_used:.1f}mm")
|
||||
print(f" Content area available: {expected_content_height:.1f}mm")
|
||||
print(f" Remaining space: {expected_content_height - total_content_used:.1f}mm")
|
||||
|
||||
# Barcode area
|
||||
print(f"\n4. BARCODE AREA:")
|
||||
barcode_bottom_margin = generator.content_y/mm
|
||||
print(f" Bottom barcode space: {barcode_bottom_margin:.1f}mm (should be ~12-15mm)")
|
||||
|
||||
top_margin = (generator.label_height - generator.content_y - generator.content_height)/mm
|
||||
print(f" Top margin space: {top_margin:.1f}mm")
|
||||
|
||||
# Check for potential issues
|
||||
print(f"\n5. POTENTIAL ISSUES ANALYSIS:")
|
||||
|
||||
# Check if content is too high
|
||||
if total_content_used > expected_content_height:
|
||||
print(f" ⚠️ ISSUE: Content ({total_content_used:.1f}mm) exceeds available space ({expected_content_height:.1f}mm)")
|
||||
else:
|
||||
print(f" ✓ Content fits within available space")
|
||||
|
||||
# Check margins
|
||||
if barcode_bottom_margin < 10:
|
||||
print(f" ⚠️ WARNING: Bottom margin ({barcode_bottom_margin:.1f}mm) may be too small for barcode")
|
||||
else:
|
||||
print(f" ✓ Bottom margin adequate for barcode")
|
||||
|
||||
if top_margin < 3:
|
||||
print(f" ⚠️ WARNING: Top margin ({top_margin:.1f}mm) very small")
|
||||
else:
|
||||
print(f" ✓ Top margin adequate")
|
||||
|
||||
# Aspect ratio check
|
||||
aspect_ratio = generator.label_height / generator.label_width
|
||||
expected_ratio = 110.0 / 80.0 # 1.375
|
||||
|
||||
print(f"\n6. ASPECT RATIO CHECK:")
|
||||
print(f" Current ratio: {aspect_ratio:.3f}")
|
||||
print(f" Expected ratio: {expected_ratio:.3f} (110/80)")
|
||||
|
||||
if abs(aspect_ratio - expected_ratio) < 0.001:
|
||||
print(f" ✓ Aspect ratio is correct")
|
||||
else:
|
||||
print(f" ⚠️ Aspect ratio mismatch!")
|
||||
|
||||
# Browser display notes
|
||||
print(f"\n7. BROWSER DISPLAY CONSIDERATIONS:")
|
||||
print(f" • Browser zoom affects apparent size")
|
||||
print(f" • PDF viewer scaling can change appearance")
|
||||
print(f" • Monitor DPI affects screen dimensions")
|
||||
print(f" • Print preview scaling may alter appearance")
|
||||
print(f"\n 🔧 SOLUTION: Always verify with physical printout at 100% scale")
|
||||
|
||||
return {
|
||||
'width_mm': generator.label_width/mm,
|
||||
'height_mm': generator.label_height/mm,
|
||||
'content_height_mm': expected_content_height,
|
||||
'content_used_mm': total_content_used,
|
||||
'aspect_ratio': aspect_ratio,
|
||||
'expected_ratio': expected_ratio
|
||||
}
|
||||
|
||||
if __name__ == "__main__":
|
||||
results = analyze_pdf_dimensions()
|
||||
|
||||
print(f"\n=== SUMMARY ===")
|
||||
if (abs(results['width_mm'] - 80.0) < 0.1 and
|
||||
abs(results['height_mm'] - 110.0) < 0.1 and
|
||||
abs(results['aspect_ratio'] - results['expected_ratio']) < 0.001):
|
||||
print("✅ PDF dimensions are CORRECT: 80mm × 110mm")
|
||||
print("If labels appear too large, check:")
|
||||
print(" • Browser zoom level (should be 100%)")
|
||||
print(" • PDF viewer scaling settings")
|
||||
print(" • Print scaling (should be 'Actual size' or 100%)")
|
||||
else:
|
||||
print("❌ PDF dimensions need adjustment")
|
||||
Reference in New Issue
Block a user