Below is script using pycups I am able to print with custom page size but I need to set the margin also how do it do that.
import cups
def print_to_printer(printer_name, file_path, custom_width=720, custom_length=432):
conn = cups.Connection()
# Get the printer information
printer_info = conn.getPrinterAttributes(printer_name)
# Convert inches to points (1 inch = 72 points)
custom_width_points = str(int(custom_width * 72))
custom_length_points = str(int(custom_length * 72))
# Create the page size string
page_size_str = f"{custom_width_points}x{custom_length_points}"
# Start the print job with custom page size
print_options = {'PageSize': page_size_str}
print_job_id = conn.printFile(printer_name, file_path, "Print Job", print_options)
print(f"Print job {print_job_id} sent to {printer_name} with custom page size ({custom_width}x{custom_length} inches)")
# Example usage
printer_name = "TVS_MSP-250CH-TVS-original" # Replace with your actual printer name
file_to_print = "/home/tk/Documents/bill.txt" # Replace with the path to your file
custom_width = 10 # Replace with your desired width in inches
custom_length = 6 # Replace with your desired length in inches
print_to_printer(printer_name, file_to_print, custom_width, custom_length)
Try again with Pycups library
Doumentation link below:- https://www.cups.org/doc/spec-ppd.html#cupsPageSizeCategory