Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for setting margins for custom page size #58

Open
tkumark opened this issue Feb 2, 2024 · 0 comments
Open

support for setting margins for custom page size #58

tkumark opened this issue Feb 2, 2024 · 0 comments

Comments

@tkumark
Copy link

tkumark commented Feb 2, 2024

Is there a way to set margins size when setting custom page size. ? I am able to pass custom page size but not able set the margin to be used.

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant