Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Requirements.txt = pip install pywin32
- 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.
- 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.
- Error Handling: You might need to add more robust error handling, especially around file and printer operations.
- Witch I can do pastebin ppl ignore this this is for someone
- import win32print
- import win32ui
- from win32.lib import win32con
- import os
- def read_numbers_from_file(file_path):
- with open(file_path, 'r') as file:
- numbers = file.readlines()
- # Assuming each line is a number and converts it into a coordinate
- coordinates = [(int(num.strip()), int(num.strip())) for num in numbers]
- return coordinates
- def print_coordinates(coordinates):
- printer_name = win32print.GetDefaultPrinter()
- hPrinter = win32print.OpenPrinter(printer_name)
- try:
- hDC = win32ui.CreateDC()
- hDC.CreatePrinterDC(printer_name)
- hDC.StartDoc("Printing Coordinates")
- hDC.StartPage()
- for i, (x, y) in enumerate(coordinates):
- hDC.TextOut(x, y, f"Point {i+1}: ({x}, {y})")
- hDC.EndPage()
- hDC.EndDoc()
- finally:
- win32print.ClosePrinter(hPrinter)
- def main():
- file_path = input("Enter the path to the text file: ")
- if not os.path.exists(file_path):
- print("File does not exist.")
- return
- coordinates = read_numbers_from_file(file_path)
- print("Coordinates read:", coordinates)
- print("Sending to printer...")
- print_coordinates(coordinates)
- print("Done printing.")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement