Skip to content

support for setting margins for custom page size #58

@tkumark

Description

@tkumark

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions