Advertisement
Sweetening

Untitled

Apr 29th, 2024
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. Requirements.txt = pip install pywin32
  2.  
  3. Coordinate Conversion: The current script assumes each line in the text file is a single number. You might need to adjust how coordinates are derived based on your actual data format.
  4. Printer Settings: The script uses the default printer. Ensure your HP printer is set as default, or modify the script to target a specific printer.
  5. Error Handling: You might need to add more robust error handling, especially around file and printer operations.
  6.  
  7. Witch I can do pastebin ppl ignore this this is for someone
  8.  
  9.  
  10. import win32print
  11. import win32ui
  12. from win32.lib import win32con
  13. import os
  14.  
  15. def read_numbers_from_file(file_path):
  16. with open(file_path, 'r') as file:
  17. numbers = file.readlines()
  18. # Assuming each line is a number and converts it into a coordinate
  19. coordinates = [(int(num.strip()), int(num.strip())) for num in numbers]
  20. return coordinates
  21.  
  22. def print_coordinates(coordinates):
  23. printer_name = win32print.GetDefaultPrinter()
  24. hPrinter = win32print.OpenPrinter(printer_name)
  25. try:
  26. hDC = win32ui.CreateDC()
  27. hDC.CreatePrinterDC(printer_name)
  28. hDC.StartDoc("Printing Coordinates")
  29. hDC.StartPage()
  30.  
  31. for i, (x, y) in enumerate(coordinates):
  32. hDC.TextOut(x, y, f"Point {i+1}: ({x}, {y})")
  33.  
  34. hDC.EndPage()
  35. hDC.EndDoc()
  36. finally:
  37. win32print.ClosePrinter(hPrinter)
  38.  
  39. def main():
  40. file_path = input("Enter the path to the text file: ")
  41. if not os.path.exists(file_path):
  42. print("File does not exist.")
  43. return
  44.  
  45. coordinates = read_numbers_from_file(file_path)
  46. print("Coordinates read:", coordinates)
  47. print("Sending to printer...")
  48. print_coordinates(coordinates)
  49. print("Done printing.")
  50.  
  51. if __name__ == "__main__":
  52. main()
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement